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

Dr Atul G- LNG
Tera Patron

https://www.servicenow.com/community/developer-forum/multi-row-variable-set-client-script-to-do-some...

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743684

****************************************************************************************
Regards
Dr Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
******************************************************************************************

Ankur Bawiskar
Tera Patron

@kali 

you can grab the MRVS value in onSubmit catalog client script which Applies to Catalog Item and it gives you the JSON object

You can iterate over that and then grab the value

function onSubmit() {
    var mrvsValue = g_form.getValue('mrvsVariableSetName'); // give your MRVS variable set name here

    for (var i = 0; i < mrvsValue.length; i++) {
        var val = mrvsValue[i].userVariableName; // give here the variable name within MRVS
        alert(val);
    }

}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@kali 

Just following up to see whether my suggested solution worked for you.

If you're still facing any issues, I'd be happy to help further.

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

Chetna_Aggarwal
Tera Contributor

 

You can't directly access individual MRVS variable values from the parent catalog item's onSubmit Catalog Client Script.

Instead, retrieve the MRVS as JSON using g_form.getValue('<mrvs_variable_name>') and parse it.

 

 
var mrvs = JSON.parse(g_form.getValue('your_mrvs_name'));

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

If g_form.getValue() returns an empty value, please confirm whether you're using the Service Portal or the Native UI, as MRVS behavior differs slightly between them.