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

ServiceNow CreatAccount Json Formay

Darhanba
New Contributor III
New Contributor III

Hi All,

I have requirement to extract a part of the user attribute value and use it to create an account in serviceNow and I'm using below Json,

\"u_extension\":\"${if(user.phonenumber!=null && user.phonenumber.len()>10){SUBSTRING(user.phonenumber, CHARINDEX('=', user.phonenumber)+ 1, user.phonenumber.len())}else{''}\"

 

\"phone\":\"${if(user.phonenumber!=null && user.phonenumber.len()>10){'SUBSTRING(user.phonenumber,0,CHARINDEX(';',user.phonenumber,0))}else{user.phonenumber}}\"

 

Actual user attribute is phonenumber 5432167890;ext=11111 , we want to extract extension which is 11111 and phone number 5432167890. Can someone please provide me some suggestions in formatting the JSON.

 

Thanks,
Darshan

7 REPLIES 7

adriencosson
Valued Contributor
Valued Contributor

Hi @Darhanba ,

You can try the following : 

  • For extracting the left part of the phone number :

 

user.phonenumber.substring(0,user.phonenumber.indexOf(';'))

 

Input : 5432167890;ext=11111 Output : 5432167890

  • For extracting the extension number :

 

user.phonenumber.substring(user.phonenumber.indexOf('=')+1)

 

Input : 5432167890;ext=11111 Output : 11111 

Regards,
Adrien COSSON

Falcon
Saviynt Employee
Saviynt Employee

Disclaimer - This is an AI generated response and the feedback on this thread will be used to fine tune. Please check important information, the AI may generate wrong response.

To address your requirements for extracting the extension and phone number from the phonenumber attribute and correctly format your JSON for creating an account in ServiceNow, you'll need to adjust the expressions within your JSON attributes to ensure they're correctly parsing and extracting the parts of the phone number as intended.

Here's a corrected and comprehensive JSON example that encapsulates both the extraction logic and error handling aspects, ensuring smooth operation within the Saviynt environment:

 

{
  "attributes": {
    "u_extension": "${user.phonenumber!=null && user.phonenumber.contains(';ext=') ? user.phonenumber.substring(user.phonenumber.indexOf('=') + 1) : ''}",
    "phone": "${user.phonenumber!=null && user.phonenumber.contains(';') ? user.phonenumber.substring(0, user.phonenumber.indexOf(';')) : user.phonenumber}"
  },
  "errorHandling": {
    "expiryError": ["Token expired", "Invalid Token"],
    "authError": ["Invalid Credentials", "Unauthorized"],
    "retryFailureStatusCode": [401, 403, 500],
    "timeOutError": ["Time out", "Server not responding"],
    "errorPath": "error.message",
    "maxRefreshTryCount": 3
  }
}

 

Explanation:

  • u_extension: This attribute is crafted to check if the phonenumber is not null and contains the extension identifier ';ext='. If the conditions are met, it extracts the extension number (e.g., 11111 from 5432167890;ext=11111). Otherwise, it assigns an empty string.
  • phone: Similarly, this checks if phonenumber is not null and contains a semicolon. If so, it extracts the substring before the semicolon (the phone number part) else it uses the phonenumber as is.
  • Error Handling: This section is crucial for robust integration. It defines behavior for various error scenarios like token expiry or invalid credentials, specifying which error messages should trigger a token refresh (expiryError), authentication retry (authError), and so on. The retryFailureStatusCode includes HTTP status codes that should trigger a retry. timeOutError captures errors related to timeouts, and errorPath specifies the JSON path to the error message in API responses. maxRefreshTryCount limits the number of retries for refreshing tokens or retrying after failures.

This JSON ensures that your integration can gracefully handle errors and retry as necessary, in addition to correctly parsing and extracting phone number and extension attributes for use in ServiceNow account creation.

rushikeshvartak
All-Star
All-Star

{
"u_extension": "${user.phonenumber != null && user.phonenumber.length > 10 ? user.phonenumber.substring(user.phonenumber.indexOf('=') + 1) : ''}",
"phone": "${user.phonenumber != null && user.phonenumber.length > 10 ? user.phonenumber.substring(0, user.phonenumber.indexOf(';')) : user.phonenumber}"
}


Regards,
Rushikesh Vartak
If you find this response useful, kindly consider selecting 'Accept As Solution' and clicking on the 'Kudos' button.

Hi @rushikeshvartak 

Thank you for the suggestion, I tried below JSON and the task failed.

\"u_extension\":\"${user.phonenumber != null && user.phonenumber.length > 10 ? user.phonenumber.substring(user.phonenumber.indexOf('=') + 1) : ''}\",\"phone\":\"${user.phonenumber != null && user.phonenumber.length > 10 ? user.phonenumber.substring(0, user.phonenumber.indexOf(';')) : user.phonenumber}\"

 

But when I use contains instead of length in the comparison the task gets completed and attributes gets calculated as expected. Am I missing something in the length compare?

\"u_extension\":\"${user.phonenumber!=null && user.phonenumber.contains(';ext=') ? user.phonenumber.substring(user.phonenumber.indexOf('=') + 1) : ''}\",\"phone\":\"${user.phonenumber!=null && user.phonenumber.contains(';') ? user.phonenumber.substring(0, user.phonenumber.indexOf(';')) : user.phonenumber}\"

 

Thanks,
Darshan

Does u_extension works ?


Regards,
Rushikesh Vartak
If you find this response useful, kindly consider selecting 'Accept As Solution' and clicking on the 'Kudos' button.

Yes it worked.

Darhanba_0-1712317945187.png

 

Please click the 'Accept As Solution' button on the reply (or replies) that best answered your original question.


Regards,
Rushikesh Vartak
If you find this response useful, kindly consider selecting 'Accept As Solution' and clicking on the 'Kudos' button.