If Statement inside of a Approval-User item in the Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:04 AM
Good Morning Everyone,
i am looking for a way to script in an if statement inside of an Approval-User item inside of a Workflow.
Basically, i have an Request with a variable inside called Department, this variable will have the users department information in it.
the condition is:
if(department Contains 'IT'){
approval user = 'sys_id' of the approving user
Else if( department contains 'Litigation') {
approval user = 'sys_id' of the approving user in Litigation
so on and so forth
i can do it with tons of If Statement items but i feel this can be scripted inside of the Approval-User item in the Workflow
Would i need to do an addQuery onto the request for it to look for the department.
and how can i do it please
thank you kindly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:21 AM
answer = ifScript();
function ifScript() {
var dept= current.variables.department;
if (dept== "abc") {
// your approavl logic
}
}
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:41 AM - edited 05-09-2024 06:42 AM
Hi @Peter Williams ,
On catalog form this departmnet field must be reference to Department table [ cmn_department ] or It's select box values. If it's reference then current.variables.<departmentFieldName> will return the sys_id of department record.
answer = [];
var department = current.variables.department; // update the corrent variable name
if (department == "sys_id of IT department") {
answer.push('sys_id of approver user');
} else if (department == "sys_id of Litigation department") {
answer.push('sys_id of approver user');
}
Note: if department field is not a reference and its local variable ( using select box ) then you can match the value as department name.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:45 AM
Sounds like a nice use case for the DecisionTable API - have you considered that?
See more of my content here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 07:02 AM
In IF condition you need to "==" instead of contains and you can check the script below:
answer = [];
var costcenter = current.variables.cost_center.getDisplayValue(); // Change the variable to your variable
if (costcenter == "Human Resources") {
answer.push('62826bf03710200044e0bfc8bcbe5df1'); //change the id's
} else if (costcenter == "Engineering") {
answer.push('a8f98bb0eb32010045e1a5115206fe3a');
}
Thanks and Regards
Sai Venkatesh