Calling a Script Include from a Business Rule (both in same scope)

CraigW1
Giga Contributor

I am trying to call a Script Include from a business rule on a Madrid instance. The problem is that when I try to initialize it, I get the following error: "The undefined value has no properties". To rule out any issue from my own Script Include, here's an example using a built in (to Security Incident Response app) Script Include that throws the same error:

Business Rule:

Table: sn_si_incident
Application: Security Incident Response
Active: True
Advanced:True:
When to run:
When: After
Order: 100
Insert: True
<No Filter Conditions/Role Conditions>

(function executeRule(current, previous /*null when async*/) {


gs.warn("Calling incident utils");
var x = sn_si.SecurityIncidentUtils();
gs.warn("Successfully called incident utils");
})(current, previous);

Both the Script Include (sn_si.SecurityIncidentUtils) and my business Rule are in the Security Incident Response application. The first warn message prints,the second does not, and I get the following error in my log:

On my New York Personal Developer instance, I get similar behavior, but I get an additional error message (in addition to the one above):

org.mozilla.javascript.EcmaError: The undefined value has no properties.
Caused by error in sys_ui_action.42da42d00a0a0b340066377beb6dd099.script at line 1

==> 1: (function executeRule(current, previous /*null when async*/) {
2:
3:
4: gs.warn("Calling incident utils");

 

I also tried removing the `sn_si` Script Include namespace: var x = SecurityIncidentUtils()

That did not change the errors.

1 ACCEPTED SOLUTION

The issue you are facing is because you are calling the script include but not callingthe function of Script Include which you wants to get executed.

Please refer to one of the OOB Business Rules where the same script include and function is being called and executed without any issues. The same was intended in my very first comment.

OOB Business Rule: Close child security incidents

Script: 

// closes or cancels any active child SIs when the parent SI is closed or cancelled
function onAfter(current, previous) {
   new sn_si.SecurityIncidentUtils().closeActiveChildSecurityIncidents(current);
   new sn_si.SecurityIncidentUtils().closeAssessments(current.getUniqueValue());
}

So you can refer to the above script and see that the same script include "SecurityIncidentUtils" is called and the function "closeActiveChildSecurityIncidents" & "closeAssessments" is being called.

closeActiveChildSecurityIncidents: It closes all the active child records associated with the current record.

closeAssessments: Closes all the assessments of the child records.

 

Similarly you need to define the function which you want to be evaluated.

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Alok

View solution in original post

9 REPLIES 9

Alok Das
Tera Guru

Hi,

Please find the sample code for initializing the script include from business rule:

var xyz = new scriptIncludeName();
xyz.functionName(param1, param2);


Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Alok

CraigW1
Giga Contributor

It's throwing an error on the `var xyz = new scriptIncludeName();` part. So that doesn't resolve the problem, unless I'm mis-understanding your answer

(Yes, I replaced scriptIncludeName with SecurityIncidentUtils)

Thanks,

Craig

Just few questions,

  1. Is the business rule and script include both in same scope of application? If not you need to set it to be accessible from all application scopes and use the api name instead of just script include
  2. The client callable checkbox in script include is unchecked?

CraigW1
Giga Contributor

1. They are in the same application scope (Security Incident Response app). It is marked to  be accessible from "All application scopes". I have tried both including the api name (sn_si) and leaving it out.

2. The client callable box is unchecked.