How to hit dynamic End point URL along with parameters from service-now

Lucky1
Tera Guru

Hello all,

 

Using a scripted REST API, a catalog item request will be created.

The customer enters a URL along with some parameters in a variable.

So, I have configured a rest outbound message and calling that from business rule before task closure.

 

Now, the customer is saying that he will change the Base URL every time he creates a request in service-now and we need to hit that URL.

So, we cannot use rest outbound message here. 

So, can someone tell me how to hit the dynamic URL every time we receive it in a catalog item variable??

What script we need to write?

 

 

Regards,

Lucky

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

you can set the endpoint using RESTMessageV2 this function setEndpoint(), don't configure endpoint there in REST Message or whatever you give it will pick based on what you pass in this method in script

RESTMessageV2 - Scoped, Global 

AnkurBawiskar_0-1743998427721.png

OR Best Way

1) Don't use REST Message and don't create REST Message, you can still consume the endpoint and send request without creating a REST Message in system using Recordless REST Message

2) check this link

Recordless RESTMessageV2 example 

AnkurBawiskar_1-1743998532383.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

18 REPLIES 18

Hi Shivalika,

 

These are the screen shots of the REST outbound message I configured.

Now he is saying, the End point URL is not fixed, and it might change along with parameters also.

Like sometimes he might send 2 parameters in the URL, and sometimes he may send 4 parameters and so on......

 

Note: He is sending the web hook URL, in a variable of a catalog item when submitted.

let's consider that variable name in that cat item is: Enter the URL here (u_url)

 

Screen shots:

Lucky1_0-1743832493607.png

 

QUery Parameters

Lucky1_1-1743832597287.png

 

Now, how can we configure every time the number of parameters he will send?

 

Please guide me.

 

 

Regards,

Lucky

 

 

 

Hello @Lucky1 

 

In the endpoint just pass this https://<sitename.com> (if there is something common) and append it with 

${endpoint}

 

In the "preview script usage" you would get script , there you will see "sn_ws.setParameter('endpoint',.....)

 

I am giving this because I named the path parameter as endpoint - you choose yours. 

 

Now in value of this parameter - just pass your url value. You don't need to micromanage the number of parameters he is passing - full endpoint is the parameter. 

 

I hope you get this now. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Hi,

 

1)    Are you speaking about REST Outbound message???

2)   

In the endpoint just pass this https://<sitename.com> (if there is something common) and append it with 

${endpoint}

------ I did not understand this. Are you telling me to configure a HTTP Query Parameter as endpoint and what could be the End point url of the rest message? is it something like,

https://<sitename.com>--------

So are we passing the End point url to the rest message dynamically?

 

3) In the "preview script usage" you would get script , there you will see "sn_ws.setParameter('endpoint',.....)

-------- I see only this below one when I clicked on Preview script usage as of now--------

Lucky1_0-1743833637349.png

 

 

Regards,

Lucky

 

Hello @Lucky1 

 

Yes it's rest outbound messages. 

 

Let me get on my Computer and share you screenshot of process shortly. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Ok SHivalika.

 

I am also opening my personal dev instance here.