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

Run script on workflow level

LaraReddy
Tera Guru

Hi All,

Can anyone please help us on the below issue.

We wrote the below run script on workflow level to add / remove the users from selected  groups but some reasons it's not working properly.

var myString = current.variable_pool.u_users.toString();
workflow.info('Splitting Pool: ' + myString);
//var myString = current.variables.u_users;

var currentUser = gs.getUserID();  // Logged in user
var impUser = new GlideImpersonate();
impUser.impersonate('6816f79cc0a8016401c5a33be04be441'); // Impersonate Admin to update record
var mySplitResult = myString.split(",");

for(i = 0; i < mySplitResult.length; i++)
{  
workflow.info('Adding user: ' + mySplitResult[i]);  
var rec = new GlideRecord('sys_user_grmember');
rec.group = current.variables.u_group;
rec.user =  mySplitResult[i];
if (rec.insert()) {
    workflow.info('User added successfully: ' + mySplitResult[i]);
} else {
    workflow.info('Failed to add user: ' + mySplitResult[i] + ', Error: ' + rec.getErrorMessage());
}
}

impUser.impersonate(currentUser); // End impersonate of admin

Note: on logs level, It's returning the "Failed to add user" info and Error returned as Undefined.


Advance thanks.
 
1 ACCEPTED SOLUTION

Hi LaraReddy,

 

It seems weird, but you need to dry run the code and do some try and checks. Definitely, you cannot do that over the prod. Might need to clone from prod to DEV and try some try checks there. That is the only thing I can suggest right now. Let me know how it goes.

 

Thanks!!

Simran

 

 

View solution in original post

5 REPLIES 5

Hi LaraReddy,

 

It seems weird, but you need to dry run the code and do some try and checks. Definitely, you cannot do that over the prod. Might need to clone from prod to DEV and try some try checks there. That is the only thing I can suggest right now. Let me know how it goes.

 

Thanks!!

Simran