- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 05:07 AM - edited 02-21-2024 05:10 AM
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.
workflow.info('User added successfully: ' + mySplitResult[i]);
} else {
workflow.info('Failed to add user: ' + mySplitResult[i] + ', Error: ' + rec.getErrorMessage());
}
Note: on logs level, It's returning the "Failed to add user" info and Error returned as Undefined.
Advance thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 06:19 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 05:23 AM
Does the impersonation work? Normally you can't impersonate some one with a higher role (like an admin, if you only have ITIL). What if you create a flow for it and run that as admin? Does that work? No impersonation needed.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 05:39 AM
Hi Mark,
Many thanks for the response.
Yes the impersonation is working fine but coming to add / remove the users functionality is not working.
Coming to creating a flow, the existing workflow which currently in place is working fine on lower environment level and the same run script is not working on prod level.
We do compared the Roles, ACL's on all the environments level and same process is available but not sure why this script not working on prod level.
Advance thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 05:31 AM
Hi LaraReddy,
I have run your script in background on my PDI, and it works for me, just added couple of custom values to test. My script is as below, added my comment with the same where you need to make changes -
var myString = '62826bf03710200044e0bfc8bcbe5df1, a8f98bb0eb32010045e1a5115206fe3a';
// Users sys_id. I hope your varaible pool returns sys_id's
gs.info('Splitting Pool: ' + myString); // Might be workflow.log won't work. I am not sure yet.
var currentUser = gs.getUserID(); // Logged in user
var impUser = new GlideImpersonate();
impUser.impersonate('0a826bf03710200044e0bfc8bcbe5d7a'); // Add your Admin record sys_id
var mySplitResult = myString.split(",");
for(i = 0; i < mySplitResult.length; i++)
{
gs.info('Adding user: ' + mySplitResult[i]);
var rec = new GlideRecord('sys_user_grmember');
rec.group = '019ad92ec7230010393d265c95c260dd'; //Check your "current.variables.u_group" is reference to group table
rec.user = mySplitResult[i];
if (rec.insert()) {
gs.info('User added successfully: ' + mySplitResult[i]);
} else {
gs.info('Failed to add user: ' + mySplitResult[i] + ', Error: ' + rec.getErrorMessage());
}
}
impUser.impersonate(currentUser); // End impersonate of admin
Try this changes and let me know if any issue. Happy to help!
Mark this answer correct, if it works for you!!
Thanks!
Simran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 05:45 AM
Hi Simran,
Many thanks for the response.
We checked your suggestions on our script level and it's same as you mentioned.
But not sure why it's not working only prod level because the same script working fine on level environments level.
We also checked all the roles , ACL's and it's completely same on all three env level.
Advance thanks.