Create JSON object post method in a business rules

Fabrizio Joaqui
Mega Guru

I have to build a JSON object in this script and send in rest message:

find_real_file.png

with this data:

find_real_file.png

how can i do?

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hello @Fabrizio Joaquin 

It will be like -

{
"first_name":"${first_name}",
"last_name":"${last_name}",
"active":"${active}"
}

Where $ variable name is the field name we have set in business rule.

Also please check below video. It will clear you all queries.

ServiceNow Rest Integration

 

Kindly let me know if you have any doubts

 

Thanks
Akshay Kangankar

View solution in original post

5 REPLIES 5

suvro
Mega Sage
Mega Sage

You can create an array

var reqArr = [

{"field": "firstName",

"field_description": "First Name",

"type_format": "STRING",

so on},

{"field": "lastName",

"field_description": "Last Name",

"type_format": "STRING",

so on},

];

 

Community Alums
Not applicable

Hello,

If you just want to send values from ServiceNow table and If you have created rest message with HTTP header , content-type is "application/json" then you can simply use below code. 

In other cases use @suvro code.

(function executeRule(current, previous /*null when async*/) {
try { 
 var r = new sn_ws.RESTMessageV2('REST Message', 'post');
 r.setStringParameterNoEscape(first_name', current.u_name); 
 r.setStringParameterNoEscape('last_name', current.u_cogname); 
 r.setStringParameterNoEscape('active', current.active); // so on you can add values and send them

 var response = r.execute();

 var responseBody = response.getBody();
		
 var httpStatus = response.getStatusCode();
}
catch(ex) {
 var message = ex.message;
}
})(current, previous);

 

Reference - Servicenow Integration

 

Thanks
Akshay Kangankar

thank you, and now how can i put it in my rest message content? 

find_real_file.png

 

Community Alums
Not applicable

Hello @Fabrizio Joaquin 

It will be like -

{
"first_name":"${first_name}",
"last_name":"${last_name}",
"active":"${active}"
}

Where $ variable name is the field name we have set in business rule.

Also please check below video. It will clear you all queries.

ServiceNow Rest Integration

 

Kindly let me know if you have any doubts

 

Thanks
Akshay Kangankar