- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2017 09:47 PM
Hello,
I want to map the value from the json array to string variable.
[{"number":0,"fields":[{"min":6,"max":10,"label":"","type":"text","value":"111111"}]},{"number":1,"fields":[{"min":6,"max":10,"label":"","type":"text","value":"111111"}]}]
var json_output=this.getParameter('sysparm_json_output');
var parser = new JSONParser();
var parsedData = parser.parse(json_output);
var length = parsedData.length; // get length
for(var i=0;i<length;i++)
{
var value1 = parsedData[i].fields[0].value;
if(value1 != "")
{
inc.u_bdc_sku_number=value1.toString();// its not working
}
else
break;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2017 10:03 PM
Following should work fine
var json_output=this.getParameter('sysparm_json_output');
var parser = new JSONParser();
var parsedData = parser.parse(json_output);
var strValue= '' ;
var parsedData = parser.parse(json_output);
var length = parsedData.length; // get length
for(var i=0;i<length;i++)
{
var value1 = parsedData[i].fields[0].value;
if(value1 != "")
{
strValue += ','+value1;
}
}
strValue = strValue.substring(1);
inc.u_bdc_sku_number=strValue ;// its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2017 10:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2017 10:38 PM
Hi Saranya,
Got it.
Have this code
var json_output=this.getParameter('sysparm_json_output');
var parser = new JSONParser();
var parsedData = parser.parse(json_output);
var strValue= '' ;
var parsedData = parser.parse(json_output);
var length = parsedData.length; // get length
for(var i=0;i<length;i++)
{
var value1 = parsedData[i].fields[0].value;
if(value1 != "")
{
strValue = strValue + value1;
}
}
inc.u_bdc_sku_number = strValue;
inc.update() // or inc.insert() based on your functionality
This should work and populate the way you want.
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
‎01-15-2017 11:38 PM
Hi Saranya,
Yes you need to update the record as well. As instructed by Ankur, add inc.update() at end of the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2017 11:52 PM
Thank you very much Gurpreet and Ankur.It got worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2017 11:56 PM
Hello Gurpreet,
Is there any way to check this value1 is not duplicate value?
I need to validate whether its a 6 to 8 digit number and value are not duplicate.
var json_output=this.getParameter('sysparm_json');
var parser = new JSONParser();
var parsedData = parser.parse(json_output);
var length = parsedData.length; // get length
var count=0;
for(var i=0;i<length;i++)
{
var value1 = parsedData[i].fields[0].value;
var value_length=value1.length;
if((value1==undefined)||(value_length>10 ||value_length<6))
{
count=1;
break;
}
else
{
count=0;
}
}
if(count==1)
{
return true; //Sending to client
}
else
return false;
}