Remote Tables Definition: Is there a possibility to pass value dynamically

pm5481
Tera Contributor

I want to pass dynamic filter value for REST message used in Remote Definition. Is this achievable?  if yes, let me know the possible ways to pass the filter value.

 

var r = new sn_ws.RESTMessageV2('x_1224_abcd', 'GetID');
        r.setStringParameterNoEscape('endPoint', 'https:/abcwelcom.ages/vp12s');
        r.setStringParameterNoEscape('filter', 'startswith"glass")');
7 REPLIES 7

Community Alums
Not applicable

Hi @pm5481 ,

Yes, you can pass dynamic filter values to a REST Message used in a Remote Definition in ServiceNow. There are a few ways to do this, depending on how you have set up your REST Message and how you want to pass the filter dynamically.

 

 

  • Define a variable in your REST Message URL or query, like ...?filter=${filter}.

  • In your script, set the variable dynamically:

var r = new sn_ws.RESTMessageV2('x_1224_abcd', 'GetID');
r.setStringParameterNoEscape('filter', 'startswith("glass")');
r.setStringParameterNoEscape('endPoint', 'https://abcwelcom.ages/vp12s');
var response = r.execute();

 

This replaces ${filter} with your dynamic value at runtime.

If your API expects the filter in the query, you can also use:

 

r.setQueryParameter('filter', 'startswith("glass")');

 

Ankur Bawiskar
Tera Patron
Tera Patron

@pm5481 

it all depends on if your 3rd party supports this

Did you check that with them?

If yes then you should check with them how the filter has to be applied and what's the pattern for it.

Ask for sample Request body if it's POST or sample endpoint if it's GET

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

shantanu_patel8
Mega Guru

Hi @pm5481 ,

 

From the information you have shared it looks like you are having a HTTP method "Default GET" used for the purpose.

 

The best way to achieve this would be to use HTTP query parameters defined for your filter and then use variable substitution while you are calling the REST method via script.

 

Please refer to the solution : https://www.servicenow.com/community/developer-forum/how-to-pass-query-parameter-dynamically-in-rest...

 

Please mark the answer helpful by clicking 👍 and correct if it resolves the issue. Happy scripting 🙂

 

-Shantanu

 

 

Thank you all for your responses, let me reframe my question.

I want to use the Remote table in catalog item reference variable, to use the response returned from API call. I am getting the response from API call by static values as of now. but wanted to pass values dynamically.

 

scenario: When a user enters string value 'UserID' on the form, then I want to pass 'UserID' value to Remote definition as dynamic filter. Is this possible or not