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

Aman Kumar S
Kilo Patron

GlideAjax is not supported in server side scripts which is BR, it only works in client script which client side scripts.

SO you have to first move the code from current client callable script include to a server side script include, and call that from your business rule.

 

Best Regards
Aman Kumar

How can I do that, 
I have removed the Client callable checkbox from client script

surbhi_123_0-1693996216166.png

And how should I call the parameters

You will have to write a similar function to be consumed on server side.

 

In your client script i see two variables - attachment_sys_id and endpoint_url

 

so in your script include, create a new function 

 

sendAttachmentServer: function(attachment_sysid, endpoint_url){

//your code goes here

}

 

now call this function from your BR as

 

var zsk = new zenderskSender();

zsk.sendAttachmentServer(attachment_sysid, endpoint_url)

 

 

Regards,

Vismit

And where I will pass the value of attachment sys id and endpoint url

In your BR, remove line number 7 to 18

 

instead, put below:

var zdsk = new global.ZendeskAttachSender();
var response = zdsk.sendAttachment(attachmentSysId, endpointUrl);

 

Now, create a new script include (you can keep client callable as checked because you can still use this for calls from server side)

var ZendeskAttachSender = Class.create();
ZendeskAttachSender.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	sendAttachment: function(attachmentSysId, endpointUrl){
		//your logic goes here
	},
    type: 'ZendeskAttachSender'
});

Let me know if this does not work.

 

Regards,

Vismit