Set Query parameter Integration

Shantanu K
Tera Contributor

Hello Experts,

 

I have created a scheduled job to trigger an integration. Where I am storing auc numbers in an array for all the request. I need to pass this AUC number in query parameter. What is the syntax for this?

 

Piece of code from Scheduled job:

var auc = [];
var pn = [];
//gs.info('test by shantanu 1.1');
var grAuc = new GlideRecord("capp_capital_project");
grAuc.addEncodedQuery('phase=execution^number=CAP0001188');
grAuc.query();
//gs.info("Test by shantanu1" + grAuc.getRowCount());
while (grAuc.next()) {
// gs.info("shantanu1 " + grAuc.u_auc.u_number);
pn.push(grAuc.number);
auc.push(grAuc.u_auc.u_number);

}

 

 

 

JSON content for query:

{
"ReParams": {
"Asset_Number": $[] // what goes inside if I want to pass an AUC Number from an array?
}
}

 

Thanks,

Shantanu

1 ACCEPTED SOLUTION

@Shantanu K 

Then in the Rest message content use the following content.

{
	"ReParams": {
		"Asset_Number": ${auc_num}
	}
}

 

Then save the form and click Auto generate variables related link so that it will generate a variable as shown below.

 

AnveshKumarM_0-1701266109200.png

 

Then in your scheduled job you can use the following sample script.

 

//Iterate through AUC array for each request
for(key in auc){
	try { 
		var r = new sn_ws.RESTMessageV2('YOUR REST Message Name', 'REST Message Method Name');
		//Set the auc_number in the content using the below line
		r.setStringParameterNoEscape('auc_num', auc[key]);
		var response = r.execute();
		var responseBody = response.getBody();
		var httpStatus = response.getStatusCode();
	} catch(ex) {
		var message = ex.message;
	}
}
	

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

View solution in original post

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @Shantanu K 

Are you trying to pass all the numbers in single request or only one for each request.

 

And are you using any Outbound REST Message for this integration?

Thanks,
Anvesh

Hi @AnveshKumar M ,

 

I am trying to send only 1 number at a time.

Yes I am using Outbound REST Message for this integration.

ShantanuK_0-1701265365409.png

 

Thanks,

Shantanu

 

@Shantanu K 

Then in the Rest message content use the following content.

{
	"ReParams": {
		"Asset_Number": ${auc_num}
	}
}

 

Then save the form and click Auto generate variables related link so that it will generate a variable as shown below.

 

AnveshKumarM_0-1701266109200.png

 

Then in your scheduled job you can use the following sample script.

 

//Iterate through AUC array for each request
for(key in auc){
	try { 
		var r = new sn_ws.RESTMessageV2('YOUR REST Message Name', 'REST Message Method Name');
		//Set the auc_number in the content using the below line
		r.setStringParameterNoEscape('auc_num', auc[key]);
		var response = r.execute();
		var responseBody = response.getBody();
		var httpStatus = response.getStatusCode();
	} catch(ex) {
		var message = ex.message;
	}
}
	

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh