The CreatorCon Call for Content is officially open! Get started here.

If Statement inside of a Approval-User item in the Workflow

Peter Williams
Kilo Sage

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

 

PeterWilliams_0-1715259815869.png

 

 

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

 

4 REPLIES 4

dgarad
Giga Sage

Hi @Peter Williams 

 

answer = ifScript();







function ifScript() {

var dept= current.variables.department;

 if (dept== "abc") {
// your approavl logic

}

}
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

AshishKM
Kilo Patron
Kilo Patron

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

CezaryBasta
Tera Guru

Sounds like a nice use case for the DecisionTable API - have you considered that?

--
See more of my content here.

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Peter Williams 

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