- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 03:53 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 06:24 PM - edited 10-31-2022 06:25 PM
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)'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2022 06:24 PM - edited 10-31-2022 06:25 PM
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)'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2022 06:23 AM
Hi Mike,
Yes, "u_additional_info" is my custom table and "u_parent_info" is my parent reference field. I believe the code is correct but its not working. I can add a record as the parent and still add it as a child for another ticket.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2022 06:28 AM
1 .Check to make sure the script include is accessible from All Application Scopes
2. Check the errors logs for any errors.
3. Check the cross scope privileges to make sure there is nothing denied between scopes
instanceName.service-now.com/sys_scope_privilege_list.do?sysparm_query=&sysparm_view=
4. Run your code from a background script to see if it works there. Obviously you'll need to tweak the code first before running in a background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2022 07:43 AM
Hi Mike,
1. The script include has the same setting as your screenshot. I never changed it.
2. Is there a specific error I should be looking for? Keywords to search for?
3. There isn't a separate application. I created this in the Global scope so it should be okay.
4. I ran the code in the background script and got this error:'
[0:00:00.383] Script completed in scope global: script
Script execution history and recovery available here
Evaluator: com.glide.script.RhinoEcmaError: Cannot read property "u_parent_info" from null script : Line(16) column(0)