The business rule was executed twice in a row

Dat Phan
Tera Guru

I have a business rule with information:

    + "When" = "after"

    + "Condition" = "Only run when user change status to "A"".

When this business rule is run, I have create a new record into the "test_function" table.

I have an UI Action to be "Test Process". When user click to the UI Action, it will change request's status to "A". Sometimes when I click on UI Actions. About 2-3 records are created. I don't know what happened.

I think there are two possible cases:

    + Case 1: double click or  double submit when click the UI Action.

    + Case 2: SN transaction management automatically reimplements when a transaction fails, but the business rules of the failed transaction are still implemented.

For case 1, I will try to use GlideRecord to update a field before implementing the business rule. But when updating data with setWorkflow = false, can the update transaction be executed immediately? And that transaction is independent of the current transaction?

In case 2, I don't know if SN has that mechanism? And how to fix it?

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Dat Phan 

what's being done in your UI action? Are you simply updating the state to 2? If yes then this will trigger the Business rule

To handle if user clicks the UI action again and Business rule doesn't trigger, add this condition in after update BR

Status [Changes To] A

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@anku yes. I only change the state to "A". But sometimes business rules are re-implemented about 2-3 times.

@Dat Phan 

seems user is clicking the button multiple times

To handle this try to query the target table and see if record already created, if not then only create new.

If already created then ignore.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Animesh Das2
Mega Sage

@Dat Phan ,

 

Just to have more information, can you share screenshots of the UI action and the BR? I assume those could be the simple ones anyways considering your use case.

Otherwise to find out the actual root cause you may try some troubleshooting as below, 

a) You may put some log statement/s in your BR to see how many times that got printed in the logs.

b) Verify if there are multiple BRs (may be not written by you) get triggered after the status change and do the same action that your BR does.

c) Instead of your UI action changes the status if you change the status manually then if still record/s gets created multiple times. To ensure if the issue with the click on UI action or not.

d) Put some log statement/s in the UI action as well to see if the UI action is getting clicked multiple times by mistake.

 

Lastly if you don't want to waste much time in finding the root cause and rather you want some workaround to prevent multiple records creation with same criteria after already a record is created, you may follow the suggestion that @Ankur Bawiskar has suggested.

 

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das