Home › Forums › Classic DFFS › Update Field based off Person or Group Type Email
- This topic has 3 replies, 2 voices, and was last updated 4 years, 6 months ago by Alexander Bautz.
-
AuthorPosts
-
-
May 7, 2020 at 17:23 #29862
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 … -
May 7, 2020 at 18:53 #29866
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
-
May 7, 2020 at 23:53 #29892
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; -
May 8, 2020 at 07:43 #29894
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.