How to use Client script code in Business rule

surbhi_123
Tera Expert

I have a onLoad Client Script on incident table which takes hard-coded values-

surbhi_123_0-1693995345287.png

It calls the Script include -

surbhi_123_1-1693995437516.png

The sys id in the client script is of the attachment added to the incident table, but it is hardcoded. To make it dynamic I wrote the same thing in BR. I wrote the BR on attachmet table as follows -

surbhi_123_2-1693995555778.png

But it gives error as - 

surbhi_123_3-1693995583395.png

How to correct this

1 ACCEPTED SOLUTION

Its better to use new script include : 

 

Business Rule

var attachmentSysId = current.sys_id; //will pass in function parameter
var apiEndpoint = 'your link'; //will pass in function parameter

var si = new ZendeskSender(); //Script include
//store return value to use further
var getReturnValue = si.sendAttachment(attachmentSysId,apiEndpoint); // function

//do your activity


 

Script include :

sendAttachment : function (attachmentSysId , apiEndpoint) {
            var attachment = new GlideSysAttchment();
           //below code will be same as per your existing code
}
Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

12 REPLIES 12

OlaN
Giga Sage
Giga Sage

Hi,

The GlideAjax call is used to interact between the client (browser) and the server (database).

A business rule runs on server side, so there is no need to call the GlideAjax (and the class is not defined here either).

You can instead call on your script include directly like so:

var someVariable = new global.ScriptIncludeName().functionName(parameters);  // replace global with scopename if the scriptinclude is not a Global script include.

How can I call the two parameters that I have here

If your script include function allows it, you can just add additional parameters, like below

var someVariable = new global.ScriptIncludeName().functionName(param1, param2, param3);

 

Providing another example, more close to your scenario:

new global.ZendeskSender().sendAttachment(current.getUniqueValue(), apiEndpoint);