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.

Substitute variable to Rest Message endpoint from script include/business rule

John_123_Snow
Mega Expert

Is it possible to substitute variable to endpoint for Rest Message? I need to pass sys_id of attachment into Delete HTTP method. I have something like this:

find_real_file.png

and in my script include and I have this: 

deleteAttachment: function (helloAttachmentSysID) {
	var request = new sn_ws.RESTMessageV2('hello eBonding', 'Delete Attachment');
        request.setStringParameter("sys_id", helloAttachmentSysID);
	var response = request.execute();
	var responseBody = response.getBody();
	var httpStatus = response.getStatusCode();
}

and of course in the business rule I am passing sys_id into deleteAttachment(helloAttachmentSysID);

but I cant seem to know how to pass it into that endpoint that current sys_id? what am I doing wrong?

I know I can do something like 

var endpoint = 'attachment/sys_id/endpoint/' + current.sys_id;

request.setEnpoint(enpoint); but I do not want to overwrite that...and would like to use the feature of substituting.

How do I achieve this? 

 

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi John,

You're missing the $ which allows for substitution

find_real_file.png

find_real_file.png

Your actual script is fine, it's just the endpoint missing the $ which is meaning your variable isn't being correctly substituted.

View solution in original post

4 REPLIES 4

Kieran Anson
Kilo Patron

Hi John,

You're missing the $ which allows for substitution

find_real_file.png

find_real_file.png

Your actual script is fine, it's just the endpoint missing the $ which is meaning your variable isn't being correctly substituted.

Thanks, I must have missed it when I was copying...

ha not a problem! just needed a fresh pair of eyes to see it 😉

Exactly!