- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 05:58 AM
Hi Team,
I have a requirement where i have to pre fill the MRVS which has single column based on certain check box and variable inside MRVS is the reference field. How can i acheive this using on submit client script.
Refer the below img.
Based on those two options the below MRVS to be filled eg. if 'prd' is selected group 'ABC' to be populated in AD group 1.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 06:28 AM
Since you want to do this onSubmit of the Request form, 1) You should hide the MRVS on the request form, or at least make it read-only so that the submitter does not populate it, and 2) It may be easier/better to do this in a workflow Run Script since you don't need to see the change happen on the client screen. The MRVS would still be populated by the time anyone viewed the RITM record, and/or a Catalog Task or whatever happens next.
In any event, to populate an MRVS, you just need to set the value of the variable to a JSON formatted object. Since your criteria is set, the script would look something like this:
function onSubmit() {
var answerArr = [];
if (g_form.getValue('prd') == 'true') { //replace with your variable name
answerArr.push('{"ad_group_1":"1232132443dsdfff3123"}'); //replace with your MRVS variable name and sys_id
}
if (g_form.getValue('test') == 'true') { //replace with your variable name
answerArr.push('{"ad_group_1":"7586978569safjkdsfjjk45jk45"}'); //replace with your MRVS variable name and sys_id
}
g_form.setValue('mrvs_internal_name', answerArr.join(',')); //replace with your MRVS name
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 06:28 AM
Since you want to do this onSubmit of the Request form, 1) You should hide the MRVS on the request form, or at least make it read-only so that the submitter does not populate it, and 2) It may be easier/better to do this in a workflow Run Script since you don't need to see the change happen on the client screen. The MRVS would still be populated by the time anyone viewed the RITM record, and/or a Catalog Task or whatever happens next.
In any event, to populate an MRVS, you just need to set the value of the variable to a JSON formatted object. Since your criteria is set, the script would look something like this:
function onSubmit() {
var answerArr = [];
if (g_form.getValue('prd') == 'true') { //replace with your variable name
answerArr.push('{"ad_group_1":"1232132443dsdfff3123"}'); //replace with your MRVS variable name and sys_id
}
if (g_form.getValue('test') == 'true') { //replace with your variable name
answerArr.push('{"ad_group_1":"7586978569safjkdsfjjk45jk45"}'); //replace with your MRVS variable name and sys_id
}
g_form.setValue('mrvs_internal_name', answerArr.join(',')); //replace with your MRVS name
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 09:49 PM
Thanks! it was very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 08:32 AM
You are welcome!