Populating response in MRVS using onSubmit client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi all,
I am getting the expected response but not able to populate/ set value in MRVS field, Please suggest
based on the attachment 'employee id's will be populated in mrvs and onsubmit associated first and last name should be populate in the mrvs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi there, this is a common MRVS gotcha..
Even if your GlideAjax response looks correct, the MRVS will only populate if you set the MRVS variable itself the multi-row set field and the value you pass is JSON in the MRVS row format array of objects keyed by the MRVS variable names.
Lets see please check:
Make sure you’re doing g_form.setValue('<MRVS_VARIABLE_NAME>', JSON.stringify(rows));
not setting a field inside the MRVSThe JSON must be like:
[ {"u_employee_id":"123","u_first_name":"John"}, {"u_employee_id":"456","u_first_name":"Jane"} ]Where the keys match the variable names inside the MRVS.
If you’re calling GlideAjax in a loop don’t set the MRVS inside each callback and async responses can overwrite each other. Build the rows array and set the MRVS once after all responses return.
Once I switched to setting the MRVS field directly and only updating it once at the end, it populated consistently.
@Ankita9793 - Please mark as Accepted Solution and Thumbs Up if you found Helpful!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
it might be challenging to set the MRVS onSubmit as by the time you set the form might submit
why not use onChange catalog client script to populate the MRVS?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
when you are returning value from script include pass the exact json string so that you can directly set it rather than parsing in client side
example: your json should be array of json objects like this
[
{
"first_name":"Abel",
"last_name":"Tuter",
"employee_id": "8978"
},
{
"first_name":"Beth",
"last_name":"Anglin",
"employee_id": "89895456"
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader