Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Prevent Recursive loop script

Pat Surtan
Tera Expert

Hello,

 

There is a parent/child feature in Incident Management where a record can be added to an incident as that incident's parent record. If the parent record has been added, that same record cannot be added as a child. This is a OOTB recursive script.


I want to create this same feature to prevent recursive loop in my custom table. Can someone provide a script for me to use? I found the OOTB script, modified it but it doesn't work. No errors and I can add one ticket as both the parent and a child, which isn't correct. 

 

Here is the OOTB script I modified.

 

var rt = new RecursionTester('u_additional_info', 'u_parent_info');
if (rt.isRecursive(current)) {
current.setAbortAction(true);
current.u_parent_info.setError(gs.getMessage('Invalid Parent Info'));
gs.addErrorMessage(gs.getMessage('The selected Parent Info loops back to this record (recursive sdq ticket loop)'));
}

 

Thanks in advance. 

1 ACCEPTED SOLUTION

Mike_R
Kilo Patron

is 'u_additional_info' your custom table name?

 

var rt = new RecursionTester('tableName', 'parentReferenceFieldName');
if (rt.isRecursive(current)) {
current.setAbortAction(true);
current.parentReferenceFieldName.setError(gs.getMessage('Invalid Parent Incident'));
gs.addErrorMessage(gs.getMessage('The selected Parent Incident loops back to this record (recursive incident loop)'));
}

View solution in original post

8 REPLIES 8

Your script looks fine and I compared it to several other OOTB business rules.

Stupid question, but can you confirm these settings on your business rule

Mike_R_0-1667315496692.png

 

Yes, it matches your screenshot.

 

when: before

Insert: true

Update: true

 

I'm not sure why it isn't working. 

I'm at a loss. I would suggest opening a case with support in the meantime.

If i think of anything else i will post here.

Hi Mike,

 

Thank you for helping out. Is there any other script I might have overlooked and that is why it isn't working?