Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.
No ratings
sai_sp
Saviynt Employee
Saviynt Employee

Use-Case:

 

Many applications like Service Now require JSON's to handle escape characters. If the escape characters are not handled properly, the SNOW ticket creation process can fail. This can be achieved by using the escapeJava method of the StringEscapeUtils() constructor. 

 

 

More Details:

 

1. public class StringEscapeUtils extends Object - Escapes and unescapes Strings for Java, Java Script, HTML, XML, and SQL.

2. escapeJava method details: 

  • public static String escapeJava(String str) - Escapes the characters in a String using Java String rules.
  • Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
  • So a tab becomes the characters '\\' and 't'.
  • The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

            Example:     

            input string: He didn't say, "Stop!"

            output string: He didn't say, \"Stop!\"

  • Parameters: str - String to escape values in, may be null
  • Returns: String with escaped values, null if null string input

 

 

JSON Syntax in Saviynt: 

 

{

    "call": [{

        "name": "call1",

        "connection": "userAuth",

        "url": "https://api.company.com/api/itsm/v1/request/create",

        "httpMethod": "POST",

        "httpParams": "{\"u_emplid\":\"${user.username}\", \"u_vendor_name\":\"Sayvint\", \"u_assignment_group\":\"MSP L2 Essbase\", \"u_short_descr\":\"Snow Access - ${user.username}\", \"u_description\":\"${org.apache.commons.lang.StringEscapeUtils.escapeJava(reqAttrs.customproperty10)}\", \"u_vendor_case_number\":\"7\", \"u_config_item\":\"Essbase\", \"u_priority\":\"3-Medium\", \"u_comments\":\"abcd\", \"u_work_notes\":\"Saviynt\"}",

        "httpHeaders": {

            "Authorization": "${access_token}"

        },

        "ticketidPath": "ticketNumber",

        "httpContentType": "application/json",

        "successResponses": {

            "statusCode": [

                200,

                201

            ]

        }

    }]

}

 

Further Reading: 

https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscape...

 
 
Version history
Last update:
‎09/06/2023 08:13 PM
Updated by:
Contributors