Redirect by Group in Custom Routing

Hey everyone,

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.

Thanks for any help!

Dear Joshua,

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.

Hello Alex,

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?

Any help would be great!

Thank you very much

Josh

@JoshMohr

Please try the code below. Just replace ‘Group Name’ with your group name.

pnp.sp.web.siteGroups.getByName('Group Name').users.get().then(function(result) {
var usersInfo = "";
for (var i = 0; i < result.length; i++) {
    usersInfo += "Title: " + result[i].Title + " ID:" + result[i].Id + "<br/>";
}
console.log(usersInfo);
}).catch(function(err) {
alert("Group not found: " + err);
});

@mnikitina

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);
});
}

Here the error:
test

Could you please clarify the group location, is it on the same site or in the root site collection?

Could you please send a screenshot of the permissions list to check the group name.

Thank you!

Hey,

the group is on the same site.
Here the Permissions for the site:
Permissions

@JoshMohr,

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).

Thank you!

@mnikitina

here you go:

Are you using Internet Explorer 11?

If so please clean the cache and update the app package. Instructions can be found in this article.

After, re-save the form and let me if that works.

No I am using chrome. Nontheless I tried as you said but I get the same error message.

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);
});

Hey @mnikitina,

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?

We’ll check.

You can find all groups for the site following the link {your_site_URL}/_layouts/15/groups.aspx

Please send me the screenshot of this page also.

Here you go:

Groups

These groups are correct!

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);
});

First there is a minor mistake in the code the closing brakets “});” are missing at the end.

But also the first line throws an error. My code looks like this:

let web = new Web(“https://ravensburger.sharepoint.com/sites/TestJosh”);

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 the error:
Error

@JoshMohr,

I’m sorry. My bad.
Thanks for noticing.

Please use the following code.

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);
});

Sorry again.

No worries! I’m sorry that this takes so long and very thankfull that you take this time on the issue.

But with this code I get that error:
error

@JoshMohr,

Please paste only that code in the Javascript editor and just in case clear the code in routing too.

image