- 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 10:55 PM
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 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-02-2023 02:44 AM
Hi Ankur,
This is not working for me.
I have a variable set called posting under which i have 25 variables.
I am mapping each one to a record producer as below:
var FR = producer.posting;
var arr = [];
var parsedData = JSON.parse(FR);
for (var i = 0; i < parsedData.length; i++) {
var obj = {};
obj['Company Code'] = parsedData[i].u_company_code;
obj['Logical System'] = parsedData[i].u_logical_system;
obj['Posting Key'] = parsedData[i].posting_key;
obj['GL Account'] = parsedData[i].glaccount;
obj['Amount'] = parsedData[i].amount;
obj['Amountinloc Currency'] = parsedData[i].amountinloc_currency;
obj['Loc Currency'] = parsedData[i].loc_currency;
obj['Amount Glob Currency'] = parsedData[i].amount_glob_currency;
obj['Global Currency'] = parsedData[i].global_currency;
obj['New Cost Center'] = parsedData[i].new_cost_center;
obj['Order'] = parsedData[i].order;
obj['Wbs Element'] = parsedData[i].wbs_element;
obj['Network'] = parsedData[i].network;
obj['Profit Center'] = parsedData[i].profit_center;
obj['Assignment'] = parsedData[i].assignment;
obj['Text'] = parsedData[i].text;
obj['Plant'] = parsedData[i].plant;
obj['Tax Code'] = parsedData[i].tax_code;
obj['Trans Typ'] = parsedData[i].trans_typ;
obj['Trading Partner'] = parsedData[i].trading_partner;
obj['Tax Jurisdiction'] = parsedData[i].tax_jurisdiction;
obj['Business Area'] = parsedData[i].business_area;
obj['Activity'] = parsedData[i].activity;
obj['Value Date'] = parsedData[i].value_date;
obj['Posting Group'] = parsedData[i].posting_group;
arr.push(obj);
}
current.setValue('u_posting', JSON.stringify(arr));
I have created custom field called posting (string field)
I'm getting output as below:
Please help me if i have missed anything?
Thanks,
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 11:59 PM - edited ‎04-13-2023 12:00 AM
Hi @Ankur Bawiskar ,
I have same requirement tried with your script and mapped, I can add data to fields in string format. I want to add all the with ' , ' separated and I want to add to field only the values not with field name.
SCRIPT:
var envs = producer.environments;
var arr = [];
var parsedData = JSON.parse(envs);
for (var i = 0; i < parsedData.length; i++) {
var obj = {};
obj['Environments'] = parsedData[i].add_environments;
arr.push(obj);
}
current.setValue('environments', JSON.stringify(arr));
Please look into the images.
Now I can add like below
But I want to add only the data like below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 04:01 AM
Hi @Mad3
I'm facing the same issue where I am getting the field name as well along with the value, Did you have the solution for this now ?