Assignment group flow designer script.

dhineshkumar
Tera Guru

Hi Community.

I have sys_user table in that table i have BU code (reference variable). The BU code variable and sys_user_group reference variable added in the sys_group_covers_location table, based on the who submits the request user of the BU code I want trigger the assignment group respective "sys_group_covers_location" group on my sc_task. write a flow designer script,

Thanks in advance.

9 REPLIES 9

Abhay Kumar1
Giga Sage

@dhineshkumar please try below flow action code if works for you so here basically you will get BU code of requester,look up in group location table and assign group to task if I understood correctly:

(function execute(inputs, outputs) {

    // Get the requester (user who submitted the request)

    var requester = new GlideRecord('sys_user');

    requester.get(inputs.requesterSysId); // 'inputs.requesterSysId' is the requester’s sys_id

 

    // Retrieve the BU code of the requester

    var buCode = requester.getValue('bu_code'); // Adjust 'bu_code' to the correct field name in sys_user if different

 

    // Find the matching group in sys_group_covers_location based on BU code

    var groupCover = new GlideRecord('sys_group_covers_location');

    groupCover.addQuery('bu_code', buCode); // Adjust 'bu_code' to the correct field name in sys_group_covers_location if different

    groupCover.query();

 

    if (groupCover.next()) {

        // Retrieve the sys_user_group reference for assignment

        var groupId = groupCover.getValue('sys_user_group');

 

        // Update the sc_task assignment group

        var task = new GlideRecord('sc_task');

        task.get(inputs.scTaskSysId); // 'inputs.scTaskSysId' is the sc_task’s sys_id

        task.assignment_group = groupId;

        task.update();

 

        // Optionally return the assignment group name in outputs

        outputs.assignmentGroupName = task.assignment_group.getDisplayValue();

    } else {

        // If no group found, set an error or default value

        outputs.error = "No matching group found for BU Code: " + buCode;

    }

})(inputs, outputs);

 

Hope this will help you.

Runjay Patel
Giga Sage

Hi @dhineshkumar ,

 

instead of writing script you can define assignment rule to set the group on task table.

 

writing script is not recommended if that can be done using configuration.

@Runjay Patel 

would you please assist to me right script based on my requirement.

Thank you.

@dhineshkumar there are multiple tables involved in your validation so I don't think without script you would be able to achieve.