If Email Domain Contains "xyx.com"

I have a custom button that I want to validate based on the value of a Person field. The button works as desired when the domain in the Person field matches 'ourcompany.com'. But when the button is clicked and the Person field has a domain value other than 'ourcompany.com', the error returned is "fd.field(...).value.includes is not a function'. I was looking for a simple solution and probably I need to try a split or some other technique. I have [looked at this post](Source: Filtration by emails with certain domain) for initial ideas for domain var options but I didn't get too far there. Sometimes I get good ideas from posts outside of Forms Designer.

Does anyone else have a good idea for this task? Thanks!

fd.spBeforeSave(function() {

var currentVolunteer = fd.field('volunteer').value;

    function checkForStaff() {
        if (fd.field('volunteer').value.includes('ourcompany.com')) {
            // Status Volunteer
    	    fd.field('_Status').value = 'Staff Has';
    	    fd.field('projectstatus').value = 'To Staff';
        } else {
            // Status Staff
    	    fd.field('_Status').value = 'Volunteer Has';
    	    fd.field('projectstatus').value = 'To Volunteer';
        }
    }

    // Calling checkForStaff on form loading
    checkForStaff();

});

return fd.save();

Hey @shedev,

Try using fd.field('volunteer').value.Description instead of fd.field('volunteer').value.

The value of a Person field is an object that holds several attributes such as DisplayText (the name of the person) and Description (their full email address).

You also need to check if value is null, this can happen when the field isn't filled in. Trying to access attributes or methods of null will result in an error.

Let me know if this helps.

Thank you @IliaLazarevskii - I will try this and report back.