Проверка выбора людей в SharePoint - PullRequest
0 голосов
/ 06 мая 2019

Я пытаюсь проверить 2 поля людей в SharePoint и вывести сообщение об ошибке, если они совпадают. В настоящее время у меня есть код ниже:

function PreSaveAction() {
if (document.getElementById('idAttachmentsRow').style.display=='none' )
  {
     alert('Please attach supporting documents.');
     return false ;
  }
if ($("select[title='Vendor & Co Code Required Field'] option:selected").val() == 279) {
                alert("Please select vendor.")
                return false;
}
else {  return true;  }
}

Я попробовал 2 кода ниже (закомментировано)

Этот ничего не делает, и отменяет существующие проверки

/*if ($("input[title='Project Manager']).val() == $("input[title='GOA Approver']).val())
    { 
        alert("Project Manager and GOA Approver cannot be the same.");
        return false;
    }*/

Этот процесс настолько близок к завершению, насколько я понял, - он сохраняет существующие проверки, но возвращает ошибку в полях выбора 2 человек, даже если они разные.

/*if (document.getElementById('ProjectManager_a553beb7-f694-4e6d-b35c-727accadf301_$ClientPeoplePicker_EditorInput').value == document.getElementById('GOA_x0020_Approver_f7d3aad1-fb6e-4bba-a5c3-9933b2a58c3f_$ClientPeoplePicker_EditorInput').value)
{ 
    alert("Project Manager and GOA Approver cannot be the same.");
    return false;
}*/

1 Ответ

0 голосов
/ 06 мая 2019

Попробуйте приведенный ниже пример кода, чтобы получить пользователя из-под контроля людей.

function getUserFromPeoplePicker(title) {
        //Get the people picker field
        var ppDiv = $("div[title='" + title + "']")[0];
        //cast the object as type PeoplePicker
        var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv.id];

        //Get list of users from field (assuming 1 in this case)
        var userList = peoplePicker.GetAllUserInfo();
        var userInfo = userList[0];            

        //The description field contains the login info without the lookup extras.  In new forms this 
        //field can be undefined depending on the field being checked.  Only check if userInfo is
        //initialized.
        if (userInfo != null) {
            // todo use user information
            if (userInfo.EntityData.Email.startsWith('test')) {
                console.log(userInfo.EntityData.Email);
                return true;
            } else {
                alert('Invalid User');
                return false;
            }
        }

        //return userEmail;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...