getNodes() method

jesusemelendezm
Mega Guru

Can anyone confirm if this method still can be used in Helsinkin?

I have tried exact same samples in a script include and BR not returning any value.

http://wiki.servicenow.com/index.php?title=XMLDocument_Script_Object#gsc.tab=0

xmldoc.getNodes

00000000.JPG

1 ACCEPTED SOLUTION

fredi_fr
ServiceNow Employee
ServiceNow Employee

Yes, it worked for me, with small modifications:



var xmlString = "<test>" +


                              "   <one>" +


                              "       <two att=\"xxx\">abcd1234</two>" +


                              "       <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +


                              "       <two>another</two>" +


                              "   </one>" +


                              "   <number>1234</number>" +


                              "</test>";




var xmldoc = new XMLDocument(xmlString);




var nodelist = xmldoc.getNodes("//one/*"); // two, three, and two


gs.log(nodelist.getLength());


gs.log(nodelist.item(0).getNodeName());


gs.log(nodelist.item(1).getNodeName());


View solution in original post

8 REPLIES 8

fredi_fr
ServiceNow Employee
ServiceNow Employee

Hi Jesus,


Show be supported. You can find the same doc under Istanbul release. Normally, SN does not remove features, might stop support, but rarely removes features.



https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/script/server-scripting/concept...



Regards,


Guillermo


were you able to test it in background scripts?


It doesn't work for me.


fredi_fr
ServiceNow Employee
ServiceNow Employee

Yes, it worked for me, with small modifications:



var xmlString = "<test>" +


                              "   <one>" +


                              "       <two att=\"xxx\">abcd1234</two>" +


                              "       <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +


                              "       <two>another</two>" +


                              "   </one>" +


                              "   <number>1234</number>" +


                              "</test>";




var xmldoc = new XMLDocument(xmlString);




var nodelist = xmldoc.getNodes("//one/*"); // two, three, and two


gs.log(nodelist.getLength());


gs.log(nodelist.item(0).getNodeName());


gs.log(nodelist.item(1).getNodeName());


For some reasons this particular line var nodelist = xmldoc.getNodes("//name/*") won't run on my code and I am suspecting it could be one of the following reasons



1) I am using client callable script include


2) It is scoped application


3) my xmlDoc is an instance of XMLDocument2(); instead of XMLDocument() as you have it there.