Update Field based off Person or Group Type Email

Forums Dynamic Forms for SharePoint Update Field based off Person or Group Type Email

Viewing 3 reply threads
  • Author
    Posts
    • #29862
      Ben Denison
      Participant

      I have a requirement to update another field based on a persons email domain. I need to know the best way to accomplish this on a form. I have tried it in Power Automate and its a lot more work because of the trigger changes.

      Its been awhile using javascript with SP and brand new to DFFS. please forgive the rough pseudo code.

      Retrieve email address from Person field type
      Evaluate email domain
      Case xyz.com
      update secondary field with 111
      Case abc.com
      update secondary field with 222
      Case 123.com
      update secondary field with 222
      Case …

    • #29866
      Alexander Bautz
      Keymaster

      You can use something like this in your Custom JS:

      function dffs_PreSaveAction(){
          var userArr = spjs.utility.getFieldValue({"fin":"YOUR_PEOPLE_PICKER_INTERNAL_NAME", "key": "loginname"});
          var userInfo = spjs.utility.userInfo(userArr[0]);
          var email = userInfo.EMail;
          switch(String(email).split("@")[1]){
              case "xyz.com":
                  setFieldValue("fieldName_1", "111");
              break;
              case "abc.com":
                  setFieldValue("fieldName_2", "222");
              break;
              case "123.com":
                  setFieldValue("fieldName_3", "333");
              break;
              default:
                  // no match
              break;
          }
          // Must return true to save item
          return true;
      }

      This code will trigger when you save the list item.

      Alexander

    • #29892
      Ben Denison
      Participant

      Thanks for the quick reply. The email field keeps evaluating to “null”. Would this be because its SharePoint Online?

      var userArr = spjs.utility.getFieldValue({“fin”:”Requester”,”key”:”loginname”});
      var userInfo = spjs.utility.userInfo(userArr[0]);
      var email = userInfo.EMail;

    • #29894
      Alexander Bautz
      Keymaster

      If you look at the userInfo variable (using console.log for example) – do you see all other properties from the user, but not the EMail?

      If so, try changing it like this:

      var userInfo = spjs.utility.userProfile(userArr[0]);
      var email = userInfo.WorkEmail;

      Alexander

Viewing 3 reply threads
  • You must be logged in to reply to this topic.