google calendar api - getting undefined for output for gd$where - javascript

i'm able to parse in and display data for all pieces of my code except in this line
" where: " + e.gd$where.valueString + // < this line is displaying undefined
here is the code block that is doing the processing. everything else displays correct data
Titanium.API.info(cal.feed.entry.length);
var i;
for (i=0; i < cal.feed.entry.length; i++){
var e = cal.feed.entry[i];
Titanium.API.info("title: " + e.title.$t +
" content " + e.content.$t +
" when: " + e.gd$when[0].startTime + " - " + e.gd$when[0].endTime +
" evenstatus" + e.gd$eventStatus.value +
" where: " + e.gd$where.valueString + // < this line is displaying undefined
" gcal$uid: " + e.gCal$uid.value
);
here is what should be displayed from the calendar
"gd$where": [{
"valueString": "Any of the 11 elementary schools"
}],

gd$where is an array of objects. In order to access "valueString" in the first key, you need to access it from within that object, like so:
gd$where[0].valueString

Related

Post response from Fedex stripped XML tags in Netsuite

I am using UserEventScript to request fedex with tracking number for asking tracking detail.
var headerObj = [];
headerObj['Content-Type'] = 'text/xml';
headerObj['Accept'] = 'text/xml';
var body =
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:v19=\"http://fedex.com/ws/track/v19\">\n" +
" <soapenv:Header />\n" +
" <soapenv:Body>\n" +
" <v19:TrackRequest>\n" +
" <v19:WebAuthenticationDetail>\n" +
" <v19:ParentCredential>\n" +
" <v19:Key>Your key</v19:Key>\n" +
" <v19:Password>Your password</v19:Password>\n" +
" </v19:ParentCredential>\n" +
" <v19:UserCredential>\n" +
" <v19:Key>Your key</v19:Key>\n" +
" <v19:Password>Your password</v19:Password>\n" +
" </v19:UserCredential>\n" +
" </v19:WebAuthenticationDetail>\n" +
" <v19:ClientDetail>\n" +
" <v19:AccountNumber>Your ac no.</v19:AccountNumber>\n" +
" <v19:MeterNumber>Your meter no.</v19:MeterNumber>\n" +
" </v19:ClientDetail>\n" +
" <v19:TransactionDetail>\n" +
" <v19:CustomerTransactionId>Track By
Number_v19</v19:CustomerTransactionId>\n" +
" <v19:Localization>\n" +
" <v19:LanguageCode>EN</v19:LanguageCode>\n" +
" <v19:LocaleCode>US</v19:LocaleCode>\n" +
" </v19:Localization>\n" +
" </v19:TransactionDetail>\n" +
" <v19:Version>\n" +
" <v19:ServiceId>trck</v19:ServiceId>\n" +
" <v19:Major>19</v19:Major>\n" +
" <v19:Intermediate>0</v19:Intermediate>\n" +
" <v19:Minor>0</v19:Minor>\n" +
" </v19:Version>\n" +
" <v19:SelectionDetails>\n" +
" <v19:CarrierCode>FDXE</v19:CarrierCode>\n" +
" <v19:PackageIdentifier>\n" +
" <v19:Type>TRACKING_NUMBER_OR_DOORTAG</v19:Type>\n" +
" <v19:Value>992959690382</v19:Value>\n" +
" </v19:PackageIdentifier>\n" +
" <v19:ShipmentAccountNumber />\n" +
" <v19:SecureSpodAccount />\n" +
" </v19:SelectionDetails>\n" +
" <v19:ProcessingOptions>INCLUDE_DETAILED_SCANS</v19:ProcessingOptions>\n" +
" </v19:TrackRequest>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>"
var resoponse = https.post({
url: 'https://ws.fedex.com:443/web-services',
body: body,
headers:headerObj
});
And the response.body i got is like this.
SUCCESSSUCCESStrck0Request was successfully processed.Request was successfully processed.Track By Number_v19ENUStrck1900SUCCESSSUCCESStrck0Request was successfully processed.Request was successfully processed.falsefalse0SUCCESStrck0Request was successfully processed.Request was successfully processed.9929596903822459294000~992959690382~FX2021-03-21T00:00:00ARArrived at FedEx locationMEMPHISTNUSUnited StatesfalseNo scheduled delivery date available at this time.EDDUNAVAILABLEFDXEFedEx ExpressSHIPPER_REFERENCEB2003217, STAR DIAM LTDINTERNATIONAL_PRIORITYInternational PriorityIPLB1.013123INLB1.0FEDEX_BOXFedEx Box1100AWBDELIVER_WEEKDAYDeliver WeekdayOTHERDUTIES_AND_TAXESRECIPIENT_ACCOUNTRecipientTRANSPORTATIONSHIPPER_ACCOUNTShipperHUNGHOM,HKHong Kong SAR, ChinafalseACTUAL_PICKUP2021-03-20T14:39:00+08:00SHIP2021-03-20T00:00:00ACTUAL_TENDER2021-03-20T14:39:00+08:00ATLANTA,GAUSUnited Statesfalse00ON_DELIVERYON_EXCEPTIONON_ESTIMATED_DELIVERYINDIRECT_SIGNATURE_RELEASEINELIGIBLEREDIRECT_TO_HOLD_AT_LOCATIONPOSSIBLY_ELIGIBLEREROUTEINELIGIBLERESCHEDULEINELIGIBLE2021-03-21T08:19:00-05:00ARArrived at FedEx location
MEMPHISTN38118USUnited Statesfalse
FEDEX_FACILITY2021-03-20T23:17:00-08:00DPDeparted FedEx location
ANCHORAGEAK99502USUnited Statesfalse
FEDEX_FACILITY2021-03-20T21:58:00-08:00ARArrived at FedEx location
ANCHORAGEAK99502USUnited Statesfalse
FEDEX_FACILITY2021-03-21T04:35:00+08:00ITIn transit
CHEK LAP KOK300HKHong Kong SAR, Chinafalse
FEDEX_FACILITY2021-03-20T18:09:00+08:00DPLeft FedEx origin facility
TSUEN WAN230HKHong Kong SAR, Chinafalse
ORIGIN_FEDEX_FACILITY2021-03-20T14:39:00+08:00PUPicked up
TSUEN WAN230HKHong Kong SAR, Chinafalse
PICKUP_LOCATION
Actually, it matches with the normal result i got from postman, but it is unreadable.
What i should do to transfer the above one to be a normal json format or xml format? Or how can i get the exactly value from the above response?
You are not showing how you get that body but I suspect you are just logging it.
What the FedEx API returns is xml. If you log that Netsuite doesn't escape the tags for you so it will look just like that in the log. If you view the log and inspect the details you should see all the tags.
to get NS to escape that for you try:
log.debug({
title:'FedEx Response',
details:xml.escape({xmlText:resp.body})
});
Then you can use code like that below to extract the info you are looking for:
var xmlDocument = xml.Parser.fromString({
text: resp.body
});
var ref = xml.XPath.select({
node: xmlDocument,
xpath: '//ns:TrackingNumber' /* or maybe //nlapi:TrackingNumber or //TrackingNumber */
});
Once you have the full xml by escaping the response you can see the namespaces used in the response. I think the first form is what you'll use but you may need the nlapi: form if the prefix xmlns prefix for ns is also the default namespace.

Selenium - Unable to find the hidden element

I am trying to create an framework where I want to find whether an webelement is hidden or not before performing an action on the web element.
I have a password field which is hidden and is structured as below
<div class=hidepassword>
<input password field >
<div>
When I query the input tag with the following lines
Isvisible1 = (string)js1.ExecuteScript("return (window.getComputedStyle?window.getComputedStyle(arguments[0], null):arguments[0].currentStyle).visibility;", myCurElement);
Isvisible2 = (string)js1.ExecuteScript("return (window.getComputedStyle(arguments[0], null).getPropertyValue('display'));", myCurElement);
Isvisible3 = (bool)js1.ExecuteScript("return !(arguments[0].offsetHeight <= 1);", myCurElement);
I am getting all the values indicating it as visible.
Later , got to know that the class which the preceding div has is making the input invisible.
I tried to get the value of overflow which is made available in the .css file for the class hidepassword
But unfortunately, there are lot of css values for the class hidepassword and when I use the below javascript function, I am able to get only one of its CSS value
public string getStyle(string ClassName)
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
return (String)js.ExecuteScript(
"function getStyle(ClassName) {" +
"var styleSheets = window.document.styleSheets;" +
"var styleSheetsLength = styleSheets.length;" +
"for (var i = 0; i < styleSheetsLength; i++)" +
"{" +
" var classes = styleSheets[i].rules || styleSheets[i].cssRules;" +
" if (!classes)" +
" continue;" +
" var classesLength = classes.length;" +
" for (var x = 0; x < classesLength; x++)" +
" {" +
" if (classes[x].selectorText == ClassName)" +
" {" +
" var ret;" +
" if (classes[x].cssText)" +
" {" +
" ret = classes[x].cssText;" +
" }" +
" else" +
" {" +
" ret = classes[x].style.cssText;" +
" }" +
" if (ret.indexOf(classes[x].selectorText) == -1)" +
" {" +
" ret = classes[x].selectorText + ret ;" +
" }" +
" return ret;" +
" }" +
" }" +
"}" +
"}return getStyle(arguments[0]);", ClassName);
}
Is there a way to get all the css values for the particular class name and then based on the css values for the class, we can make a call whether the element is visible or not visible. ?
Thanks in advance for all your help on this.
Selenium had supply api:isDisplayed() to detect element visibility, why you want to implement it as such complex by yourself

How to split innherHTML string using Javascript into specific parts after a certain character like a '+' sign

I need to break a string apart after certain characters.
document.getElementById("result").innerHTML = Monster + "<p id='vault" + loop + "'> || HP: " + HP + "</p>" + " || Defense: " + Def + " || Attack: " + ATK + " || Can it Dodge/Block: " + DB + " || Can it retaliate: " + RET + " || Initative: " + INT + " || Exp: " + MEXP + " <input type='submit' class='new' onclick='Combat(" + loop + ")' value='FIGHT!'></input>" + "<br><br>" + A;
function Chest(id){
window.open('LootGen.html', '_blank');
}
function Combat(id){
document.getElementById("C").value = document.getElementById("vault" + id).innerHTML;
}
When this runs the value that results is:
|+HP:+20
However I only want '20' part,now keep in mind that this variable does change and so I need to use substrings to somehow pull that second number after the +. I've seen this done with:
var parameters = location.search.substring(1).split("&");
This doesn't work here for some reason as first of all the var is an innher html.
Could someone please point me in the write direction as I'm not very good at reading docs.
var text = "|+HP:+20";
// Break string into an array of strings and grab last element
var results = text.split('+').pop();
References:
split()
pop()
using a combination of substring and lastIndexOf will allow you to get the substring from the last spot of the occurrence of the "+".
Note the + 1 moves the index to exclude the "+" character. To include it you would need to remove the + 1
function Combat(id){
var vaultInner = document.getElementById("vault" + id).innerHTML;
document.getElementById("C").value = vaultInner.substring(vaultInner.lastIndexOf("+") + 1);
}
the code example using the split would give you an array of stuff separated by the plus
function Combat(id){
//splits into an array
var vaultInner = document.getElementById("vault" + id).innerHTML.split("+");
//returns last element
document.getElementById("C").value = vaultInner[vaultInner.length -1];
}

How to return a value in the only non-blank column in a range for sendEmail function in Google App Scripts

The issue is: I can't find a way to return the value for 'Course' because each form submission generates a new row where the name of the course is spread over columns E to M (column 4 through 12).
In each row, there is only one 'Course' name in one of the columns from E to M (e.g only in F) and all other columns are blank. (Users can only select one course and all the other columns will be blank. I have to categorize the courses into the 9 columns because of the page breaks in order to split the sheer number of options that users select the course from.) How do I return the value of the only non blank cell from E to M which will be entered in the email ?
I was advised to insert the entire findCourse function inside of the sendEmail function before any of the other code. I did so but I have still been receiving failure notifications of the Google App Scripts: TypeError: Cannot read property "values" from undefined. (line 14, file "Code") (referring to var value = e.values[i])
The full code below:
function sendEmail(e) {
function findCourse (e){
var courseToTake;
//loop through values
for ( var i = 4; i <=12; i ++){
//pull value into variable
var value = e.values[i];
if (value != undefined){
//if we find an actual string value, set the course to take variable
courseToTake = value;
}
}
return courseToTake;
}
var Name = e.namedValues["Full name as appear in NRIC"];
var Course = findCourse();
var Start = e.values[14];
var End = e.values[15];
var StartTime = e.values[24];
var EndTime = e.values[25];
var Details = e.values[13];
var Cost = e.values[17];
var Email = e.values[18];
var ROname = e.values[19];
var ROemail = e.values[20];
var Location = e.values[23];
var subject = "Training Approval Request for " + Course;
var message = "<p >" + "Dear " + ROname + "<p />"
+ Name + " seeks your approval to attend the " + Course + ". The details are as follow:"
+ "<p >" + "<b>Date:</b> " + Start + " - " + End + " <br />"
+ "<b>Time:</b> " + StartTime + " - " + EndTime + " <br />"
+ "<b>Location:</b> " + Location + " <br />"
+ "<b>Course objectives and benefits:</b> " + Details + " <br />"
+ "<b>Course fees:</b> " + "$" + Cost + " <br />" + "<p />"
+ "Please reply directly to this email for your approval or if you have any questions/comments. Thank you. "
MailApp.sendEmail(ROemail, Email, subject, message);
}
After rearranging findCourse as its own function: sorry if I made any mistakes here but i'll try my best to follow all suggestions. If i've added in Logger.log(e) correctly, both functions seem to be undefined
function sendEmail(e) {
Logger.log(e);
var Name = e.values[2];
var Course = findCourse();
var Start = e.values[14];
var End = e.values[15];
var StartTime = e.values[24];
var EndTime = e.values[25];
var Details = e.values[13];
var Cost = e.values[17];
var Email = e.values[18];
var ROname = e.values[19];
var ROemail = e.values[20];
var Location = e.values[23];
var subject = "Training Approval Request for " + Course;
var message = "<p >" + "Dear " + ROname + "<p />"
+ Name + " seeks your approval to attend the " + Course + ". The details are as follow:"
+ "<p >" + "<b>Date:</b> " + Start + " - " + End + " <br />"
+ "<b>Time:</b> " + StartTime + " - " + EndTime + " <br />"
+ "<b>Location:</b> " + Location + " <br />"
+ "<b>Course objectives and benefits:</b> " + Details + " <br />"
+ "<b>Course fees:</b> " + "$" + Cost + " <br />" + "<p />"
+ "Please reply directly to this email for your approval or if you have any questions/comments. Thank you. "
MailApp.sendEmail(ROemail, Email, subject, message);
}
function findCourse (e){
var courseToTake;
//loop through values
for ( var i = 4; i <=12; i ++){
//pull value into variable
var value = e.values[i];
if (value != undefined){
//if we find an actual string value, set the course to take variable
courseToTake = value;
}
}
return courseToTake;
var courseToTake = findCourse(e);
Logger.log(e);
}
I will really deeply appreciate any help or alternative solutions here.
Thank you!
What I changed in your code to address your question:
I assigned the onFormSubmit trigger to your sendEmail function so the event object would no longer be undefined
I added a call to findCourse() so your course variable would no longer be undefined
I fixed the undefined check by changing if(value != undefined) to if(typeof value !== 'undefined')
I added a check for a blank value (This was the important bit in the logic after the faulty undefined check) if(value != '')
Explanation:
To trigger the event, an installable trigger needs to be setup for the On Form Submit event that points to your sendEmail function. This can be found in Resources -> Current Project Triggers
To retrieve the course, you need to call your function findCourse() and pass in the e event object. Example: var course = findCourse(e);. This will assign the return value from findCourse(e); to the course variable. You can then use this variable like normal within the rest of your statements.
When checking for undefined, you need to use typeof and then check for the string of 'undefined', or your check will ironically throw an undefined exception.
The values of the form submit should not be undefined, blank values should just be blank strings. so checking for non-blank strings was necessary to get the course name from the values array.
Fixed Code:
function sendEmail(e) {
Logger.log(e)
var course = findCourse(e);
var Name = e.values[19];
var Start = e.values[12];
var End = e.values[14];
var StartTime = e.values[13];
var EndTime = e.values[15];
var Details = e.values[11];
var Cost = e.values[17];
var Email = e.values[20];
var ROname = e.values[21];
var ROemail = e.values[22];
var Location = e.values[16];
var subject = "Training Approval Request for " + course;
var message = "<p >" + "Dear " + ROname + "<p />"
+ Name + " seeks your approval to attend the " + course + ". The details are as follow:"
+ "<p >" + "<b>Date:</b> " + Start + " - " + End + " <br />"
+ "<b>Time:</b> " + StartTime + " - " + EndTime + " <br />"
+ "<b>Location:</b> " + Location + " <br />"
+ "<b>Course objectives and benefits:</b> " + Details + " <br />"
+ "<b>Course fees:</b> " + "$" + Cost + " <br />" + "<p />"
+ "Please reply directly to this email for your approval or if you have any questions/comments. Thank you. "
MailApp.sendEmail(ROemail, Email+";" + "redactedEmail", subject, message);
}
function findCourse (e){
var courseToTake;
//loop through values
for ( var i = 2; i <=10; i ++){
//pull value into variable
var value = e.values[i];
if (typeof value !== 'undefined'){ //If value is defined
if(value != ''){ //If value is not blank
//if we find an actual non-blank string value, set the course to take variable
courseToTake = value;
}
}
}
return courseToTake;
}

dynamics crm 4.0 lookup field onload() query

I have an account entity with a lookup field schoolLookupId which refers back to a custom entity new_schools. The lookup field only display the name of the school. What I would like to be able to do using the onload() event handler of the account form is to run some javascript code that will query the new_phonenumber attribute of the new_schools entity to see if it matches a value i provide lets say var x = "1234" and if it does then update schoolLookupId accordingly with the name of the school that corresponds with the found phone number. i.e update the lookup field with a phone number that already exists without creating a completely new lookup value.
I can get the attributes of the lookupfield using
var name = crmForm.all.schoolLookupid.DataValue[0].name
var id = crmForm.all.schoolLookupid.DataValue[0].id
var typename = crmForm.all.schoolLookupid.DataValue[0].typename
but I can't figure out how to retrieve, compare the data that lies behind the lookup field, and update the lookupfield accordingly.
Your help as always is invaluable.
Try put this code in load event:
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
" <q1:EntityName>new_schools</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>new_schoolsid</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:Criteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>new_phonenumber</q1:AttributeName>" +
" <q1:Operator>Equal</q1:Operator>" +
" <q1:Values>" +
" <q1:Value xsi:type=\"xsd:string\">"+crmForm.all.new_phonenumber.DataValue+"</q1:Value>" +
" </q1:Values>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:Criteria>" +
" </query>" +
" </RetrieveMultiple>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "http://"+window.location.hostname+":"+window.location.port+"/mscrmservices/2007/crmservice.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
if (_resultXml.xml.search('<q1:new_schoolsid')>0)
{
var val = xmlDoc.getElementsByTagName("q1:new_schoolsid")[0].childNodes[0].nodeValue;
var lookupitem = new Array();
lookupitem[0] = new LookupControlItem(val , typecode, name);
crmForm.all.schoolLookupid.DataValue = lookupitem ;
}
}
I don't try this code be careful. Use this code as a guide.
Hope this helps.
If i answered your question, please mark the response as an answer and also vote as helpful.

Categories