- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 07:58 AM
I have an after business rule that runs on deletion of a record on a custom table.
The results of the gs.log are as expected - the sys_id of the group member record I want to delete.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var groupRecordX = new GlideRecord('sys_user_grmember');
groupRecordX.initialize();
groupRecordX.gmRec = current.sys_id; //get the sys_id of current group member record
gs.log(groupRecordX.gmRec);
var groupRecordXu = groupRecordX.gmRec
gs.log(groupRecordXu)
groupRecordXu.deleteRecord(); //Remove the group member record
return;
})(current, previous);
No error messages...
Any ideas?
Thanks for your time,
Lon
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 12:32 AM - edited 06-16-2023 12:32 AM
var groupRecordX = new GlideRecord('sys_user_grmember');
groupRecordX.addQuery('name','yourGroupName');
groupRecordX .addQuery('user','user_sysId'); // user whom you want to remove.. not sure what do you mean by current user...
groupRecordX.query();
gs.log('user: '+userSysId.getDisplayValue());
while(groupRecordX.next()){
groupRecordX.deleteRecord();
}
try the above code in your BR . you have to change accordingly.
mark my answer as correct if helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 08:53 AM
why are you initializing the GR, you are not querying the group, not looping the group etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 09:02 AM
Whoops, groupRecordX.initialize(); was there because I had copied from the script, I have working for adding a member to a group...
I removed that line but still not working as expected.
gs.log consistently returns expected data with no errors or warnings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 10:17 AM - edited 06-15-2023 11:09 AM
I removed initilize() and am trying script below.
and get gs.logs as expected but info message of type: m2m, name[sys_user_grmember] view[null]
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var groupRecordX = new GlideRecord('sys_user_grmember');
groupRecordX.record = current.sys_id; //get the sys_id of current group member record
gs.log(groupRecordX.record);
while (groupRecordX.next){
groupRecordX.deleteRecord(); //Remove the user from TEST group in users's record
groupRecordX.update();
gs.log(groupRecordX.record);
return;}
})(current, previous);
I am opening a new question since code changed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 12:32 AM - edited 06-16-2023 12:32 AM
var groupRecordX = new GlideRecord('sys_user_grmember');
groupRecordX.addQuery('name','yourGroupName');
groupRecordX .addQuery('user','user_sysId'); // user whom you want to remove.. not sure what do you mean by current user...
groupRecordX.query();
gs.log('user: '+userSysId.getDisplayValue());
while(groupRecordX.next()){
groupRecordX.deleteRecord();
}
try the above code in your BR . you have to change accordingly.
mark my answer as correct if helpful.