javascript - google sheets trouble with xml -


i trying pull data ups tracking spreadsheet. signedforbyname part of xml feed there , not. when isn't there, issue: typeerror: cannot read property "text" undefined. (line 60, file "code") if comment out line 60 looking signedforbyname fine after pull variable out of string supposed generated.

i'm not familiar javascript doing daft syntax thing, great. easy answers. if point me in right direction snippit, appreciate it.

i figured if check if value there way go, doesn't seem working either same error occurs in same place or without if/then (even if messed syntax).

code missed mark on:

catch(err) { if (jsontext.trackresponse.shipment.package.activity.activitylocation.signedforbyname.text !==null){   var signedby = jsontext.trackresponse.shipment.package.activity.activitylocation.signedforbyname.text;}   else {var signedby = "no signature";} var droplocation = jsontext.trackresponse.shipment.package.activity.activitylocation.description.text; var estdate = 'signed by: '+signedby+' @ '+droplocation; 

xml log:

[15-03-28 07:52:43:381 cst] xml.parse([<?xml version="1.0"?> <trackresponse><response><responsestatuscode>1</responsestatuscode><responsestatusdescription>success</responsestatusdescription></response><shipment><shipper><shippernumber>xxxx</shippernumber><address><addressline1>xxxxx</addressline1><city>tracy</city><stateprovincecode>ca</stateprovincecode><postalcode>95304   9370</postalcode><countrycode>us</countrycode></address></shipper><shipto><address><city>roundup</city><stateprovincecode>mt</stateprovincecode><postalcode>59072</postalcode><countrycode>us</countrycode></address></shipto><shipmentweight><unitofmeasurement><code>lbs</code></unitofmeasurement><weight>4.90</weight></shipmentweight><service><code>003</code><description>ground</description></service><referencenumber><code>01</code><value>xxxxxxxx</value></referencenumber><shipmentidentificationnumber>1za85y090310073852</shipmentidentificationnumber><pickupdate>20150318</pickupdate><deliverydateunavailable><type>scheduled delivery</type><description>scheduled delivery date not available, please try later</description></deliverydateunavailable><package><trackingnumber>1za85y090310073852</trackingnumber><activity><activitylocation><address><city>roundup</city><stateprovincecode>mt</stateprovincecode><postalcode>59072</postalcode><countrycode>us</countrycode></address><code>mp</code><description>garage</description></activitylocation><status><statustype><code>d</code><description>delivered</description></statustype><statuscode><code>fs</code></statuscode></status><date>20150323</date><time>131200</time></activity><packageweight><unitofmeasurement><code>lbs</code></unitofmeasurement><weight>4.90</weight></packageweight><referencenumber><code>01</code><value>fn1-2514196-2965923</value></referencenumber><referencenumber><code>01</code><value>d3m0kfd7k</value></referencenumber><referencenumber><code>01</code><value>na</value></referencenumber><referencenumber><code>01</code><value>ups-caoak-t00441361l  ups842508  up</value></referencenumber></package></shipment></trackresponse>, true]) [0.067 seconds] [15-03-28 07:52:43:450 cst] logger.log([{trackresponse={response={responsestatuscode={text=1}, responsestatusdescription={text=success}}, shipment={shipmentidentificationnumber={text=1za85y090310073852}, service={description={text=ground}, code={text=003}}, referencenumber={value={text=129821607}, code={text=01}}, shipper={address={postalcode={text=95304   9370}, stateprovincecode={text=ca}, countrycode={text=us}, addressline1={text=xxxxx}, city={text=tracy}}, shippernumber={text=xxxx}}, package={activity={status={statuscode={code={text=fs}}, statustype={description={text=delivered}, code={text=d}}}, time={text=131200}, date={text=20150323}, activitylocation={description={text=garage}, address={postalcode={text=59072}, stateprovincecode={text=mt}, countrycode={text=us}, city={text=roundup}}, code={text=mp}}}, referencenumber=[{value={text=fn1-2514196-2965923}, code={text=01}}, {value={text=d3m0kfd7k}, code={text=01}}, {value={text=na}, code={text=01}}, {value={text=ups-caoak-t00441361l  ups842508  up}, code={text=01}}], trackingnumber={text=1za85y090310073852}, packageweight={unitofmeasurement={code={text=lbs}}, weight={text=4.90}}}, shipmentweight={unitofmeasurement={code={text=lbs}}, weight={text=4.90}}, deliverydateunavailable={description={text=scheduled delivery date not available, please try later}, type={text=scheduled delivery}}, pickupdate={text=20150318}, shipto={address={postalcode={text=59072}, stateprovincecode={text=mt}, countrycode={text=us}, city={text=roundup}}}}}}, []]) [0.001 seconds] [15-03-28 07:52:43:451 cst] logger.log([1, []]) [0 seconds] [15-03-28 07:52:43:523 cst] execution failed: typeerror: cannot read property "text" undefined. (line 60, file "code") [0.551 seconds total runtime] 

edit: try checking condition of signedforbyname:

if (jsontext.trackresponse.shipment.package.activity.activitylocation.signedforbyname) { ... } 

then set variable ...signedforbyname.text if signedforbyname exists.

testing out json object, replicated error message when looking signedforname.text got undefined when trying access signedforbyname.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -