Routing on new item on group membership

Good day ,
i'm trying routing on creating new form on group membeship,but nothing happens. it works only on edit.

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++) {

                if (groupsData[i].Title === 'DenySolicitareSoftCreate') {
                  vb = true;
              //    alert('Group')
                }
              }
              if (vb) {
                return '0c40f68f-9d1a-4ab0-94db-8e15f85658d6'

              } else if (item.Starea_x0020_solicit_x0103_rii == 'Salvată') {
                return 'a8c42b52-6be7-4305-b1ff-edde44c9be41'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'Respinsă') {
                return 'a8c42b52-6be7-4305-b1ff-edde44c9be41'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'Transmisă la DTI') {
                return 'f3e269b7-6801-4c10-873a-352cb42d666f'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'Transmisă la aprobare') {
                return '884c386e-9c92-4d77-9e86-efb7ac3f4a48'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'Estimare DTI') {
                return '8db82556-364f-40af-841c-aa74c529f174'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'EstimareDTI') {
                return '44815195-037a-4c12-a479-af23a47fa12f'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'Ǝn lucru') {
                return 'aefa2478-42ad-4372-aef6-ff5285a02f38'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'Estimată') {
                return 'aefa2478-42ad-4372-aef6-ff5285a02f38'
              } else if (item.Starea_x0020_solicit_x0103_rii == 'Salvat') {
                return 'ff0bb835-4d9b-43fc-8664-4aaa182efed4'
              } else
                return 'aefa2478-42ad-4372-aef6-ff5285a02f38'
            });
        });
    });
}

I tryed this code
it works for new and edit.
now a want only redirect for new items created. i delete edit form in deny view. for new items works redirect , for existing in edit i have an error:

var web = new Web('http://intranet/procese');
return web.siteGroups.getByName('DenySolicitareSoftCreate').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 '0c40f68f-9d1a-4ab0-94db-8e15f85658d6';
      }
    }
    if (item) {
      var user;
      return web.currentUser.get()
        .then(function (u) {
          user = u;
          return item.get();
        })
        .then(function (item) {
          //FachprĆ¼fer
          if (item.Starea_x0020_solicit_x0103_rii == 'Salvată') {
            return 'a8c42b52-6be7-4305-b1ff-edde44c9be41'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'Respinsă') {
            return 'a8c42b52-6be7-4305-b1ff-edde44c9be41'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'Transmisă la DTI') {
            return 'f3e269b7-6801-4c10-873a-352cb42d666f'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'Transmisă la aprobare') {
            return '884c386e-9c92-4d77-9e86-efb7ac3f4a48'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'Estimare DTI') {
            return '8db82556-364f-40af-841c-aa74c529f174'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'EstimareDTI') {
            return '44815195-037a-4c12-a479-af23a47fa12f'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'Ǝn lucru') {
            return 'aefa2478-42ad-4372-aef6-ff5285a02f38'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'Estimată') {
            return 'aefa2478-42ad-4372-aef6-ff5285a02f38'
          } else if (item.Starea_x0020_solicit_x0103_rii == 'Salvat') {
            return 'ff0bb835-4d9b-43fc-8664-4aaa182efed4'
          } else
            return 'aefa2478-42ad-4372-aef6-ff5285a02f38'
        });
    }
  });
}).catch(function (err) {
  alert("Group not found: " + err);
});

Hello @ixxxl,

This condition checks if item already exist, so it works for Edit and Display forms:

//check if Item already exists, will return true for Edit and Display Form
if (item) {
}

For the routing on New form, place the code outside of this condition.

To route users based on the current user membership try out the code form our documentation.

1 Like

@mnikitina Thank you. for now it works.. strange for me doesn't worked code from manual , by your link..


if (item) {
  var user;
  return web.currentUser
    .get()
    .then(function (u) {
      user = u;
      return item.get();
    })
    .then(function (item) {
 
      if (item.Starea_x0020_solicit_x0103_rii == 'Salvată') {
        return 'a8c42b52-6be7-4305-b1ff-edde44c9be41';
      } else if (item.Starea_x0020_solicit_x0103_rii == 'Respinsă') {
        return 'a8c42b52-6be7-4305-b1ff-edde44c9be41';
      } else if (
        item.Starea_x0020_solicit_x0103_rii == 'Transmisă la DTI'
      ) {
        return 'f3e269b7-6801-4c10-873a-352cb42d666f';
      } else if (
        item.Starea_x0020_solicit_x0103_rii == 'Transmisă la aprobare'
      ) {
        return '884c386e-9c92-4d77-9e86-efb7ac3f4a48';
      } else if (item.Starea_x0020_solicit_x0103_rii == 'Estimare DTI') {
        return '8db82556-364f-40af-841c-aa74c529f174';
      } else if (item.Starea_x0020_solicit_x0103_rii == 'EstimareDTI') {
        return '44815195-037a-4c12-a479-af23a47fa12f';
      } else if (item.Starea_x0020_solicit_x0103_rii == 'Ǝn lucru') {
        return 'aefa2478-42ad-4372-aef6-ff5285a02f38';
      } else if (item.Starea_x0020_solicit_x0103_rii == 'Estimată') {
        return 'aefa2478-42ad-4372-aef6-ff5285a02f38';
      } else if (item.Starea_x0020_solicit_x0103_rii == 'Salvat') {
        return 'ff0bb835-4d9b-43fc-8664-4aaa182efed4';
      } else return 'aefa2478-42ad-4372-aef6-ff5285a02f38';
    });
  } else {
  var web = new Web('http://intranet/procese');
return web.siteGroups.getByName('DenySolicitareSoftCreate').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 '0c40f68f-9d1a-4ab0-94db-8e15f85658d6';
      }
    }
  });
  })
  }

1 Like