- 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 09:58 PM
Hi Saranya,
I think you had asked similar question which I had answered correctly. you can refer the same here
Parse json to incident referal record
json parse check the array if it is null or undefined
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 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:24 PM
Hello Gurpreet,
Thanks for the response.
Still its not working
It's not mapping
Logs are coming.
var parser = new JSONParser();
var parsedData = parser.parse(json_output);
var strValue= '' ;
var parsedData1 = parser.parse(json_output);
var length = parsedData1.length; // get length
for(var i=0;i<length;i++)
{
var value1 = parsedData[i].fields[0].value;
if(value1 != "")
{
strValue += ','+value1;
gs.log('Jan16 '+strValue);
}
}
strValue = strValue.substring(1);
inc.u_bdc_sku_number=strValue ;
This is my field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2017 10:29 PM
Hi Saranya,
Do you want the field to store all the values in comma separated such as
or you want 2 records to be created in incident table with individual values present in json i.e. record1 in inc with value of field u_bdc_sku_number as "11111" and second record with value of "22222"
inc.u_bdc_sku_number = '111111,111111' ;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader