Hi everyone
I've seen many versions of this question asked but none that directly relates to the Nintex forms for Office 365 app.
I have a simple form with a People Picker on it.
I have written code which onload gets the current user and current user manager. I need to populate a Nintex people picker with the result from the Rest call.
My code so far. Any idea how I can do this?
NWF.FormFiller.Events.RegisterAfterReady(function (){
//No need to worry about this part, I've got this covered. GetManager is returning a manager object
var managerUserId = GetManager();
//Get reference to Manager People Picker
var mgrCtrl = document.getElementById(ManagerPickerControlId);
//Now what?
});
you can try the following approach assuming your GetManager() function returns an object that looks like the one below.
NWF.FormFiller.Events.RegisterAfterReady(function (){
var managerUserId = {
"email": "manger@yourdomain.onmicrosoft.com",
"id": "9",
"label": Manager
"title": "",
"type": "User",
"value": "i:0#.f|membership|manger@yourdomain.onmicrosoft.com"
};
//Get reference to Manager People Picker
var mgrCtrl = NWF$('#'+ ManagerPickerControlId);
mgrCtrl.data('uiItempicker')._addItem(managerUserId);
});
NB: please not this approach is not a permanent solution and there is no guarantee it will work in the future.
Hi Cellou, thanks for this solution.
Do you/does anyone know how to remove items from or preferably 'empty' a people picker? I'm populating based on a drop down selection, so at the moment I'm just adding more entries to the people picker, rather than replacing the existing entry with the new one.
I tried setting it to an empty string which didn't work, then I had a guess at a removeItem method, this seems to be on the right lines, but then you need to know the details of the item you're removing I think.. complicated...! Is there any other way?
Hi Stefanie,
Do you have any solution for this one ? I tried using _removeitem, however getting error. Let me know please. Thanks,
Did you test the above solution. This does not work. Grrrrr
It really worked. Thanks..... Below is the code where i am looking people manager from a list.
NWF.FormFiller.Events.RegisterAfterReady(function (){
alert('In Ready....');
var ObjRequesterID = NWF$("#" + SalesRepClientID);
var objManagerID = NWF$("#" + RegManagerClientID);
ObjRequesterID.change(function(){
getManager(ObjRequesterID,objManagerID);
});
})
function getManager(ObjReqID,ObjMngrID)
{
//******* This function gets the Manager from List 'Participant Configurations'********
var ManagerAccount;
alert('In getManager fucntion');
var clientContext= SP.ClientContext.get_current();
var web = clientContext.get_web();
var list = clientContext.get_web().get_lists().getByTitle("Participant Configurations");
if(ObjReqID.val()!="")
{
var trequester=ObjReqID.val().split('|')[2];
alert(trequester.split(';')[0]);
var requesterEmail=trequester.split(';')[0];
var userRequesterInfo = web.ensureUser(requesterEmail);
clientContext.load(userRequesterInfo);
clientContext.executeQueryAsync(
function (sender, args) {
var camlQuery = new SP.CamlQuery();
alert(userRequesterInfo.get_title());
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Person' /><Value Type='User'>"+userRequesterInfo.get_title()+"</Value></Eq></Where></Query></View>");
var items = list.getItems(camlQuery);
clientContext.load(items);
clientContext.executeQueryAsync(
function (sender, args) {
var itemEnumerator = items.getEnumerator();
while(itemEnumerator.moveNext())
{
var item = itemEnumerator.get_current();
var userManagerInfo = web.ensureUser(item.get_item("Manager").get_email());
clientContext.load(userManagerInfo);
clientContext.executeQueryAsync(
function (sender, args) {
var managerUserId = {"email": userManagerInfo.get_email(),"id": "9","label": userManagerInfo.get_title(),"title": "","type": "User","value": userManagerInfo.get_loginName()
};
ObjMngrID.data('uiItempicker')._addItem(managerUserId);
});
}
});
});
}
else
{
//Add code to remove item
}
}