How do I populate a reference field in a MRVS, from onload script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 10:44 PM
Hi all,
I am trying to populate a multi row variable set via an onload script.
The mrvs is called software_requested, and contains two variables. 'justification' is a multi line text field, no problem. 'software' is a reference field and this is where I'm failing. I tried passing in the sys id of the documents I need to select, but no good. My code below.
Any assistance greatly appreciated.
Chris
function onLoad() {
//Type appropriate comment here, and begin script below
// function onLoad() {
var rowObj = [];
rowObj.push({
"actions": "",
"software": '32b3fd841baf3810183cffbdcc4bcb81',
"justification":"New starter - Advisory"
});
rowObj.push({
"actions": "",
"software": '10d3b9841baf3810183cffbdcc4bcb8e',
"justification":"New starter - Advisory"
});
g_form.setValue('software_requested', JSON.stringify(rowObj));
}
- Labels:
-
Multiple Versions
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 10:53 PM
Hi,
are you sure you are setting the correct sys_id of the record from the table which is being referred by software variable?
Not working for admins or non-admins?
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
07-10-2022 10:54 PM
Hi Chris,
Refer this article it may help you Multi Row Variable Set autofill from server side data.
Kindly mark correct and helpful if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2022 11:15 PM
Hello,
Please make sure you are doing below things correctly
1) passing the correct sys_id
2) while setting the value correct MVRS back end name and try using below code .
3) Make sure your client script is at catalog item level and not inside MVRS.
4) Also make sure you used correct back end names for field too(software and justification)
I removed actions element from JSON because we need set actions for MVRS that will be take care Automatically we just have to set the field values in key value pair like below.
function onLoad() {
var rowObj = [];
rowObj.push(
{
"software": '32b3fd841baf3810183cffbdcc4bcb81',
"justification":"New starter - Advisory"
},
{
"software": '10d3b9841baf3810183cffbdcc4bcb8e',
"justification":"New starter - Advisory"
}
);
g_form.setValue('software_requested', JSON.stringify(rowObj));
}
Please mark my answer correct it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 03:25 PM
Thank you all for your excellent assistance. Turned out to be a dumb user error. I hadn't checked properly and the field was not a reference, but a lookup select box. As soon as I converted it to a reference, all worked fine. Oops. Thanks again