Custom routing not working anymore

Hello there,

i made a custom routing, so that users asssigned in a form will redirected to the right form.
I am the owner.

Unfortunately this is not working anymore. I do not know what happened, because i have not made any changes (as far as i remember).

The problem is that the OWNER is redirected to the INCOGNITO-Formset instead of the first one at the top. 4b18c612-31e4-4763-8ae9-6422e4a75fe0

var web = new Web('https://mysite.mylist');
return web.siteGroups.getByName('Besitzer von Ideenmanagement').users.get().then(function(result) {
  return pnp.sp.web.currentUser.get().then(function(currentUser){  
    for (var i = 0; i < result.length; i++) {
      if(result[i].Email == currentUser.Email){
        return '4b18c612-31e4-4763-8ae9-6422e4a75fe0';
      }
      else if (item) {
    	var user;
    	return web.currentUser.get()
    		.then(function(u) {
    			user = u;
    			return item.get();
    		})
    		.then(function(item) {
                //Fachprüfer
                if (user.Id == item.Fachpr_x00fc_fer_PersonId) {
                	return '358c9335-0ed3-4ac2-94bb-f7e70702b113';
                }
                //Gremiummitglieder
                else if(user.Id == item.GremiumbesetzungId) {
                   return '91e19746-6e95-4ec2-909c-72ba068ed9da';
                }
                //Umsetzer
                else if(user.Id == item.UmsetzungsverantwortungId) {
                   return 'e901c555-1b11-48bd-b799-d8f046f5d00f';
                }
                //Incognito
                else if(user.Id != item.AuthorId) {
                   return '3b12f956-986e-4b3a-9f7b-826009c604ac';
                }
                //Sonst Default Form wenn Ersteller
    		});
    }
    } 
  });
}).catch(function(err) {
  alert("Group not found: " + err);
});

Any suggestions for that?

Hello @DanielB,

What SharePoint version are you using?

Add the code below to the form, to the JavaScript editor. Do you see the alert message when the owner opens the form?

var web = new Web('SiteURL');
web.siteGroups.getByName('GroupName').users.get().then(function(result) {
  pnp.sp.web.currentUser.get().then(function(currentUser){  
    for (var i = 0; i < result.length; i++) {
      if(result[i].Email == currentUser.Email){
        alert('user is a group member');
      }
    } 
  });
});

image

Yes I do get the message!

@DanielB,

Ok, I see. There is a wrong logic in your code.

Please try out the code below:

var web = new Web('https://mysite.mylist');
return web.siteGroups.getByName('Besitzer von Ideenmanagement').users.get().then(function(result) {
  return pnp.sp.web.currentUser.get().then(function(currentUser){  
    for (var i = 0; i < result.length; i++) {
      if(result[i].Email == currentUser.Email){
        return '4b18c612-31e4-4763-8ae9-6422e4a75fe0';
      }
    }
    if (item) {
    	var user;
    	return web.currentUser.get()
    		.then(function(u) {
    			user = u;
    			return item.get();
    		})
    		.then(function(item) {
                //Fachprüfer
                if (user.Id == item.Fachpr_x00fc_fer_PersonId) {
                	return '358c9335-0ed3-4ac2-94bb-f7e70702b113';
                }
                //Gremiummitglieder
                else if(user.Id == item.GremiumbesetzungId) {
                   return '91e19746-6e95-4ec2-909c-72ba068ed9da';
                }
                //Umsetzer
                else if(user.Id == item.UmsetzungsverantwortungId) {
                   return 'e901c555-1b11-48bd-b799-d8f046f5d00f';
                }
                //Incognito
                else if(user.Id != item.AuthorId) {
                   return '3b12f956-986e-4b3a-9f7b-826009c604ac';
                }
                //Sonst Default Form wenn Ersteller
    		});
    }
    } 
  });
}).catch(function(err) {
  alert("Group not found: " + err);
});
1 Like

This code is working.
I just had to remove one bracket before the catch-statement.
Think it was a copy paste error.

Thanks very much!

1 Like