- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2020 08:52 PM
Hi,
I have a script include which is returning me with the JSON object, my requirement is if i get atleast one flag as true then i need to throw an error if not i need to set the server name's received from the server.
[{"flagg":false,"serverName":"Winodws Server 2003"},{"flagg":true,"serverName":"IIS"},{"flagg":false,"serverName":"Winodws Server 2004"}]
for above object result i have true flag for IIS so if there at least one true flag in the complete object result then i should throw an error if not i need to set value in Server name variable.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2020 09:06 PM
Hi Shaik,
try running this in scripts background; use similar in client script
var str = '[{"flagg":false,"serverName":"Winodws Server 2003"},{"flagg":true,"serverName":"IIS"},{"flagg":false,"serverName":"Winodws Server 2004"}]';
var parser = new JSONParser();
var parsedData = parser.parse(str);
var flag = false;
for(var i=0;i<parsedData.length;i++){
if(parsedData[i].flagg){
flag = true;
break;
}
}
if(flag){
// do whatever required
}
Mark ✅ Correct if this solves your issue and also mark 👍 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-07-2020 09:06 PM
Hi Shaik,
try running this in scripts background; use similar in client script
var str = '[{"flagg":false,"serverName":"Winodws Server 2003"},{"flagg":true,"serverName":"IIS"},{"flagg":false,"serverName":"Winodws Server 2004"}]';
var parser = new JSONParser();
var parsedData = parser.parse(str);
var flag = false;
for(var i=0;i<parsedData.length;i++){
if(parsedData[i].flagg){
flag = true;
break;
}
}
if(flag){
// do whatever required
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader