The list item was NOT saved: Error sending email

Home Forums Classic DFFS The list item was NOT saved: Error sending email

Tagged: 

Viewing 2 reply threads
  • Author
    Posts
    • #35846
      AdamP
      Participant

        Hello

        I’ve run into a slight issue using email functionality with SharePoint Online (with a DFFS_Email list). On form save, an error message pops up, the item isn’t saved to the sharepoint list and the email isnt written to the DFFS_Email list.

        The issue appears to be related to using a people picker (to populate To: on the email), where the person in the picker, even though validated through the UI on the form, at that point in time hasnt been added to the UIL (https://Tenant.sharepoint.com/sites/SiteName/_layouts/15/people.aspx?MembershipGroupId=0)
        Looking at the network calls in Dev Tools – it appears to be doing an old soap call to validate the user – which then fails as the user isnt in the UIL yet, returning a pop-up:
        “The list item was NOT saved: Error sending email – Missing recipient for the email template TestSend. Please verify that you have a value in the “To” field in your email template (NameField) and then retry saving this item.”
        (The To field definitely does have the correct setup – using a user already in the UIL, DDFS emailing works exactly as expected).

        Request URL: https://tenant.sharepoint.com/sites/SiteName/_vti_bin/lists.asmx
        Which returns <rs:data ItemCount=”0″> when it fails

        Am I doing something fundamentally wrong with the set-up or is there any way to work around this? Ideally I need the form to work with any user, even if they’re not in the UIL immediately.

        Thanks

        AdamP

      • #35849
        Alexander Bautz
        Keymaster

          Hi,
          This function does try to read the email from the site collection user list so when the user has not logged in or been selected (and saved) in a people picker it cannot read the email address.

          The historic reason for this is that earlier versions of SharePoint (that is still supported by DFFS) does not have the userprofile service.

          To work around this issue you must use some custom js.

          Add these two functions and the variable at the “root” of your custom js:

          function getEmailFromUserProfile(fin){
              var selectedUserLogin = spjs.utility.getFieldValue({"fin":fin, "key": "loginName"});
              var userProfile = spjs.utility.userProfile(selectedUserLogin[0]);
              return userProfile.WorkEmail;
          }
          var userEmail = "";
          
          function dffs_PreSaveAction() {
              userEmail = getEmailFromUserProfile("Your_people_picker_field");
              return true;
          }
          

          Please note:
          If you have a dffs_PreSaveAction function already you must edit it to add the line to your current function.

          Now use this variable in your Email template (in the To field):

          {var:userEmail}
          

          Let me know how this works out.

          Alexander

        • #35850
          AdamP
          Participant

            Thank you Alexander !

            Works perfectly. Great answer and speedy reply as always.

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