How to populate data to MRVS using onsubmit client script

Bindhu1
Tera Contributor

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.

Bindhu1_0-1674136527684.jpeg

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

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
}

 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

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
}

 

Thanks! it was very helpful.

You are welcome!