and more in a single search tool across platforms. Read the announcement here. |
10/14/2022 06:54 AM
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?
Solved! Go to Solution.
10/14/2022 07:34 AM
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) '}}"
]
}
10/17/2022 08:28 AM
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
10/17/2022 08:29 AM - edited 10/17/2022 08:30 AM
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) '}}"
]
}
10/17/2022 08:40 AM
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
10/17/2022 08:43 AM
{
"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) '}}"
]
}