Is it possible to get One value from an array such as:
Array
(
[id] = 100917
[sid] = SM0ddb860df74148f19f57b314bfc80b39
[date_created] = 2016-02-10 12:04:08
[date_updated] = 2016-02-10 12:04:08
[date_sent] =
[to] = +996559138088
[from] = +15674434357
[body] = Confirmation code: 75ba76
[status] = queued
[direction] = outbound-api
[price] =
[price_unit] = USD
)
I need somehow to get a value of "75ba76" (in confirmation code string) using:
[to] = +996559138088
When i try to select it, i see:
http://prntscr.com/a1cngn
Any ideas?..
Thanks.
You can use string and array operations to get the value that you need, as text in html elements are stored as strings by default. filter() function can be used to get the <pre> element that has the number you specify in arrString variable below. Here's how -
var arrString = "[to] = +996559138088";
var reqValue;
element.all(by.css('pre')).filter(function(ele){
return ele.getText().then(function(str){
return str.search(arrString) > -1;
});
}).getText().then(function(val){ //returns array as a string
reqValue = val.split('\n').filter(function(eachEle){return eachEle.search(/body/i)>-1}).toString().split(' ').pop();
//reqValue holds the data that you require
});
Though code looks a little weird, it should do the job. Hope it helps.
With a strong brainstorm i solved the problem using the next code. It's maybe seems to be huge, but it works great!
it("get temp password", function () {
browser.get("http://api.test.yalla.ng/sms.php?db=stena_kg");
var preElement = element.all(by.css('pre'));
var matchPhone = browser.params.phones.matchPhone;
var matchPass;
var elementIndex = 0;
parseNextElement();
function parseNextElement() {
preElement.get(elementIndex).getText().then(function (text) {
parseElementData(text);
if(!matchPass){
elementIndex++;
parseNextElement();
}else{
onMatch();
}
});
}
function parseElementData(data){
var dataArr = data.split("\n");
var phoneTxt = "";
var passTxt = "";
for(var i = 0; i<dataArr.length; i++){
var str = dataArr[i];
var splitStr = str.split(" ");
if(str.match(/\[to\]/)){
phoneTxt = splitStr[splitStr.length - 1];
}
if(str.match(/\[body\]/)){
passTxt = splitStr[splitStr.length - 1];
}
}
console.log(phoneTxt, passTxt);
if(phoneTxt == matchPhone){
matchPass = passTxt;
}
}
function onMatch(){
console.log("COMPLETE!!!", matchPass);
}
}, 600000);
});
Related
I have 6 documents each with the format below
Header
Text
table 1
Bullet Points
table 2
Text
I want to combine them into one doc - however when I tried this code it dose not work.Please if anyone can advise please
`
function mergeDocs() {
var docIDs = ['list-of','documents','ids','you should have somehow'];
var baseDoc = DocumentApp.openById(docIDs[0]);
var body = baseDoc.getActiveSection();
for( var i = 1; i < docIDs.length; ++i ) {
var otherBody = DocumentApp.openById(docIDs[i]).getActiveSection();
var totalElements = otherBody.getNumChildren();
for( var j = 0; j < totalElements; ++j ) {
var element = otherBody.getChild(j).copy();
var type = element.getType();
if( type == DocumentApp.ElementType.PARAGRAPH )
body.appendParagraph(element);
else if( type == DocumentApp.ElementType.TABLE )
body.appendTable(element);
else if( type == DocumentApp.ElementType.LIST_ITEM )
body.appendListItem(element);
else
throw new Error("According to the doc this type couldn't appear in the body: "+type);
}
}
`
ERROR: (-4014) Cannot add row without complete selection of batch/serial numbers.
The default function of DI API SaveDraftToDocument() is working fine on MS SQL Database but not SAP HANA.
I am posting the Delivery document with Serial Numbers.
SAPbobsCOM.Documents oDrafts;
oDrafts = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);
oDrafts.GetByKey(Convert.ToInt32(EditText27.Value));
var count = oDrafts.Lines.Count;
var linenum = oDrafts.Lines.LineNum;
//Validation
#region
var RsRecordCount = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
var sQryRecordCount = String.Format("Select * from \"SANTEXDBADDON\".\"#TEMPITEMDETAILS\" where \"U_DraftNo\" = '{0}'", EditText27.Value);
RsRecordCount.DoQuery(sQryRecordCount);
#endregion
if (count == RsRecordCount.RecordCount)
{
//LINES
string ItemCode = "", WhsCode = ""; double Quantity = 0; int index = 0;
for (int i = 0; i < oDrafts.Lines.Count; i++)
{
oDrafts.Lines.SetCurrentLine(index);
ItemCode = oDrafts.Lines.ItemCode;
//SERIAL NUMBERS
var RsSerial = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
string table = "\"#TEMPSERIALS\"";
var sQrySerial = String.Format(
"Select \"U_ItemCode\" , \"U_DistNumber\" from \"SANTEXDBADDON\".\"#TEMPSERIALS\" where " +
"\"U_DraftNo\" = '{0}' and \"U_ItemCode\" = '{1}'", EditText27.Value, ItemCode);
RsSerial.DoQuery(sQrySerial);
int serialindex = 1, lineindex = 0;
#region
if (RsSerial.RecordCount > 0)
{
while (!RsSerial.EoF)
{
//OSRN SERIALS
var RsSerialOSRN = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
var sQrySerialOSRN = String.Format(
"Select * from OSRN where \"DistNumber\" = '{0}' and \"ItemCode\" = '{1}'"
, RsSerial.Fields.Item("U_DistNumber").Value.ToString(), ItemCode);
RsSerialOSRN.DoQuery(sQrySerialOSRN);
oDrafts.Lines.SerialNumbers.SetCurrentLine(0);
oDrafts.Lines.SerialNumbers.BaseLineNumber = oDrafts.Lines.LineNum;
oDrafts.Lines.SerialNumbers.SystemSerialNumber =
Convert.ToInt32(RsSerialOSRN.Fields.Item("SysNumber").Value.ToString());
oDrafts.Lines.SerialNumbers.ManufacturerSerialNumber =
RsSerialOSRN.Fields.Item("DistNumber").Value.ToString();
oDrafts.Lines.SerialNumbers.InternalSerialNumber =
RsSerialOSRN.Fields.Item("DistNumber").Value.ToString();
oDrafts.Lines.SerialNumbers.Quantity = 1;
if (RsSerial.RecordCount != serialindex)
{
Application.SBO_Application.StatusBar.SetText("INTERNAL NO " + oDrafts.Lines.SerialNumbers.InternalSerialNumber, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
oDrafts.Lines.SerialNumbers.Add();
serialindex++;
lineindex++;
}
RsSerial.MoveNext();
}
}
#endregion
index++;
}
var status = oDrafts.SaveDraftToDocument();
if (status == 0)
{
oDrafts.Remove();
Application.SBO_Application.StatusBar.SetText("Delivery Posted Successfully !", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
}
else
{
int code = 0; string message = "";
oCompany.GetLastError(out code, out message);
Application.SBO_Application.SetStatusBarMessage(message, SAPbouiCOM.BoMessageTime.bmt_Medium, true);
}
}`
The error you have posted explains the problem. You are trying to deliver products but have not included all of the serial/batch numbers.
I don't think there's enough information to be sure where this problem happens, but here are some pointers:
You are reading the serial numbers from a custom table. Are the values you are reading valid? For example, could another user have added them to a different order? Could the values be for a different product?
Are you specifying the correct quantity of serial numbers? Is it possible that the item quantity on the line is more than the number of serial numbers you are adding?
Believe the error message until you can prove it's wrong. It doesn't seem like this is a HANA issue (we use HANA extensively) it's a logical problem with the data you are providing.
You may want to capture more debugging information to help you if you can't easily identify where the problem is.
can someone show me how to query an array of strings with realm in react-native?
assume i have an array like the following:
const preferences = ["automatic","suv","blue",eco]
What I want is to get realm results where ALL strings in the attribute "specifications" of Cars is in "preferences".
E.g.: If an instance of Cars.specifications contains ["automatic","suv"]
a result should be returned.
But if an instance of Cars.specifications contained ["automatic,"suv","green"] this instance shouldn't be returned.
The length of preferences can vary.
Thank you very much.
Update:
What i tried is the following:
const query = realm.objects("Cars").filtered('specifications = preferences[0] OR specifications = preferences[1]')
As you see it is an OR operator which is surely wrong and it is hardcoded. Looping with realm really confuses me.
This code will work!
const collection = realm.objects('Cars');
const preferences = ["automatic","suv","blue","eco"];
let queryString = 'ANY ';
for (let i = 0; i < preferences.length; i++) {
if (i === 0) {
queryString += `specifications CONTAINS '${preferences[i]}'`;
}
if (i !== 0 && i + 1 <= preferences.length) {
queryString += ` OR specifications CONTAINS '${preferences[i]}'`;
}
}
const matchedResult = collection.filtered(queryString);
example of function to test if a word is inside an array of word
function inArray(word, array) {
var lgth = array.length;
word = word.toLowerCase();
for (var i = 0; i < lgth; i++) {
array[i] = (array[i]).toLowerCase();
if (array[i] == word) return true;
}
return false;
}
const preferences = ["automatic","suv","blue","eco"];
const specifications = ["automatic","suv"] ;
const specifications2 = ["automatic","suv", "boat"] ;
function test(spec,pref){
for (var i in spec){
if(!inArray(spec[i],pref)){
return false ;
}
}
return true;
}
console.log(test(specifications,preferences));
console.log(test(specifications2,preferences));
https://jsfiddle.net/y1dz2gvu/
I'm trying to get the "id" of the TD Node that a field is in. I created a function, but I am not getting the data out of the loop ... I'm guessing that the variables are out of scope and I can't figure out how to make it work.
function getTD(vStartNm)
{
vNm = document.getElementsByName(vStartNm),
vId = vNm[0].getAttribute('id'),
vNode = document.getElementById(vId),
vTag = vNode.nodeName;
vTDId = '';
for (i = 0; i >10; i++)
{
vPar = vNode.parentNode;
vTag = vPar.nodeName;
vTDId = vPar.id;
vNode = vPar;
if (vTag == 'TD'){return vTDId; break;}
}
}
vTD_id = getTD('udfchar45');
vTD = document.getElementById(vTD_id);
my syntax on the do loop may be wrong. once i changed it to a while loop, it seems to work just fine.
function getTD(vStartNm)
{
vNm = document.getElementsByName(vStartNm),
vId = vNm[0].getAttribute('id'),
vNode = document.getElementById(vId),
vTag = vNode.nodeName;
vTDId = '';
i=0;
while (i < 10)
{
i++;
vPar = vNode.parentNode;
vTag = vPar.nodeName;
vTDId = vPar.id;
vNode = vPar;
if (vTag == 'TD'){return vTDId; break;}
}
}
vTD_id = getTD('udfchar45');
vTD = document.getElementById(vTD_id);
I tried to research a bit, but has not found a proper solution to this.
What I'm trying to do is to have a HTML.Action in a page like so
Html.Action("Calendar", "GlobalShared")
Inside the action "Calendar", I need to return the result of the html of the traditional calendar control
public ActionResult Calendar(
String ID,
String CssClass,
int CellSpacing,
int CellPadding,
String BorderWidth,
String ShowGridLines,
String ShowTitle,
String DayNameFormat
)
{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
}
How can I do this? Btw, I use HTML.Action is because I read that it returns a html string, is that correct or should I be doing some other ways?
Thanks
Edit. Before I attempted this in a controller, I tried the following code in a view .cshtml and it works, but I prefer to move the code into a controller
#{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
cal.RenderControl(new HtmlTextWriter(Html.ViewContext.Writer));
}
Edit #2. The reason I want to use that in a controller is because if in the future, i want to hook up an event say "DayRender", I can do it in the controller. I can not do the same in a view without polluting the view page.
Okay. Thanks guys. I figured out. Basically, I need to use #{Html.RenderAction(..)} and in the action itself, use StringBuilder/StringWriter and then return Content(...). Code below
In View
#{Html.RenderAction("Calendar", "GlobalShared");}
In Controller
[ChildActionOnly]
public ActionResult Calendar(
)
{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
cal.DayRender += new System.Web.UI.WebControls.DayRenderEventHandler(CalendarDayRender);
StringBuilder sb = new StringBuilder();
using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))
{
System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(sw);
cal.RenderControl(writer);
}
String calHTML = sb.ToString();
return Content(calHTML);
}
private void CalendarDayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Text = "";
if (e.Day.Date == System.DateTime.Today)
{
e.Cell.CssClass = "today";
System.Web.UI.HtmlControls.HtmlGenericControl h3 = new System.Web.UI.HtmlControls.HtmlGenericControl("h3");
h3.InnerHtml = HttpContext.GetGlobalResourceObject("JTG_DateTime", "JTK_Today") + " " + e.Day.DayNumberText;
e.Cell.Controls.Add(h3);
}
}
Simply move your code
#{
System.Web.UI.WebControls.Calendar cal = new System.Web.UI.WebControls.Calendar();
cal.ID = "MyCalendar";
cal.CssClass = "month-view";
cal.CellSpacing = 0;
cal.CellPadding = -1;
cal.BorderWidth = 0;
cal.ShowGridLines = false;
cal.ShowTitle = false;
cal.DayNameFormat = System.Web.UI.WebControls.DayNameFormat.Full;
cal.RenderControl(new HtmlTextWriter(Html.ViewContext.Writer));
}
in a view and return that View from your Calendar Action.
public ActionResult Calendar(
String ID,
String CssClass,
int CellSpacing,
int CellPadding,
String BorderWidth,
String ShowGridLines,
String ShowTitle,
String DayNameFormat
)
{
return View("Calendar");
}
You can either create a ViewModel or use ViewBag to transfer these values from Calendar Action to your newly created View