Redirect to formset depending of group membership

Hello,

is it possible to route to a form depending on group membership?

I have an idea management system.

Every user can create elements.
Every user can display elements, but not all of the fields, like name (if the current user is not the author of the element. --> Can do this with custom routing.
But in custom routing the user who are accept or decline the ideas also are affected by this custom routing!

Can i make the custom routing only for one formset? Or any other suggestions?

Can i place the custom routing information in a fd.rendered(function() within the specific form set?

Thanks!

Hello @DanielB,

Yes, you can route the user to a specific form set depending on group membership. Please find the code example in this post:

Add the code to the routing settings:

Thanks for the response.

TBut i think the Problem is, i can not do this on item level. How can i do this on item level?

User A is in group "visitors"
--> visitors can create ideas, edit own ideas and display them ("default form")
--> visitors can view every idea ("incognito form", where names are not displayed)

User B is in group "owner"
--> can do everything ("master-form")
--> set a user to approve the idea

User C is in group "visitors", "approver" (via flow-workflow)
--> visitors like above
--> approver can edit ONLY THE ITEM where the User B set the User C as "approver".
--> every other item is show in "incognito-form"

Is it possible to check on spRendered if a user is the approver and redirect them to a specific form?
I think this would be the easiest way to solve the problem.

I hope this makes things a bit clearer.

Thank you :wink:

@DanielB,

You can check user membership as well as values on the form and route to a specific form.

For instance, check if a user is a member of the Visitors group and if he's created the 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
				for (var i = 0; i < groupsData.length; i++) {
					if(groupsData[i].Title == 'Site visitors') {
						groups.push('Site visitors');
					}
					
					if(groupsData[i].Title == 'Site Owners') {
						groups.push('Site Owners');
       	 			}
				}

                //Redirect to a Form Set if the user is a member of a group
				if (groups.indexOf('Site visitors') > 0 && user.Id == AuthorId) {
					return 'FormSetIdForSiteVisitors';
				}
				else if (groups.indexOf('Site Owners') > 0) {
					return 'FormSetIdOfIncognitoForm';
				}
			});
	});

Thanks for the reply.

I think this is getting too complex because i have to add a user to a group and delete them afterwards.

Maybe i just should redirect the user to the form he needs in order of field values.

I have different Sharepoint fields (Approver, Deployer).
I want to check something like

if currentuser.value == author.id --> go to default form
if currentuser.value != author.id && (fd.field('Approver').value == currentuser.value --> go to Form1
if currentuser.value != author.id && (fd.field('Deployer').value == currentuser.value --> go to Form2

Example:

  • User is the creator --> Default form
  • User is not the creator but the approver --> Form 1
  • User is not the creator but the deployer --> Form 2
  • .........

Sorry, I'm new in JS...
To check those values, can i usepeople picker and a few if else conditions?
Can you post an example?

Thanks!

Daniel

Hello @DanielB,

If you want to check if the current user is an author or if he is an approver/deployer, you can use this code in custom routing:

    if (item) {
    	var user;
    	return web.currentUser.get()
    		.then(function(u) {
    			user = u;
    			return item.get();
    		})
    		.then(function(item) {
    			
                if (user.Id == item.AuthorId) {
                	return 'FormSetIdForAuthor';
                }
                else if(user.Id == item.ApproverId) {
                    return 'FormSetIdForApprover';
                }
                else if(user.Id == item.DeployerId) {
                   return 'FormSetIdForDeployer';
                }
    		});
    } 

Replace Approver and Deployer with the valid internal names of the fields.

Works like a charm!!!! Never thought that the "Id" at the End will take affect!!!

1 Like