Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

ITSM Catalog item

kali
Tera Contributor

Hi All,

I want to populate the variable's value which is inside the MRVS onto the onsubmit catalog client script , however i am not able to access the mrvs value from the onsubmit client script which applies to the catalog item.please help me on this

6 REPLIES 6

ajmalmuhamm
Tera Contributor

Hi @kali ,

 

If you're trying to access a value from a Multi-Row Variable Set (MRVS) in an onSubmit Catalog Client Script, you can retrieve the MRVS value using g_form.getValue() and then parse the returned JSON.

For example:

function onSubmit() {
    var mrvsValue = g_form.getValue('your_mrvs_name');

    if (mrvsValue) {
        var rows = JSON.parse(mrvsValue);

        for (var i = 0; i < rows.length; i++) {
            var value = rows[i].your_variable_name;
            console.log(value);
        }
    }

    return true;
}

Make sure you use the MRVS internal name with g_form.getValue(), and inside each row use the internal name of the variable, not its label.

If you need to populate another catalog variable based on a value inside the MRVS, you can extract the required value first and then use g_form.setValue() before returning true.

vsrahul127
Mega Contributor

Hi @kali

 

You can access the values of variables inside an MRVS from the Catalog Item onSubmit Catalog Client Script by using g_form.getValue() to retrieve the MRVS data and then parsing the returned JSON.

 
function onSubmit() {
    var mrvs = g_form.getValue('your_mrvs_name');

    if (mrvs) {
        var mrvsData = JSON.parse(mrvs);

        for (var i = 0; i < mrvsData.length; i++) {
            alert(mrvsData[i].your_variable_name);
        }
    }}

Please note:

  • Replace your_mrvs_name with the Name of your MRVS.
  • Replace your_variable_name with the Name of the variable inside the MRVS.
  • g_form.getValue() returns the MRVS data as a JSON string.
  • JSON.parse() converts the JSON string into an array, allowing you to access each row and its variables.

I hope this helps! If this solution resolves your issue, please consider marking this answer as Correct.