- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 08:12 AM
Hi,
I am using the below code in before BR to map the multi-row variable set of record producer to the description field of a table extended from case.
var FR = current.variables.files_required;
var arr = [];
var parser = new global.JSON();
var parsedData = parser.decode(FR);
for (var i = 0; i < parsedData.length; i++) {
var obj = {};
obj['Proposed lock period'] = parsedData[i].proposed_lock_period;
obj['Comments'] = parsedData[i].comments;
obj['File date'] = parsedData[i].file_date;
obj['File Name'] = parsedData[i].file_name;
obj['Personal Information'] = parsedData[i].pi;
arr.push(obj);
}
gs.log("Array is " + arr);
current.setValue('description', JSON.stringify(obj));
But it's not happening as no data is getting in to the description field.
could any one suggest me a solution for this
Thanks and Regards,
Abhi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 11:01 PM
Hi,
you should set the array when you stringify
var FR = producer.files_required;
var arr = [];
var parsedData = JSON.parse(FR);
for (var i = 0; i < parsedData.length; i++) {
var obj = {};
obj['Proposed lock period'] = parsedData[i].proposed_lock_period;
obj['Comments'] = parsedData[i].comments;
obj['File date'] = parsedData[i].file_date;
obj['File Name'] = parsedData[i].file_name;
obj['Personal Information'] = parsedData[i].pi;
arr.push(obj);
}
current.setValue('description', JSON.stringify(arr));
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-24-2022 08:24 AM
Hi
in the last line write
current.setValue('description', JSON.stringify(arr));
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 10:07 PM
Hi,
Even this is returning nothing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 10:15 PM
Hi,
why not use record producer script itself and no BR is required
var FR = producer.files_required;
var arr = [];
var parsedData = JSON.parse(FR);
for (var i = 0; i < parsedData.length; i++) {
var obj = {};
obj['Proposed lock period'] = parsedData[i].proposed_lock_period;
obj['Comments'] = parsedData[i].comments;
obj['File date'] = parsedData[i].file_date;
obj['File Name'] = parsedData[i].file_name;
obj['Personal Information'] = parsedData[i].pi;
arr.push(obj);
}
current.setValue('description', JSON.stringify(obj));
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-24-2022 10:48 PM
Hi,
This is returning only one record to the field.