I too have come across this scenario (but on On-Premise). I went on to implement the Option#1 that you have mentioned, wherein I came up with a common function which was used for multiple such controls.
- On New form
- Get list of user by making REST API call and bind it to drop-down as options
- On drop-down change, event set the drop-down selected value to a hidden People Picker control which is mapped to List column
- On Edit form
- Get list of user by making REST API call and bind it to drop-down as options
- Get the hidden People Picker value and set it as drop-down selected value
NWF$(document).ready(function () {
if (Is New Mode)
BindApproverNames(NWF$("#" + choApproverName));
if (Is Edit Mode)
{
SetApproverNames(NWF$("#" + choApproverName),NWF$("#" + pplApprover));
}
});
function BindApproverNames(control)
{
control.find('option').remove();
control.append('<option value=""-1"">' + 'Please select a value...' + '</option>');
NWF$.ajax({
type: 'GET',
url: <<url>>,
dataType: 'jsonp',
contentType: 'application/json',
async: true,
success: function (data) {
if (data.esError != 'undefined' && data.esError.type != '' && data.esError.type == 'S')
{
NWF$.each (data.employees, function (key, value) {
approverNames.append('<option value=' + value.employeeId + '>' + value.fullName + '</option>');
});
}
}
});
}
function SetApproverNames(control,pplControl)
{
//get employee ID of the value in the People Picker- You can costomise as per your needs
var approverID = "";
var selectedAccount = pplControl.val();
var slashPos = selectedAccount.lastIndexOf("\");
var selectedLogin = selectedAccount.substring(slashPos + 1,selectedAccount.length-1);
// Getting selected user details from AD via ADLookup Web API
var wsURL = WebApiUrl + 'ADLookup/GetUser?Id=' + selectedLogin; //this is custom
NWF$.ajax({
type: 'GET',
url: wsURL,
dataType: 'jsonp',
contentType: 'application/json',
async: true,
success: function (data) {
approverID = data.employeeId;
}
});
//since employeeId is used as value in the drop-down option
NWF$("#"+ choApproverName).val(approverIDValue) ;
}
Thanks for your reply, I pretty much followed this link and got my issue resolved.
How to Create Cascading Choice Controls – Nintex Forms
Can your code sample be used to get a list of users from a SharePoint Group? If so, do you replace << url >> with the URL of the SharePoint Group? e.g.:
url: 'http://server/manage/site/_layouts/15/people.aspx?MembershipGroupId=123'
Also, there are a few invalid JavaScript lines (e.g. "Is New Mode") and undefined variables (WebApiUrl). Do you mind at least showing samples of what these should contain, even if you use fictitious names? For example, I have no idea how to define the New or Edit mode condition, nor what my WebApiUrl should be.
Thanks in advance.