Home › Forums › Classic DFFS › Pull email recipients from second list
- This topic has 9 replies, 4 voices, and was last updated 5 years, 6 months ago by Alexander Bautz.
-
AuthorPosts
-
-
November 7, 2018 at 00:42 #22720
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
-
November 7, 2018 at 19:24 #22738
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
-
November 7, 2018 at 19:43 #22743
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.
-
November 7, 2018 at 21:21 #22749
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
-
November 8, 2018 at 23:03 #22768
Worked great! Thank you.
-
April 2, 2019 at 21:19 #24605
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-
April 3, 2019 at 08:01 #24621
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
-
-
April 3, 2019 at 17:18 #24651
Thanks! Will give it a try
-
May 2, 2019 at 16:31 #25167
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?
-
May 3, 2019 at 15:23 #25181
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.