Issue with deleting record from sys_user_grmember table

Lon Landry4
Mega Sage

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

1 ACCEPTED SOLUTION

Sreedhar Mamill
Giga Expert

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.

 

View solution in original post

5 REPLIES 5

Sreedhar Mamill
Giga Expert

why are you initializing the GR, you are not querying the group, not looping the group etc. 

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.

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

 

 

Sreedhar Mamill
Giga Expert

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.