in Forms Designer we could easily redirect by the user defined rules. I liked this very much because it was easy and powerfull. Now in Forms we can route by Group OR create Custom Routing. Most of the time I have to route According to Group Membership AND specific values etc… So my question is: Is there an good way to check for Group Membership in the custom routing? This would make life a lot easier for me.
Although Automatic routing based on SharePoint group membership and Custom Routing can’t be applied alltogether, you can check user’s group membership with pnp (available in Forms and Custom Routing) https://pnp.github.io/pnpjs/documentation/getting-started/
Automatic routing is supposed to be the easiest way to set routing based only on group membership, for all other issues - Custom Routing is applicable the best way.
sorry for digging out this old question. I found another solution in that case but now I have to get the group membership through pnp. I tried a lot and found this in the web:
function CheckIfUserBelongsToGroup(groupName: string, userEmail: string) {
pnp.sp.web.siteGroups.getByName(groupName).users.getByEmail(userEmail).get().then(rs => {
console.log("user belongs to group");
}).catch(error => {
console.log("user does not belong");
})}
But I don’t get it to work. I’m not that deep in developing so maybe you could help me a bit? Is this the right way to do this? Do you have any clue how to achieve this?
Thanks for your help! Unfortunately it always runs on an error.. It seems that the group is not found but it defininitely is the correct name. Also tried to get the group by id, same result. Do you have any clue what could be causing this?
if (item) {
pnp.sp.web.siteGroups.getByName('Mitglieder von TestJosh').users.get().then(function(result) {
var usersInfo = "";
for (var i = 0; i < result.length; i++) {
usersInfo += "Title: " + result[i].Title + " ID:" + result[i].Id + " ";
}
console.log(usersInfo);
}).catch(function(err) {
alert("Group not found: " + err);
});
}
Could you please send me the screenshot of your code in the Javascript Editor. And also the screenshot of the errors from the browser console and network (scroll down the list to the name highlighted red and click on it).
Could you please paste the following code in Javascript editor and send me the console screenshot. It’ll show group names available.
pnp.sp.web.siteGroups.get().then(function(data) {
var groups = "";
for (var i = 0; i < data.length; i++) {
groups += data[i].Title + "\n";
}
alert(groups);
});
this is interesting. These are the groups that your code finds:
Benutzer für schnelles Bereitstellen
Besitzer von Campus
Besitzer von eBusiness
Besitzer von Öffentlich
Besitzer von Teamwebsite
Besucher von Campus
Besucher von eBusiness
Besucher von Öffentlich
Besucher von Teamwebsite
Designer
Excel Services-Viewer
Formatressourcenleser
Genehmigende Personen
Hierarchie-Manager
Mitglieder von Campus
Mitglieder von eBusiness
Mitglieder von Öffentlich
Mitglieder von Teamwebsite
Personen mit eingeschränkten Leserechten
SharePointHome-OrgLinks-Administratoren
SharePointHome-OrgLinks-Bearbeiter
SharePointHome-OrgLinks-Betrachter
SharingLinks.4daa0031-a0b4-45fd-b381-d0b0b6d41e23.AnonymousEdit.8bf6525f-4829-42b1-9688-e23f6dbf2e86
Übersetzungsmanager
But none of these Groups have permissions on this page. These are just some random groups of other pages but not even close to all groups. Also tried this on different site collections same result. How can this be?
Please try the following code. It’ll return group names of the specified site.
let web = new Web("{your_site_URL}");
pnp.sp.web.siteGroups.get().then(function(data) {
var groups = "";
for (var i = 0; i < data.length; i++) {
groups += data[i].Title + "\n";
}
alert(groups);
});
pnp.sp.web.siteGroups.get().then(function(data) {
var groups = “”;
for (var i = 0; i < data.length; i++) {
groups += data[i].Title + “\n”;
}
alert(groups);
});
var Web = new Web("{your_site_URL}");
Web.siteGroups.get().then(function(data) {
var groups = "";
for (var i = 0; i < data.length; i++) {
groups += data[i].Title + "\n";
}
console.log(groups);
});