Variable substitution in Rest Endpoint through script include & get variable value from client scrip
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 05:22 AM
Hi All,
I need to put a variable value in Rest Endpoint: https:lookup/${address_id}
If I hard code this address in script I'm getting 200 response, but if I add it dynamically through not getting any response/error but I could able to log the variable value correctly in System Logs.
var r3 = new sn_ws.RESTMessageV2('smaty_test', 'Int complete address'); //Rest MSG & Method
r3.setStringParameterNoEscape('address_id', add3); //add3 - 'PD4DPC8DPgNHT09HTExGS00DOjE4'
Please suugest if anything to be added additionaly/ make change in above code
Thanks,
Padma
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:09 PM
Could you please share your client script code in order to debug further?
----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.
Mark this as Helpful / Accept the Solution if this helps.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 11:23 PM
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return; }
var int_street_1 = g_form.getValue('international_street');
var country_1 = g_form.getValue('country');
var id = g_form.getValue('int_shipping_address');
alert(id);
var slice = id.split(','); // Splitting the Shipping Address.
var n= slice.length; //length of returned slices.
var id_slice = slice[n-1];
var add_id =id_slice.toString();
var gb = new GlideAjax('TestSmarty');
gb.addParam('sysparm_name', 'getInternational3'); //Method
gb.addParam('sysparm_iddd', add_id);
gb.addParam('sysparm_street3', int_street_1);
gb.addParam('sysparm_country3', country_1);
gb.getXML(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('answer:' + answer);
var obj = JSON.parse(answer); // Parsing
alert('obj:' + obj);
}
Script INclude:
var TestSmarty = Class.create();
TestSmarty.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInternational3: function() {
var address_id = this.getParameter('sysparm_iddd');
var int_country3 = this.getParameter('sysparm_country3');
var country3 =int_country3.toString();
var address_id3 = address_id.toString();
gs.log('id3_test'+ address_id);
gs.log('country3_test'+int_country3);
try {
var r3 = new sn_ws.RESTMessageV2('smaty_test', 'Int complete address'); //Rest MSG & Method
r3.setStringParameterNoEscape('address_id', address_id.toString()); //add3 - 'PD4DPC8DPgNHT09HTExGS00DOjE4'
r3.setStringParameterNoEscape('country', country3 );
gs.log('country31_test' + country3); gs.log('ad id_test' + add3);
var response3 = r3.execute();
gs.log("This is topic token3_test" + response3);
var responseBody3 = response3.getBody();
gs.log('response:_test'+responseBody3);
var httpStatus3 = response3.getStatusCode();
gs.log('http_test'+ httpStatus3);
if(httpStatus3 == 200){
gs.log("smarty success3_test" + responseBody3);
}
//var parsed = JSON.parse(responseBody3);
//var token = responseBody.toString().split('credentials token="')[1].split('" estimated')[0];
} catch (ex) {
gs.log('inside catch');
var message3 = ex.getMessage();
gs.error(message3);
}
return responseBody3;
},
type: 'TestSmarty'
});
I am not getting the outbound log also