- 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-16-2017 01:57 AM
Hi Saranya,
You could make use of array utils in here. There is a function unique to remove duplicates.
http://wiki.servicenow.com/index.php?title=ArrayUtil
Following could be used to check numeric number.A little modification may be required to use code server side
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 08:36 PM
The mapping of field are not correct in the above loop.
[{"number":0,"fields":[{"min":6,"max":10,"label":"","type":"text","value":"1234567890"}]},{"number":1,"fields":[{"min":6,"max":10,"label":"","type":"text","value":"234567890"}]}]
But its mapping like this 234567890,234567890
[{"number":0,"fields":[{"min":6,"max":10,"label":"","type":"text","value":"1234567890"}]},{"number":1,"fields":[{"min":6,"max":10,"label":"","type":"text","value":"0987654321"}]},{"number":2,"fields":[{"min":6,"max":10,"label":"","type":"text","value":"1231231231"}]}]
Its mapping like 34567890,0987654321,1231231231
First value is not taking correctly
thanks
saranya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 08:46 PM
Hi Saranya,
Its seems like you have used instruction twice strValue = strValue.substring(1); OR there may be some issue with break; instruction. Please paste your code in here any i will try to troubleshoot the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 08:58 PM
Hello Gurpreet,
Here I want to insert that value in the other table of the incident record as well as I need to map that value1 in one string field with comma separated.
var parser = new JSONParser();
var strValue1= '' ;
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 != "")
{
strValue1 += ','+value1;
var gr = new GlideRecord('u_bdc_sku_details');
gr.initialize();
gs.log('Jan 17 inside if '+strValue);
gr.u_bdc_sku =value1.toString();
gr.u_incident=inc.sys_id;
gr.insert();
}
strValue1 = strValue1.substring(1);
}
inc.u_bdc_sku_number = strValue1;
inc.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 09:07 PM
Hello Gurpreet,
I got the issue.
Now its working .
Thank you very much for the help
var parser = new JSONParser();
var strValue1= '' ;
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 != "")
{
strValue1 += ','+value1;
var gr = new GlideRecord('u_bdc_sku_details');
gr.initialize();
gs.log('Jan 17 inside if '+strValue);
gr.u_bdc_sku =value1.toString();
gr.u_incident=inc.sys_id;
gr.insert();
}
}
strValue1 = strValue1.substring(1);
inc.u_bdc_sku_number = strValue1;
inc.update();