The CreatorCon Call for Content is officially open! Get started here.

How to Limit a Reference Variable in an MRV for the same value selected in the first Row

Peter Williams
Kilo Sage

good morning everyone,

so i have a trick request to configure,

i have an MRV with a reference variables that is looking up on the cmn_department table

 

i want to have the ability to auto fill the other row users will select with the same value they selected in the first row of the MRV.

 

Example:

 

the Department Column u selected Office Expenses

 

PeterWilliams_0-1712240365919.png

 

i want every other row to only show Office Expenses and not have the users be able to select anything else but Office Expenses base on their first row

so all other rows will only have the Office Expense and nothing else

 

is this possible with an onChange script?

 

1 ACCEPTED SOLUTION

maroon_byte
Mega Sage

Consider having Department variable outside of your mrvs in the form as well.. After the user selects this form Department variable and is adding first mrvs row, use onLoad script within mrvs to set the read-only mrvs Department field using below script:

 

var dept = g_service_catalog.parent.getValue('department');
    g_form.setValue('mrvs_dept', dept);

View solution in original post

21 REPLIES 21

i created this script to push the Type into the MRV but it shows a blank value in the MRV reference variable

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var type = g_form.getValue('type');

  var obj = (g_form.getValue('items_mrv')) ? JSON.parse(g_form.getValue(items_mrv)):[];

obj.push({department_vc: type});
g_form.setValue('items_mrv', JSON.stringify(obj));
   
}
 
 
PeterWilliams_0-1712243468519.png

 

Also i like to expand on the script for when they select the Type a popup window will appear to ask how many items for them to enter and then it will create those rows below

 

'

i was able to get it to work by changing the Type variable to a reference but now the GL code Ref. Q. doesnt seem to work

 

Well I thought you could just do a g_form.getValue("MRV NAME"); but that does not appear to work on Service Portal or I'm getting the name wrong on my end.

 

So a little experiment and I found you could use 

this.myVar = "The value they selected";

 

So you can use an onChange script to set the value and then use an onLoad script to set the value for the new row and mark it read only when it has a value.

 

If you are not doing this on Service Portal you can try parent.g_form.getValue("MRV_NAME") to see if you can get the value.

 

do you have the full code?