I want a script for workflow conditions.

Taaha M
Tera Contributor

I am looking for a script to meet mu condition.
My condition is to :

  1.  If Opened by is the same as the Manager then it should trigger task. If
  2.  If Manager is inactive --- then it should trigger other task.
1 REPLY 1

Dnyaneshwaree
Mega Sage

Hello @Taaha M ,

 

Please refer below code for a example and update it as per your req:

(function checkConditions(current) {
    var openedBy = current.opened_by;
    var manager = openedBy.manager;

    if (!manager) {
        // No manager assigned, return false
        return false;
    }

    // Check if 'Opened by' is the same as 'Manager'
    if (openedBy == manager) {
        // Trigger the first task
        workflow.scratchpad.triggerTask = 'task1';
        return true;
    }

    // Check if the manager is inactive
    var grManager = new GlideRecord('sys_user');
    if (grManager.get(manager) && grManager.active == false) {
        // Trigger the second task
        workflow.scratchpad.triggerTask = 'task2';
        return true;
    }

    return false;
})(current);

 

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru