Hi, @Margo
I want to redirect to specified view an user which belong to a SharePoint group from routing.
I see that i can select group in routing options, but i have custom routing and options didn't work.
i need to check user membership from routing.
Hello @ixxxl,
You can check if a user is a member of the SharePoint group and rout him to a specific form set using the code from this post:
@Margo
Thank you, it works.
But when i put it to all my cod in routing simple user can't enter the form. User have edit, but when enter in the form access denied maybe is some mistake?
i have some returns by the Status.
if (item) {
//first, get the current user
var user;
// return Promise
return web.currentUser.get()
.then(function (u) {
user = u;
return item.get();
})
.then(function (item) {
return web.siteGroups.getByName('SupervizoriIT').users.get().then(function (result) {
return pnp.sp.web.currentUser.get().then(function (currentUser) {
// if (item.Numarul_x0020_de_x0020_tabel == "985215") {
var vb = false;
for (var i = 0; i < result.length; i++) {
if (result[i].Email == currentUser.Email) {
vb = true;
}
}
if (item.SupervizoriId && item.SupervizoriId.indexOf(user.Id) >= 0) {
vb = true
}
if (item.Statutul_x0020_Cererii == 'Creată') {
vb = false
}
if (user.Id == item.SpecialistId) {
vb = false
}
if (item.Catre_x0020_specialistulId && item.Catre_x0020_specialistulId.indexOf(user.Id) >= 0) {
vb = false
}
// if (user.Id==item.AuthorId){vb=false}
if (vb) {
return '5d1dbfda-e546-43d6-a28c-93d767147e48'
} //view supervizor
// } //nr tabel
if (item.Statutul_x0020_Cererii == 'Transmisă') {
return '2fe9c0c6-ff85-4e5e-87ca-119f123327d3'
} else if (item.Statutul_x0020_Cererii == 'Preluată') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Returnată') {
return '79f5dd37-e1c8-4ab2-b4ec-2cf9200b65ce'
} else if (item.Statutul_x0020_Cererii == 'Refuzată') {
return '98a419f4-ad38-4d88-8614-59dc0f8c2a60'
} else if (item.Statutul_x0020_Cererii == 'Pauză') {
return '1995262e-84e6-4ecb-a428-6de06a2ec429'
} else if (item.Statutul_x0020_Cererii == 'Rezolvată') {
return 'a9ad54bd-2be0-4437-ab25-9f24104fcba9'
} else if (item.Statutul_x0020_Cererii == 'Redirecționată') {
return '731707b4-fed7-41fb-bddd-3d5f11b7dfdf'
} else if (item.Statutul_x0020_Cererii == 'Închisă') {
return '431689cf-7fc3-478d-a496-ea75cf59779a'
} else if (item.Statutul_x0020_Cererii == 'Preluată după Redirecționare') {
return '62b2414a-0e25-477f-afdc-ed3c9f3caea1'
} else if (item.Statutul_x0020_Cererii == 'Preluată după returnare') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Preluată din pauză') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Preluată după Refuzare') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Transmisă după Returnare') {
return '085a3c32-d589-469e-aa61-9c34c87e056d'
} else if (item.Statutul_x0020_Cererii == 'Întoarsă la rezolvare') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
}
});
})
}); //then item
}
Hello @ixxxl,
Syntax is correct. I have two suggestions:
- If a user is a member of multiple groups, you will get the incorrect result. Please see the code example for multiple groups in the same post here:
- Try to debug the code or split it to the smaller parts and test. Might be the problem in logic or typos in Form Set IDs.
@Margo
Thank you!!! i added to begin and works perfect ![]()
if (item)
{
return item.get()
.then(function (item)
{
return web.currentUser.get()
.then(function(user){
return web.siteUsers.getById(user.Id).groups.get()
.then(function(groupsData){
//var groups = [];
//Check if the user is a member of the desired groups and add them to the array
var vb=false;
for (var i = 0; i < groupsData.length; i++) {
//s+=groupsData[i].Title+"/n";
if(groupsData[i].Title == 'SupervizoriIT') {
//groups.push('SupervizoriIT');
// alert("popal");
vb=true;
}
}
// alert(vb);
//Redirect to a Form Set if the user is a member of a group
//if (groups.indexOf('SupervizoriIT') > 0) {
if (item.Statutul_x0020_Cererii == 'Creată') {
vb = false
}
if (user.Id == item.SpecialistId) {
vb = false
}
if (item.Catre_x0020_specialistulId && item.Catre_x0020_specialistulId.indexOf(user.Id) >= 0) {
vb = false
}
// if (user.Id==item.AuthorId){vb=false}
if (vb) {
return '5d1dbfda-e546-43d6-a28c-93d767147e48'
//view supervizor
} else if (item.Statutul_x0020_Cererii == 'Transmisă') {
return '2fe9c0c6-ff85-4e5e-87ca-119f123327d3'
} else if (item.Statutul_x0020_Cererii == 'Supervizor') {
return '2fe9c0c6-ff85-4e5e-87ca-119f123327d3'
} else if (item.Statutul_x0020_Cererii == 'Preluată') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Returnată') {
return '79f5dd37-e1c8-4ab2-b4ec-2cf9200b65ce'
} else if (item.Statutul_x0020_Cererii == 'Refuzată') {
return '98a419f4-ad38-4d88-8614-59dc0f8c2a60'
} else if (item.Statutul_x0020_Cererii == 'Pauză') {
return '1995262e-84e6-4ecb-a428-6de06a2ec429'
} else if (item.Statutul_x0020_Cererii == 'Rezolvată') {
return 'a9ad54bd-2be0-4437-ab25-9f24104fcba9'
} else if (item.Statutul_x0020_Cererii == 'Redirecționată') {
return '731707b4-fed7-41fb-bddd-3d5f11b7dfdf'
} else if (item.Statutul_x0020_Cererii == 'Închisă') {
return '431689cf-7fc3-478d-a496-ea75cf59779a'
} else if (item.Statutul_x0020_Cererii == 'Preluată după Redirecționare') {
return '62b2414a-0e25-477f-afdc-ed3c9f3caea1'
} else if (item.Statutul_x0020_Cererii == 'Preluată după returnare') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Preluată din pauză') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Preluată după Refuzare') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
} else if (item.Statutul_x0020_Cererii == 'Transmisă după Returnare') {
return '085a3c32-d589-469e-aa61-9c34c87e056d'
} else if (item.Statutul_x0020_Cererii == 'Întoarsă la rezolvare') {
return 'acc1aafa-5e8d-404b-b03b-ec7e319b10e9'
}
});
});
});
}
P.S how to make whole code in forum reply to be in one section, not separated as now?
I'm glad it is working now!
To display the whole code in one section you need to cover them in backquotes ``` like this:
