This topic contains 4 replies, has 0 voices, and was last updated by Jayadeep Reddy 10 years ago.

  • Author
    Posts
  • #10160

    Jayadeep Reddy

    Is there a way to create a group and associate it with approval process
    This is a cached copy. Click here to see the original post.

  • #10161

    corey

    You can do this by using a Workflow action script to check if a user is a member of group. I use this exact mechanism for quote approvals.

    Here is the code I use:

    PHP Code:

    // Take in a group and checks if the current
    // user is in the group. Returns true or false.
    var main = function() {
        // vars
        var group,        
            user,
            filters = [],
            columns = [],
            searchresults = [];

        // Get logged in user
        user = nlapiGetUser();    
        //nlapiLogExecution(‘DEBUG’, ‘User ‘, user);
        
        // Get the group parameter.
        group = nlapiGetContext().getSetting(‘SCRIPT’, ‘custscript_cxs_cswo_spvrgroup’);
        //nlapiLogExecution(‘DEBUG’, ‘Group ‘, group);
        
        // Criteria
        filters.push(new nlobjSearchFilter(‘internalid’, null, ‘is’, group));
        filters.push(new nlobjSearchFilter(‘internalid’, ‘groupmember’, ‘is’, user));
        
        // Results
        columns.push(new nlobjSearchColumn(‘internalid’, ‘groupmember’ )); // Member Id

        try {
            // Check for user
            searchresults = nlapiSearchRecord(‘entitygroup’, null, filters, columns); 
            // Return true if we have results
            if (searchresults){
                return ‘T’;
            }        
        } catch (e) {
            nlapiLogExecution(‘DEBUG’, e.name, e.message);
            return ‘F’;
        }    
        return ‘F’;
    }

  • #10162

    evan_goldberg

    I think there may be an even easier way to test group membership in a workflow, using a search for the transition – in the search, have a filter user : group includes , that should match the record if and only if the logged in user is a member of the specified group. I haven’t actually tried it though…

  • #10163

    corey

    That would indeed be easier, Evan. That option must not have been around 3 years ago when you told me to create a workflow action script for this

  • #10164

    Jayadeep Reddy

    It worked,

    Thanks a lot corey and evan

You must be logged in to reply to this topic.