servicenow integration

RekhaK
Tera Contributor

we are setting up the final description which is a combination of multiple things ok
so this we are setting up in the description of the JSON body that we are sending for creating demand via post call

now the issue is json will only take the valid character so if user put some line break or any addition invalid character .it will threw an error .so if i will use regex so i cant use that because in the post call directly i can write code while setting up the JSON body and if there is a way to write also so how many character i have to remove .that is also a big issue
tell me how to do that

5 REPLIES 5

VishalC3
Kilo Guru

HI @RekhaK 

 

You can try encoding the data and then decode at receiving end. You can use below out of box methods.

 

Scope                      Encode Method                                                Decode Method

Global ScopeGlideStringUtil.base64Encode(string)GlideStringUtil.base64Decode(encodedString)
Scoped Appsgs.base64Encode(string)gs.base64Decode(encodedString)

 

Thanks,

Vishal

Tanushree Maiti
Tera Sage

Hi @RekhaK 

 

Before sending the description using JSon validator , you can validate whether its having any invalid char

OR

You can try with this:

r.setStringParameterNoEscape('desc', jsonEncode(current.description + ''));

Ref: https://www.servicenow.com/community/developer-forum/rest-script-help-the-payload-is-not-valid-json/...

 

OR

Try the code as mentioned in 

https://www.servicenow.com/community/developer-forum/line-breaks-in-json-response/m-p/2017202#M67412...

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

I have tried above solution, but no luck 

Ankur Bawiskar
Tera Patron

@RekhaK 

so what manipulation you did before sending and which is not working?

share here

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