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

GrantAccessJSON Database Insert Logic Not Triggering

mtorres
New Contributor II
New Contributor II

I am currently utilizing the following logic to trigger one of two database inserts depending on which entitlement is assigned to the user:

{
"Role": [

"${if(task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Admin User'){'GRANT '+task.entitlement_valueKey.entitlement_value+' TO '+accountName+' '} INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = '${task.accountName}'),8) else if (task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Standard User') {'GRANT '+task.entitlement_valueKey.entitlement_value+' TO '+accountName+''} INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = '${task.accountName}'),9) else {'REVOKE '+task.entitlement_valueKey.entitlement_value+' TO '+accountName+''}}"
]
}

The entitlements are assigned correctly but the inserts are not occurring.  I do not see any errors in the logs.  

Is there anything incorrect with my json sysntax?

5 REPLIES 5

rushikeshvartak
All-Star
All-Star

if you are trying to 2 operations then separate with comma. It seems you just need insert query

{
"Role":[
"${if(task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Admin User'){' INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = '+accountName+'),8) '}else if (task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Standard User') {'INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = ''+accountName+'),9) '}}"
]
}


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

Thank you Rushikesh.

I attempted to use your syntax posted above but I'm failing syntax checks around the else if statement:

{
"Role":[
"${if(task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Admin User'){' INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = '+accountName+'),8) '}else if (task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Standard User') {'INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = ''+accountName+'),9) '}}"
]
}

It seems like its expecting an extra ')' but despite what I try to add, it continues to fail.  Hoping to get another set of eyes on this to see what I'm missing

Below should work

{
"Role":[
"${if(task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Admin User')){' INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = '+accountName+'),8) '}else if (task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Standard User')) {'INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = ''+accountName+'),9) '}}"
]
}


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

Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: SimpleTemplateScript3915.groovy: 1: expecting ')', found 'else' @ line 1, column 259. e = '+accountName+'),8) '}else if (t ^ 1 error

Adding ), results in the following error:

Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: SimpleTemplateScript3916.groovy: 1: unexpected token: , @ line 1, column 260. = '+accountName+'),8) '}),else if ( ^ 1 error

{
"Role":[
"${if(task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Admin User')){' INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = '+accountName+'),8) '}else if (task.entitlement_valueKey.entitlement_value.equalsIgnoreCase('Standard User')) {'INSERT INTO testdatabase1(UserID,RoleID) VALUES ((Select ID FROM testdatabase2 WHERE Username = ''+accountName+'),9) '}}"
]
}


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