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")');
9 REPLIES 9

pm5481
Tera Contributor

Thank you all for your reply, let me reframe my question.
I want to pass dynamic value to remote definition, so that I can use the remote table in reference field on catalog item. 

pm5481_0-1747638128825.png

 

pm5481
Tera Contributor

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

 

pm5481_0-1747640602497.png

 

sadafkhan
Tera Contributor

@pm5481  - Have you resolved this? as i am also facing same.

Alex Karas
ServiceNow Employee

There are a couple of months now, but I'll post it here just for anyone else looking at a solution on this.

You can actually use query condition "creatively" to pass parameters to the definition script or flow - just take any parameter name that is not a field on your table and pass it on your query.

Let's take an example where I just use gliderecord to populate a remote table I build with incidents. I'm parsing a "test_parameter" field on the applied query using v_query - there is no actual dictionary definition for that on the remote table, I only use that to inject a parameter into my definition script:

(function executeQuery(v_table, v_query) {

	var test_parameter = v_query.getParameter("test_parameter");

	var grinc = new GlideRecord("incident");

	if (test_parameter=='1'){
		grinc.addActiveQuery();
	}
	else if (test_parameter=='2'){
		grinc.addQuery("state", 7);
	}
	
	grinc.query();

	while (grinc.next()){

		v_table.addRow({"sys_id": grinc.getValue("sys_id"),
						"u_number": grinc.getValue("number"),
						"u_short_description": grinc.getValue("short_description"),
						"u_priority": grinc.getValue("priority")
		});
	}


  })(v_table, v_query);

 
This is how you'd pass the parameter then from a list view:

AlexKaras_0-1761041424282.png
This is how you'd pass the parameter from a reference field/variable:

AlexKaras_1-1761041697292.png


The same goes for related lists/relationship or fixed queries.

Always apply an "test_parameter=<VALUE>^ORtest_parameterISEMPTY" after you pass these "fake" parameters so that the actual query that is applied at any time is not affected.

 

Hi Alex, 
This approach unfortunately did not work for me for my usecase. I had to work with an elastic search endpoint and I had to define date sorting parameters.

I also leave my solution in this thread so that it may help others in the future.

However, what worked for me is that I have created the fields on the table 

I also use this parameter as an example:

var test_parameter = v_query.getParameter("test_parameter");



Then I construct the query normally with this field as "test_parameter=<VALUE>".

However, at the end when I define my row object for the 

v_table.addRow() method I make sure that I actually pass the value within the test_value parameter so that the query never runs on error.

The advantage of this approach is that it consistently works with gliderecord queries as well.