Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Remove group from workflow approval group activity via script.

Vijay Baokar
Kilo Sage

Hi Folks,

 

I have written below BR to remove the group from group notification if its getting deactivated which is working perfect but how can i remove the same group from "workflow approval group activity" if this group is used for group approval. This BR is running on sys_user_group table with condition active changes to false.

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var Grp = current.getValue("sys_id");// Sys_id of deactivated group.
    var GRgrp = new GlideRecord('sysevent_email_action');
    GRgrp.addQuery('recipient_groups',Grp);
    GRgrp.query();
    while (GRgrp.next())
    {
        var watchlst = GRgrp.recipient_groups.toString();
        var newWatch = watchlst.replace(Grp, '');
        GRgrp.recipient_groups = newWatch;

        GRgrp.update();
    }

    //var wf = new GlideRecord('wf_activity');

})(current, previous);
2 ACCEPTED SOLUTIONS

Kieran Anson
Kilo Patron

Workflow activity variables are stored on the sys_variable_value. The 'value' will be the sys_id of the group

KieranAnson_0-1715857314658.png

KieranAnson_1-1715857325896.png

 

View solution in original post

its works with below code:

 

var wfgr = new GlideRecord('sys_variable_value');
    var myquery = "valueLIKE" + Grp;
    wfgr.addEncodedQuery(myquery);
    wfgr.query();

    while (wfgr.next()) {
        var watchlist = wfgr.value.toString();
        var newWatchlst = watchlist.replace(Grp, '');
        wfgr.value = newWatchlst;
        wfgr.update();
    }

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hi @Vijay Baokar ,

Please make some changes like be sure your BR is Before type and update your script with below script 

var Grp = current.getValue("sys_id"); // Sys_id of deactivated group.
    var GRgrp = new GlideRecord('sysevent_email_action');
    GRgrp.addQuery('recipient_groups', Grp);
    GRgrp.query();
    while (GRgrp.next()) {
        GRgrp.recipient_groups = '';
    }

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

@Community Alums My script is all working , i just need similar logic to remove that group from any workflow approval group activity if used.

Kieran Anson
Kilo Patron

Workflow activity variables are stored on the sys_variable_value. The 'value' will be the sys_id of the group

KieranAnson_0-1715857314658.png

KieranAnson_1-1715857325896.png

 

@Kieran Anson but with BR i am not able to remove specific sys_id from value field of group which is getting deactivated.

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here

    var Grp = current.getValue("sys_id"); // Sys_id of deactivated group.

    var GRgrp = new GlideRecord('sysevent_email_action');
    GRgrp.addQuery('recipient_groups', Grp);
    GRgrp.query();
    while (GRgrp.next()) {
        var watchlst = GRgrp.recipient_groups.toString();
        var newWatch = watchlst.replace(Grp, '');
        GRgrp.recipient_groups = newWatch;

        GRgrp.update();
    }

    var wf = new GlideRecord('sys_variable_value');
    wf.addQuery('value', Grp);
    wf.query();
    while (wf.next())
    {
        var watchlist = wf.value.toString();
        var newWatchlst = watchlist.replace(Grp, '');
        wf.value = newWatchlst;

        wf.update();



    }

})(current, previous);