How to set default value of a field in MRVS based on another field outside MRVS?

dianemiro
Kilo Sage

Hi Everyone,

I want to set the default value of Company field in MRVS based on Company field outside MRVS. Is this possible?

Thanks,
Diane

1 ACCEPTED SOLUTION

Phonsie Hevey1
Tera Expert

Have a look at ryanlitwiller reply on https://community.servicenow.com/community?id=community_question&sys_id=5d28d390db272300fb115583ca961920.

 

this.NOW.[myAttributteName] = g_form.getValue("myfield");

However this doesn't seem to work in the back end but only in the Service Portal from what I can see.

 

View solution in original post

8 REPLIES 8

Manish Vinayak1
Tera Guru

Hi Diane,

You can set value in MRVS using both client script and server side script (I haven't tried the Server Side bit, but it should work):

Client Side Script:

//Considering there are 2 variables, variable1 and variable2 in your MRVS variable set, and the variable set's internal name is mrvs

var obj = [{"variable1" : "value1", "variable2" : "value2"},  {"variable1" : "value1", "variable2" : "value2"}];

g_form.setValue("mrvs", JSON.stringify(obj));

Server Side Script:

//Considering there are 2 variables, variable1 and variable2 in your MRVS variable set, and the variable set's internal name is mrvs

var obj = [{"variable1" : "value1", "variable2" : "value2"},  {"variable1" : "value1", "variable2" : "value2"}];

current.variables.mrvs = JSON.stringify(obj);

 

You will have to create the JSON object for the values you want to set, and then stringify the JSON object to be set to the MRVS variable.

 

Here is another helpful post on the scripting on MRVS:

https://community.servicenow.com/community?id=community_blog&sys_id=865b5aeddbc023c0feb1a851ca9619f9

 

Hope this helps!

Cheers,

Manish

 

Hi Manish,

Thanks for your response. But I am looking for a way to set a field inside MRVS based on another field that is NOT in MRVS. Your code I think is for if both fields are inside MRVS.

Thanks,
Diane

If you look at the below excerpts from docs, the functionality is not yet present.

  • Scripts that are not included in a multi-row variable set cannot affect variables inside the multi-row variable set. Similarly, the scripts included in the multi-row variable set cannot affect the variables that are not included in the multi-row variable set.

dianemiro
Kilo Sage

I still haven't got any luck on this. Any ideas?