Issue with special characters in Outbound Rest Message

Rob Bushrod
Tera Guru

Hi,

Having some issues with getting an error message on a REST Web Service with unterminated strings. I believe most of the time it is down to the '&' symbol being in the description field. 

I found the following community post; https://community.servicenow.com/community?id=community_question&sys_id=478ecb21dbdcdbc01dcaf3231f96... and have used the correct answer but I am still getting the error;

find_real_file.png

I really need to try and resolve this issue as it is causing incidents not to be raised in the customers system.

Thanks,

Rob

4 REPLIES 4

Rob Bushrod
Tera Guru

The above was with the following code:

message.setStringParameter('Description', jsonEncode(current.description + ''));

I have also tried with:

message.setStringParameterNoEscape('Description', jsonEncode(current.description + ''));

and got the following result;

find_real_file.png

It does not seem to replace the '&' or encode it at all.

 

Jorn van Beek
Tera Guru

first I asume you tested the same message without the "&". I have seen often people thinking that is it while the error was somewhere else.

besides this, how critical is it to have the "&" or other special chars in the string? Can you for example just replace it with a space?

Something like current.description.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,' ');

I think this is an issue on the api endpoint. The "&" char does not have to be escaped in JSON format.

Yes I tested with the word 'and' and did not get the error at all with all other parts of the incident the same.

It is not necessarily our Service Desk that are logging the tickets it could be that it comes from an email and somebody has put that symbol in so it is imperative that we find a way around it so that the customers system is updated correctly.

I have found that replacing with '%26amp' might work although not fully tested as yet, it is not giving the error when replacing '&'.

Thanks,

Rob

Hi Robert,

setStringParameterNoEscape() this should help you get around this;

can you update code as below; no need to encode the description

message.setStringParameterNoEscape('Description', current.description);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader