Pull email recipients from second list

Forums Classic DFFS Pull email recipients from second list

Viewing 8 reply threads
  • Author
    Posts
    • #22720
      MikeS
      Participant

      The “E-Mail templates for use with DFFS rules” section will work great if I can pull the email recipients from another list (List B) where they are maintained in two multiple value people-picker fields (TO column and CC column) by an end user. This same user will then submit the email from the List A Display form.

      It looks like this approach from the on screen help would be the way to go:

      You can use a variable by inserting the variable name in this format:
      {var:NameOfVariable}
      You must ensure this variable is available in the page.

      I’ve inspected the spjs-utility posts for help in this area but can’t quite determine if that is the way to go to get my email recipients from List B into two variables (TO and CC fields) on List A. Am I on the right track? Any help is much appreciated.

      Mike

    • #22738
      Alexander Bautz
      Keymaster

      Yes, this should be pretty easy with some custom js, but what is the search criteria used to locate the correct item in list B? – I guess it will be based on a value from your current list item in list A?

      Alexander

    • #22743
      MikeS
      Participant

      The items in List B are the same for all items in List A, i.e., every item in List A will always send DFFS-generated emails to the same recipients found in the one row List B.

    • #22749
      Alexander Bautz
      Keymaster

      Look at this sample snippet and see if you can adapt it to fit your needs. Change PeoplePicker1 and PeoplePicker2 with your field names.

      var pp1Var = "";
      var pp2Var = "";
      var listB_item = spjs.utility.getItemByID({
      	"listName":"ListB_DisplayName_or_GUID",
      	"id":Item_ID_in_listB,
      	"viewFields":["PeoplePicker1","PeoplePicker2"]
      });
      // Peoplepicker 1
      if(listB_item.PeoplePicker1 !== null){
      	var arr = [];
      	jQuery.each(listB_item.PeoplePicker1.split(";#"),function(i,v){
      		if(i%2===0){
      			var email = spjs.utility.userInfo(v).EMail;
      			if(email !== null){
      				arr.push(email);
      			}
      		}
      	});
      	pp1Var = arr.join(";");
      }
      // Peoplepicker 2
      if(listB_item.PeoplePicker2 !== null){
      	var arr = [];
      	jQuery.each(listB_item.PeoplePicker2.split(";#"),function(i,v){
      		if(i%2===0){
      			var email = spjs.utility.userInfo(v).EMail;
      			if(email !== null){
      				arr.push(email);
      			}
      		}
      	});
      	pp2Var = arr.join(";");
      }

      Use these variables in your To and Cc.

      Alexander

    • #22768
      MikeS
      Participant

      Worked great! Thank you.

    • #24605
      Leonid
      Participant

      Alex,
      Wondering if there is a way to get user name by email address WITHOUT people-picker. I lookd at spjs.dffs.userInfo() and spjs.dffs.userProfile() and didnt see those taking email address as argument

      • #24621
        Alexander Bautz
        Keymaster

        You can use this custom function:

        function getUserFromEmail (email) {
            var arrOfFields, query, res, result, item;
            result = { success: false };
            arrOfFields = ['ID', 'Name', 'Title', 'EMail', 'Department', 'JobTitle', 'Notes', 'Picture', 'IsSiteAdmin', 'Created', 'Author', 'Modified', 'Editor', 'SipAddress'];
            query = "<Where><Eq><FieldRef Name='EMail' /><Value Type='Text'>" + email + "</Value></Eq></Where>";
            res = spjs.utility.queryItems({ 'listName': 'UserInfo', 'listBaseUrl': _spPageContextInfo.webServerRelativeUrl, 'query': query, 'viewFields': arrOfFields, setRequestHeader: false });
            if (res.count > 0) {
                result.success = true;
                item = res.items[0];
                jQuery.each(arrOfFields, function (i, fin) {
                    result[arrOfFields[i]] = item[arrOfFields[i]];
                });
                return result;
            } else {
                result.success = false;
                return result;
            }
        }
        // Use like this
        getUserFromEmail("user@domain.com");

        Alexander

    • #24651
      Leonid
      Participant

      Thanks! Will give it a try

    • #25167
      John Garrido
      Participant

      The result that comes back is [Object Object]. Is there a way to modify to show the actual data. Or, do you think I’m doing something wrong with the code?

    • #25181
      Alexander Bautz
      Keymaster

      The result of the function is an object and to see it you must use for example console.log like this:

      var res = getUserFromEmail("user@domain.com");
      console.log(res);

      res is now and object and you can access for example the Name attribute like this:

      res.Name

      Alexander

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