How to replace special character (/) with a space in Business rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 11:48 PM
Hi All,
Having some issue with getting an error message on a REST web service.
Over the BR, I have kept as below to replace special characters in short description.
r.setStringParameterNoEscape('short_description', current.short_description.replace(/[\\"_'ø:*]/g, " "));
It is working for all the special characters except '/'. Please guide me what changes to be made to achieve this.
Example:
Hi,
2/03/31 23.51 APISM610 CPU1 3 WPIS6157 0032
22/03/31 23.51 APISM610 CPU1 15 WPIS6162 0047
In the request body, I am seeing as below :
"short_description":"Hi,\n\n2/03/31 23.51 APISM610 CPU1 3 WPIS6157 0032\n22/03/31 23.51 APISM610 CPU1 15 WPIS6162 0047"
and in response body, receiving this:
[ERROR CODE: 400 ] Method failed: (/dev_servicenow_incident_tkts/_doc/INC0149665) with code: 400
Please guide me how to resolve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 12:40 AM
Hello Priyanka,
The regex to find the forward slash is to add - "\/" this to your existing pattern,
So it would look something like /\/[\\"_'ø:*]/g
The forward slash that you are replacing is a date one, so I suggest you try replacing that with a hyphen to make it readable. Try to do this in a variable in the line above and then add it to setStringParameter Line.
Also if you are sending a JSON request, I do not see any error in the short description that you have pasted. Try to see if there is some issue with the other variables added or the overall JSON formatting.
Hope this helps.
Regards,
Joshton Fernandes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 01:10 AM
Hi Joshton,
Thanks for the reply.
,Would the issue because of \n\n if there is a text in the second line.
Hi,
2/03/31 23.51 APISM610 CPU1 3 WPIS6157 0032
22/03/31 23.51 APISM610 CPU1 15 WPIS6162 0047
How can this be replaced?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 04:33 AM
No, that looks correct, having \n in a JSON body is normal.
Can you paste your generated request body here ? the complete JSON, if its not data sensitive.
OR
what you can do is use Online JSON formatters to see if your request body has any issue.
there might be an extra quote " or a comma , which is making your request invalid to process on other end.
If the JSON Request body looks good, then you can try to debug if the content in your outbound message has any typo issue in key pair variable substitutions, or see if your script Include or BR has added any extra values which are not expected in the request body.
Regards,
Joshton
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2022 02:43 AM
Hi Joshton,
As part of testing purpose I am placing the request body here.
For description: hi*_?1/12//3,45.567
2/03/31 23.51 APISM610 CPU1 3 WPIS6157 0032
I am having a script to replace special characters as below,
r.setStringParameterNoEscape('description', current.short_description.replace(/[\\"_'ø:*]/g, " "));
I have tested randomly and till this (hi*_?1/12//3,45.567) in my description I am receving response status as 200
But when I add the second line(2/03/31 23.51 APISM610 CPU1 3 WPIS6157 0032) for testing purpose, I am receving as 400.
Unable to understand the issue here. Could you please help in resolving this. What I am missing here