http query parameters dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 04:50 AM
hii
i need to do variable substitution my http query parameter name is enclave_name and my variable name is enclave_name..if i give any value in script restMessage.setStringParameterNoEscape('enclave_name', 'tes123');mannually its working fine iam getting response.. but i need to do dynamically when ever i select enclave names in enclave_name variable on catalog item i need to populate response in u_comment varible i tried in different ways but its not working sharing script and screen shots kindly help on this
client script ;;;
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetEnclaveData');
ga.addParam('sysparm_name', 'getData');
ga.addParam('sysparm_enclave',g_form.getValue('enclave_name'));
ga.getXMLAnswer(getResponse);
// Get the value of the 'response' variable
function getResponse(answer) {
g_form.setValue('u_comment',answer);
}
}
script include;;;
var GetEnclaveData = Class.create();
GetEnclaveData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getData:function(){
//gs.log('indise SI','sh1');
var queryParam = this.getParameter('sysparm_enclave');
gs.log("check query param 231"+enclaveValue);
var restMessage = new sn_ws.RESTMessageV2('network access', 'GET Enclave Data By Enclave Name');
restMessage.setStringParameterNoEscape('enclave_name','tes123');its working fine static
restMessage.setStringParameterNoEscape('enclave_name', queryParam);its not working dynamic..i have taken enclave_name values in queryParam..in log iam getting the value which i selected on the catalog item
restMessage.setHttpMethod('GET');
var response = restMessage.execute();
gs.log("check enclave response code"+response.getStatusCode(),'sh1');
var responseBody = response.getBody();
gs.log("check enclave response 1"+responseBody,'sh1');
var httpStatus = response.getStatusCode();
gs.log("check enclave response http"+responseBody,'sh1');
if (httpStatus == 200) {
// Store the response body in a variable
gs.setVariable('response', responseBody);
//return JSON.stringify(responseBody);
return (responseBody);
// gs.log("check enclave response"+responseBody);
}
},
type: 'GetEnclaveData'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 06:12 AM
You screenshots are too small to see. I see you have variable substitution configured but I can't see what is actually the name of the query variable and the substitute.
You should have an query parameter with name 'enclave_name' and value '${enclave_name}', and a related variable substitute named 'enclave_name' as well.
Then make sure you comment out your static test 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 09:10 PM - edited 01-23-2023 09:16 PM
sorry i didn't check screen shots properly my query parameter name is enclave_name...if i send any static value in the value filed iam getting response but i have variable on catalog item enclave_name in that variable i have some names list i need place that variable in value so that when ever user selects any value in that variable i need to the response can you please check this
Then make sure you comment out your static test ... iam not getting this point
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 03:09 AM
I see. It actually looks good and I see no reason why it wouldn't work as expected... Do you know what is actually sent? Try creating an interceptor endpoint (e.g. by using beeceptor) so you can verify what are you actually sending out of ServiceNow.