I want to change the variable (single line text ) in MVRS on change of variable in catalog item

sariksorte
Tera Contributor

I want to change the variable (single line text ) in MVRS on change of variable in catalog item. 

can anyone suggest something

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@sariksorte 

so variable within MRVS should change based on outside variable?

If yes then use this logic to access the outside variable in client script which applies to MRVS
sharing here as well

You can access the variables with this syntax. This works in both Native + Portal

var applicationType = g_service_catalog.parent.getValue("variableName");

Example: I have used an onLoad catalog client script which applies to MRVS and it gave me the value of outside variable when the MRVS form was loaded.

Client Script:

AnkurBawiskar_0-1741841488526.png

 

 

Output in Native:

AnkurBawiskar_1-1741841488253.png

 

 

Output in Portal:

AnkurBawiskar_2-1741841488234.png

 

 

I created blog for the same recently

Access value of catalog item variable within MRVS client script 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

GopikaP
Mega Sage

Hi @sariksorte , you may try the following: 

  • Create an onChange client script for the catalog item, where the field change variable is the one whose value change should trigger an update in a single-line text variable inside the MRVS.SC1.png

     

     

  • Within the same onChange client script, you can update the rows accordingly.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //Type appropriate comment here, and begin script below.
    var mrvs = JSON.parse(g_form.getValue('mrvs')); //your MRVS name

    var rows = mrvs.length;
    if (rows > 0) {
        for (var i = 0; i < mrvs.length; i++) {
            mrvs[i].single_line_variable = 'Value you need to update';
        }
        g_form.setValue('mrvs', JSON.stringify(mrvs));
        alert(rows + ' rows affected by the change in the "Requested For" field value.');
    }

}​

 

  • Please see the results, if this is what you are expecting? SC2.pngSC3.pngSC4.png

One more question: Are you trying to update a specific row based on certain conditions, or do you need to update all rows inserted so far?