Email notification firing multiple times when updating Multi-Row Variable Set (MRVS) in RITM

AnaLucíaR
Tera Contributor

Hi everyone,

I’m facing an issue with a Catalog Item in Employee Center. I have a form where users can schedule sessions and add participants using a Multi-Row Variable Set (MRVS).

  • The Workflow: When the form is initially submitted, an email is sent to all invited participants. This part works perfectly—no duplicates.

  • The Problem: When I open the Requested Item (RITM) later to add a new user to the session and save the record, the email notification is sent about 5 times to the user.

I am looking for a way to handle MRVS updates so that emails are only sent to the newly added row, or a way to prevent these duplicate triggers.

Has anyone encountered this? Should I be using a Business Rule with a specific condition, or is there a better way to compare the previous state of the MRVS with the new one?

Thanks in advance!

1 ACCEPTED SOLUTION

egonzalezmu
Tera Expert

Hello.

To trigger notifications only for new users added to the MVS from the created RITM, I can think of a couple of solutions. I'll share the one I think is best, the solution is basically to use a Business Rule to compare the previous MVS value with the new one and trigger notifications through an event.

 

  • You have a catalog item, for example: Sessions cat item
    egonzalezmu_0-1768622584940.png

     

  • You have added a MVS to the catalog Item to add sessions and users, for example: Schedule Sessions
    • User field is a referenced field to the sys_user table
      egonzalezmu_1-1768622714208.png

Here is where the solution starts:

  1. Create a new variable in the catalog Item: this field will store the current sessions
    egonzalezmu_2-1768622993863.png
  2. Create a client script in the catalog item: this will copy the MVS value to the new variable (Current Sessions) as a serialized JSON
    egonzalezmu_4-1768623250641.png
  3. Submit the catalog item
    egonzalezmu_5-1768623426435.png
  4. The RITM should look like this
    egonzalezmu_6-1768623480077.png
  5. Got to event registry module
    egonzalezmu_8-1768623789882.png
  6. Click on new and fill the fields
    egonzalezmu_9-1768623874499.png
  7. Create a business rule on the RITM table
    • When to run
      egonzalezmu_7-1768623537921.png
    • Advanced: 
(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    //getting MVS
    try {
		//Getting current sessions from the multiline text variable
        var previosSessions = current.variables.current_sessions + "";

		//Getting All sessions from the MVS variable
        var currentSessions = current.variables.schedule_sessions + "";

		//If they are differents it means a new session was added
        if (previosSessions.length != currentSessions.length) {
			//parsing the serialized JSONs to operate
            previosSessions = JSON.parse(previosSessions);
            currentSessions = JSON.parse(currentSessions);

			//Trigger the event only for the new added users
            for (var s = (previosSessions.length); s < currentSessions.length; s++) {
                gs.eventQueue('new.session.email', current, currentSessions[s]["user"]);
            }
            current.variables.current_sessions = JSON.stringify(currentSessions);
        }










    } catch (e) {
        gs.addErrorMessage(e);
    }

})(current, previous);​
  • Create a notification on the RITM table
    • When to send
      egonzalezmu_10-1768624095053.png
    • Who will receive
      egonzalezmu_11-1768624129095.png
  • Test the functionality
    • Add one or more users to the MVS 
      egonzalezmu_12-1768624237381.png
    • Save the record
    • Go to emails log and verify emails were sent only to the new added users
      egonzalezmu_13-1768624305581.png

       

View solution in original post

1 REPLY 1

egonzalezmu
Tera Expert

Hello.

To trigger notifications only for new users added to the MVS from the created RITM, I can think of a couple of solutions. I'll share the one I think is best, the solution is basically to use a Business Rule to compare the previous MVS value with the new one and trigger notifications through an event.

 

  • You have a catalog item, for example: Sessions cat item
    egonzalezmu_0-1768622584940.png

     

  • You have added a MVS to the catalog Item to add sessions and users, for example: Schedule Sessions
    • User field is a referenced field to the sys_user table
      egonzalezmu_1-1768622714208.png

Here is where the solution starts:

  1. Create a new variable in the catalog Item: this field will store the current sessions
    egonzalezmu_2-1768622993863.png
  2. Create a client script in the catalog item: this will copy the MVS value to the new variable (Current Sessions) as a serialized JSON
    egonzalezmu_4-1768623250641.png
  3. Submit the catalog item
    egonzalezmu_5-1768623426435.png
  4. The RITM should look like this
    egonzalezmu_6-1768623480077.png
  5. Got to event registry module
    egonzalezmu_8-1768623789882.png
  6. Click on new and fill the fields
    egonzalezmu_9-1768623874499.png
  7. Create a business rule on the RITM table
    • When to run
      egonzalezmu_7-1768623537921.png
    • Advanced: 
(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    //getting MVS
    try {
		//Getting current sessions from the multiline text variable
        var previosSessions = current.variables.current_sessions + "";

		//Getting All sessions from the MVS variable
        var currentSessions = current.variables.schedule_sessions + "";

		//If they are differents it means a new session was added
        if (previosSessions.length != currentSessions.length) {
			//parsing the serialized JSONs to operate
            previosSessions = JSON.parse(previosSessions);
            currentSessions = JSON.parse(currentSessions);

			//Trigger the event only for the new added users
            for (var s = (previosSessions.length); s < currentSessions.length; s++) {
                gs.eventQueue('new.session.email', current, currentSessions[s]["user"]);
            }
            current.variables.current_sessions = JSON.stringify(currentSessions);
        }










    } catch (e) {
        gs.addErrorMessage(e);
    }

})(current, previous);​
  • Create a notification on the RITM table
    • When to send
      egonzalezmu_10-1768624095053.png
    • Who will receive
      egonzalezmu_11-1768624129095.png
  • Test the functionality
    • Add one or more users to the MVS 
      egonzalezmu_12-1768624237381.png
    • Save the record
    • Go to emails log and verify emails were sent only to the new added users
      egonzalezmu_13-1768624305581.png