How to Pass Parameters to the rest service that is called by a sn_ws.RESTMessageV2

pneuvil1
Mega Guru

How do I configure a parameter to be passed to the subject of a RESTMessageV2 call and how to I get that parameter once in that rest service

 

Attempted the following calling code:

extendedLogs = 'getExtendedLogs';

 

                var restmsg = new sn_ws.RESTMessageV2(Rest Message Name, Method Name);
                restmsg.setEccParameter('skip_sensor', true);
                restmsg.setHttpMethod('POST');
                restmsg.setRequestHeader('Content-Type', 'application/json');
                restmsg.setRequestHeader('Accept', 'application/json');
                restmsg.setQueryParameter ('extendedLogs', extendedLogs);
                restmsg.setStringParameter("extendedLogs", extendedLogs);
                restmsg.setRequestBody(extendedLogs);
                var results = restmsg.execute();
 
Then in the Scripted Rest Service to receive the call, the following was attempted:
function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response)
 
            extendedLogs = request.queryParameter('extendedLogs');
            gs.log('---queryParameter ' + extendedLogs, 'layout');

            extendedLogs = request.getQueryParameter('extendedLogs');
            gs.log('===getQueryParameter ' + extendedLogs, 'layout');

            extendedLogs = request.getStringParameter("extendedLogs");
            gs.log('+++getstringparameter ' + extendedLogs, 'layout');
 
all come up undefined. This is code suggested by google searches and the docs.
 
a variable substitution named extendLogs is defined with no excaping for the rest method.
 
 
Also tried this to see if I could squeeze out the value passed in to the request
 
                gs.log('request=' + request, 'layout');
                gs.log('request.body=' + request.body, 'layout');
                for (var x in request.body)
                    gs.log('request.body[' + x + '] = ' + request.body[x], 'layout');

                gs.log('request.body.data=' + request.body.data, 'layout');
                for (x in request.body.data)
                    gs.log('request.body.data[' + x + '] = ' + request.body.data[x], 'layout');
                gs.log('request.body.data.extendedLogs=' + request.body.data.extendedLogs, 'layout');
 
all come up empty.
1 REPLY 1

Tanushree Maiti
Tera Patron

Hi @pneuvil1 

 

Did you test the different parameters (in this case, extendLogs) methods individually or all at once?

If they were tested together, the variable value may have been overwritten. Please test each method separately, one at a time.

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti