Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Example that can be used to capture MRVS values, including when a record is deleted

Guilherme Mazie
Tera Contributor

⚙️ 2️⃣ Detecting MRVS changes to update the main form

Now imagine you want to automatically update a “Total” field every time a row is added, removed, or modified in your MRVS.
How can you achieve this, considering the MRVS has its own event scope?

The solution: use a listener to detect any changes in the main form.
Create a Catalog Client Script of type onLoad and add the following event:

/*

Example that can be used to capture MRVS values, including when a record is deleted — a scenario for which there is currently no native event for row deletion.

Example code

GuilhermeMazie_0-1763117352437.png

 

GuilhermeMazie_1-1763117376646.png


check link : https://pastebin.com/4fYa8Wtj

GuilhermeMazie_0-1763116973591.png

 

💡 With this approach, any modification in the MRVS automatically updates the “Total” field in the main catalog form.

⚠️Important: Although this solution works well in many scenarios, it is essential to validate it with the platform architect or follow the best practices established by the development.

#ITSM#SERVICENOW

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Guilherme Mazie 

thanks for sharing.

Could you explain why onSubmit script was used?

It would be nice if you explain the scripts

Will this also work in native or only in portal and in both catalog item and record producer?

Also it would be nice if you share the scripts rather than the link to it, the link doesn't open up.

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

 

Sure!


Yes, this approach should work for both catalog items (sc_req_item) and record producers.

The submit event is used to remove the event listener and prevent memory leaks. That’s why, in the onLoad, we assign the following snippet:


scope._refDereg = scope.$on('field.change', customListener);


This way, during submit, we can access scope._refDereg and properly unbind the listener.


**** I had to change some words in the script because the community does not allow certain words.


It’s important to note that I cannot guarantee 100% that this won’t have any impact on other form behaviors. Still, it’s worth sharing so the community can provide feedback — and because it offers a practical way to handle scenarios such as:

  • Dynamically populating multiline fields

  • Performing calculations when rows are added, modified, or deleted

  • Reacting to updates in internal tables or MRVS


 

@Guilherme Mazie 

Will this also work in native or only in portal?

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

I only tested it on catalog items via portal, mainly because ServiceNow doesn't recommend updating variables after the requester has been sent.