Servicenow Integration -502 Responses from EventOps FOR Json payload

VR17
Tera Contributor

Hi Team,

 

Any Suggestion appreciated 🙂

I am working on an Integration from ServiceNow to a third party application. Integration is working fine successfully payload is received by thirdparty .

 

However when there is any special character in Short desc -"test:  xxxxx\xx\xxx ". It is throwing error 502 IN response 

 

I have configured the payload in Business Rule itself. Tried current.short_description.toString() didn't worked. 

 

request.setRequestBody("{ \"_time\" : \"" + gdt.getNumericValue() + "\",\"number\" : \"" + current.number + "\" , \"dv_assignment_group\" : \"" + current.assignment_group.getDisplayValue() + "\" , \"dv_state\" : \"" + current.state.getDisplayValue() + "\", \"short_description\" : \"" + current.short_description + "\", \"dv_cmdb_ci\" : \"" + current.cmdb_ci.getDisplayValue() + "\",  \"sys_created_on\" : \"" + current.sys_created_on + "\",\"origin\" : \"xyz\" ,\"dv_priority\" : \"" + current.priority.getDisplayValue()  + "\" ,\"owner_name \" : \"" + current.caller_id.getDisplayValue() + "\", \"dv_service_offering\" : \"" + current.category.getDisplayValue() + "\" , \"dv_business_service\" : \"" + current.business_service.getDisplayValue() + "\",\"service_type\" : \"Incident\" ,\"sys_created_by\" : \"" + current.sys_created_by + "\", \"sys_updated_on\" : \"" + current.sys_updated_on + "\"}");

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Rahul Talreja
Mega Sage
Mega Sage

Hi @VR17 ,
Dealing with special character might create a problem.
Try using encoding the special character before adding it to JSON.
You can take help from URL Encoding Reference — ServiceNow Elite.
ServiceNow JavaScript escape characters - Support and Troubleshooting
Solved: How do I escape these characters in the Script Inc... - ServiceNow Community

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

View solution in original post

2 REPLIES 2

Rahul Talreja
Mega Sage
Mega Sage

Hi @VR17 ,
Dealing with special character might create a problem.
Try using encoding the special character before adding it to JSON.
You can take help from URL Encoding Reference — ServiceNow Elite.
ServiceNow JavaScript escape characters - Support and Troubleshooting
Solved: How do I escape these characters in the Script Inc... - ServiceNow Community

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

VR17
Tera Contributor

I have used  this solution

 

var sd=current.short_description.replace(/[^A-Z0-9]/ig, "_");