POST method in outbound REST message

Rj27
Mega Guru

Hi All,

Can we define HTTP query parameters of post method (defined in outbound REST message) using any script?

find_real_file.png

 

My doubt is- here in script I am setting the parameters but there is a possibility there might be no value passed for any one of them (suppose field 'memory').

In that case when no value is there for memory, entire field/key named 'memory' should not be there in the content Shared above. The case SHOULD NOT be like "memory":' '. Rather there should be no memory at all.

find_real_file.png

 

TIA,

-Ruchi

6 REPLIES 6

Harsh Vardhan
Giga Patron

you can pass it in your endpoint and then in your script pass it like below code. 

 

Example:

 

  http://abc/Test-abc/Test('${input}')

 

var rm= new sn_ws.RESTMessageV2('<Rest message name>', '<Rest message function name>');

rm.setStringParameter('input','check');

 

https://docs.servicenow.com/bundle/madrid-application-development/page/integrate/outbound-rest/conce...

Hi Harshvardhan,

Thanks for the response!

I would like to re-frame my question.

The example given above is already used in workflow .PFA the screenshot.

My doubt is- here in script I am setting the parameters but there is a possibility there might be no value passed for any one of them (suppose field 'memory').

In that case when no value is there for memory, entire field/key named 'memory' should not be there in the content Shared above. The case SHOULD NOT be like "memory":' '. Rather there should be no memory at all.

find_real_file.png

you can add this logic in your script it self to validate if the variables has some value or not and based on that you can pass it in setStringParameterNoEscape().

 

example:

 

var bl ;

var mem = current.variables.var_memory;

if(mem != '')

bl+= current.variables.var_memory;

 

var rm= new sn_ws.RESTMessageV2('<Rest message name>', '<Rest message function name>');

rm.setStringParameterNoEscape('memory',bl);

 

 

I have one question here, what will happen, if you send the blank value ? may i know your business need. 

 

 

Harsh Vardhan
Giga Patron

adding one thread here, which will give you one example.. give a try and let me know if you have any further question on it. 

 

https://community.servicenow.com/community?id=community_question&sys_id=7d15836ddbd8dbc01dcaf3231f96...