- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2017 01:00 AM
Hi,
I am facing to fetch the node value of one the attributes. In my XML Payload, the response is something like:
<domain>europe.abc.com</domain>
Or
<domain>pacific.abc.com</domain>
Or
<domain>americas.abc.com</domain>
Or
<domain>abc.com</domain>
I need to read the first value (before dot) of the attribute <domain>.
So my desired output is: europe Or pacific Or americas Or abc.
I am using below line to get the value but i am getting 'undefined' always
var dom = xmldoc.getNodetext("//domain")
Please advise if anyone knows the solution of it.
Regards
Vishal
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2017 09:05 AM
Hi Vishal,
The dom variable should print the value "europe.abc.com" and you wanted to retrieve the value "europe" so as I mentioned earlier in my comment you will have to split using dot
var dom = "europe.abc.com"; // this you are getting as per your comment
var splitValues = dom.split(".");
var firstValue = splitValues[0]; // this prints europe
var secondValue = splitValues[1]; // this prints abc
var thirdValue = splitValues[2]; // this prints com
Can you try and let me know?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2017 01:14 AM
Hi Vishal,
Following is the way to fetch the value within the <domain> tag. once you get that value you can split using dot and get the first value as below
var str = ''; // your xml document
var xmldoc = new XMLDocument(str);
var value = xmldoc.getNodeText("//domain");
gs.print(value);
var splitValues = value.split("."); // split with dot
gs.print(splitValues[0]); // this should give you europe
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2017 07:34 AM
Hi Ankur,
Thanks for your response.
I tried to use this method but it gives 'undefined' result to me. Please see the script
var dom = parseString(xmldoc.getNodetext("//domain"));
var splitValues = dom.split(".");
//var domName = gs.print(splitDom[0]);
gs.log("Payload Values: " + correlationID + " " + name + " " + " " + os + splitValues);
The logs gives correct value if I comment the 2nd line and just print the first variable i.e., 'dom' (Result: europe.abc.com)
But when I use split method it doesn't show any value at all.
I also tried to use .toString() and parseString() methods but neither works.
Will be great if you can suggest any solution to overcome this issue.
Regards
Vishal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2017 09:05 AM
Hi Vishal,
The dom variable should print the value "europe.abc.com" and you wanted to retrieve the value "europe" so as I mentioned earlier in my comment you will have to split using dot
var dom = "europe.abc.com"; // this you are getting as per your comment
var splitValues = dom.split(".");
var firstValue = splitValues[0]; // this prints europe
var secondValue = splitValues[1]; // this prints abc
var thirdValue = splitValues[2]; // this prints com
Can you try and let me know?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2017 01:38 AM
Hi Ankur,
This is working. It was creating an issue because of small syntax error.
Thanks for the assistance.
Regards,
Vishal