Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Pass field values as parameters - POST

Not applicable

I am trying to do a POST from one ServiceNow instance to another using a   business rule.   However, the record inserts, but the field values aren't carrying over.

The fields I want to carry over when the record is inserted are u_password and u_asset.   What am I doing wrong here?

var request = new sn_ws.RESTMessageV2();

request.setEndpoint('https://myinstance.service-now.com/api/now/table/u_password_vault?sysparm_fields=');

request.setHttpMethod('POST');

//Eg. UserName="admin", Password="admin" for this code sample.

var user = '';

var password = '';

request.setBasicAuth(user,password);

request.setRequestHeader("Accept","application/json");

request.setRequestHeader('Content-Type','application/json');request.setRequestBody("{}");

var response = request.execute();

gs.log(response.getBody());

3 REPLIES 3

Mike Allen
Mega Sage

You have to set the parameters:


var request = new sn_ws.RESTMessageV2();


request.setEndpoint('https://myinstance.service-now.com/api/now/table/u_password_vault?sysparm_fields=');  


request.setHttpMethod('POST');


request.setStringParameterNoEscape('u_password', current.u_password);


request.setStringParameterNoEscape('u_asset', current.u_asset);



[...]


Not applicable

Thanks Mike.



Unfortunately this still didnt work.



Here is my full script:



var request = new sn_ws.RESTMessageV2();



request.setEndpoint('myinstance.service-now.com/api/now/tableu_password_vault?sysparm_fields=');


request.setHttpMethod('POST');





//Eg. UserName="admin", Password="admin" for this code sample.


var user = '';


var password = '';



request.setBasicAuth(user,password);


request.setRequestHeader("Accept","application/json");


request.setRequestHeader('Content-Type','application/json');


request.setStringParameterNoEscape('u_password', current.u_password);


request.setStringParameterNoEscape('u_asset', current.u_asset);



var response = request.execute();


gs.log(response.getBody());


Check out the example given here:



http://wiki.servicenow.com/index.php?title=Scripting_Outbound_REST#gsc.tab=0



also, here:



https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_RMV2-RESTMessageV2



How I have seen it set up in the past is that you set the outbound rest call in the module:



find_real_file.png


Set the parameters in that record.


find_real_file.png


find_real_file.png



and it will generate an example script for you:


find_real_file.png