On deleting row from MRV run catalog client script

sravanip
Tera Contributor

Hi,

 

While adding row in MRV or deleting by using 'x' or 'Remove All' I want to execute MRV catalog client and make the variable in the catalog item mandatory/non mandatory. 

 

scenario:

 

1. if value entered in MRV matches criteria and the variable in catalog is made mandatory, then on removing this particular MRV value should non mandate the variable.

 

2. if value entered in MRV does not match criteria then make catalog variable non mandate. and on adding valid mrv value should mandate the catalog variable.

3 REPLIES 3

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @sravanip ,

Please check out this link which will help you.

https://www.servicenow.com/community/developer-articles/solved-issue-with-mrvs-multi-row-variable-se...

 

Thank you,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Its_Azar
Tera Guru

Hey there @sravanip 

 

Write a catalog client script that will be triggered when adding or removing a row in the MRV. 

Define the criteria that determine whether the variable should be mandatory or non-mandatory based on the value entered in the MRV. 

In the catalog client script, implement the logic to check the value entered in the MRV against the defined criteria. If the criteria are met, make the variable mandatory; otherwise, make it non-mandatory.

Bind the catalog client script to the MRV field events such as onAddRow and onRemoveRow. 

 update the state of the variable in the catalog item to reflect whether it should be mandatory or non-mandatory.

sample catalog client script below

 

function onAddRow() {
    if (valueMatchesCriteria) {
        g_form.setMandatory('variable_name', true);
    } else {
        g_form.setMandatory('variable_name', false);
    }
}

function onRemoveRow() {
}

 

If this helps kindly accept the res[ponse thanks much. 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

I already have code in place when we add row through 'Add' button. but the issue is how to detect delete row using 'x'. This action is not calling the client script I wrote in the MRV.