Hi all, I have a list control with a people field.
I want to remove the user from a sharepoint group once deleted from the list but if I use the onchange event "delete" when I try to find the user it doesn't exists anymore in the site due to it's been already deleted.
Is there any method to have a before delete event in list controls?
Dear @Pedro,
It seems like you're using Delete button from List or Library control - in that case, you can re-write the code that runs on Delete: instead of deleting the item, mark it for deletion and hide from view, the rest can be done without extra code in Power Automate. Here's how to work with buttons - List or Library control — SharePoint forms
Thank you @Nikita_Kurguzov , I've achieve it re-writing the Delete button's function.
This function first of all remove selected users from the Sharepoint group and later deletes the selected items.
Works like a charm.
Dear @Pedro,
Great to hear it! If you can share the code, please, consider doing so here - other users might be interested in your case, and it will be great help for the community! Of course, only if you don't mind.
var delButton = fd.control('TablaMiembros').buttons.find(function(b) {
return b.id === 'DELETE';
});
delButton.click = function(){
let items = fd.control('TablaMiembros').selectedItems;
let strGrupo = fd.field("Title").value.toString().replaceAll(" ","").normalize("NFD").replace(/[\u0300-\u036f]/g, "");
items.forEach(function(item){
//Get list item from list
pnp.sp.web.lists.getByTitle("Miembros").items.getById(item.ID).get().then(function(Participante){
//Get the user from corresponding column
pnp.sp.web.getUserById(Participante.MiembroId).get().then(function(Usuario){
//Remove Users from Sharepoint Group
pnp.sp.web.siteGroups.getByName(strGrupo).users.removeByLoginName(Usuario.LoginName).then(function(d){
console.log('User removed from group');
});
//Remove users from List
pnp.sp.web.lists.getByTitle("Miembros").items.getById(item.ID).delete().then(function(e){
console.log('Participant deleted from list');
fd.control('TablaMiembros').refresh();
});
});
});
});
};
}