and more in a single search tool across platforms. Read the announcement here. |
04/04/2024 05:29 AM
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
Solved! Go to Solution.
04/04/2024 08:13 AM - edited 04/04/2024 08:13 AM
Hi @Darhanba ,
You can try the following :
user.phonenumber.substring(0,user.phonenumber.indexOf(';'))
Input : 5432167890;ext=11111 Output : 5432167890
user.phonenumber.substring(user.phonenumber.indexOf('=')+1)
Input : 5432167890;ext=11111 Output : 11111
04/04/2024 11:00 AM
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
}
}
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.
04/04/2024 11:03 AM
{
"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}"
}
04/04/2024 12:11 PM
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
04/04/2024 09:27 PM
Does u_extension works ?
04/05/2024 04:52 AM
Yes it worked.
04/05/2024 04:57 AM
Please click the 'Accept As Solution' button on the reply (or replies) that best answered your original question.