Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Vishal Birajdar
Giga Sage

Hello @surbhi_123 ,

 

You need to create new function in Script include and directly call that function in Business rule & no need to use GlideAjax

You can adjust the code in script include to run for business rule.

 

e.g .,

var si =  zenderskSender();  // name of script include

si.sendAttachment();   //function name

 

 

Vishal Birajdar
ServiceNow Developer

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

and how can I pass the attachment sys id and content type to the script include

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