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

Syntax for writing java or javascript code inside JSON of REST calls

sampath18
Regular Contributor II
Regular Contributor II

Hi Team,

Is there any syntax documented for writing any custom javascript or java code inside REST calls?

There are requirement where we need to call some java methods. so can anyone suggest what syntax need to be followed in below sample jsons.

In short, having syntax challenges when writing some custom code when used if else condition in rest calls for account operations.

{
"call": [
{
"name": "call1",
"connection": "userAuth",
"url": "https://********/api/now/import/u_import_set_saviynt_integration",
"httpMethod": "POST",
"httpParams": "${if((user?.customer?.id==5) && (task?.tasktype==3 || task?.tasktype==6)){return '{\"u_user\":\"'+user?.username+'\",\"u_short_description\":\"text\" ,\"u_description\":\"some text and variables\",\"u_correlation_id\":\"'+task?.id+'\",\"u_correlation_display\":\"IGA\",\"u_category\": \"User onboarding\", \"u_due_date\":\"'+new java.text.SimpleDateFormat('yyyy-MM-dd HH:mm:ss').format(user?.startdate)+'\"}';} else{ return '{\"u_user\":\"'+user?.username+'\",\"u_short_description\":\"text\" ,\"u_description\":\"Some text and variables\",\"u_correlation_id\":\"'+task?.id+'\",\"u_correlation_display\":\"IGA\",\"u_category\": \"User offboarding\", \"u_due_date\":\"'+new java.text.SimpleDateFormat('yyyy-MM-dd HH:mm:ss').format(Calendar.getInstance().getTime())+'\"}';}}",
"httpHeaders": {
"Authorization": "${access_token}"
},
"httpContentType": "application/json",
"ticketidPath": "result.display_value",
"unsuccessResponses": {
"message": ""
}
}
]
}

7 REPLIES 7

rushikeshvartak
All-Star
All-Star

New keyword is not supported use calender object

https://forums.saviynt.com/t5/community-knowledge-base/new-date-function-not-working-in-json/ta-p/20...


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

sampath18
Regular Contributor II
Regular Contributor II

Hi @rushikeshvartak  Thanks for the response. above dates function is working fine for us currently. but the question is about when wanted to write small code and assign that to variable and use it in the json body. do you have any syntax for that. one line code and direct methods we are able to make use. however, we there situation to manipulate input data using code then we are unable to do. so looking for some assistance here.

Thanks

Sampath

 

It will be javascript hence if you tell us logic i can help with it


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

sampath18
Regular Contributor II
Regular Contributor II

okay, let say i wanted to substring based on indexes . Some data transformation can not be achieved in single method. so in such cases we may need to write few lines of code. How i can include those coding lines in between the json.

Sample

"EMPLOYEEID": "#CONST#${return org.apache.commons.lang.StringUtils.leftPad(response.userId.substring(2), 6, '0')}~#~char",


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

sampath18
Regular Contributor II
Regular Contributor II

Thanks again. But that is not something i am looking for. 

lets say we are creating servicenow ticket or creating Azure AD account. we have if-else logic written to handle the different usecases. In such cases can you tell me how code can be included to transform data and make api call.

\"u_description\":\"some text and variables\",

In above, variables should have been assigned from custom code after data transformation as per the business need.

You can use jar do manipulation and call from  connector

${com.saviynt.ecm.identitywarehouse.domain.Account_entitlements1.findAllByAccountkey(account).collect{it.entitlement_valuekey}}


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