Friday, June 30, 2017

Set people picker value to nintex form field by javascript

Set people picker value to nintex form field by javascript


var traderList = 'XYZ';
var approversList = 'ABC';

NWF.FormFiller.Events.RegisterAfterReady(function()
{
   NWF$('#'+traderDdl).change(function() 
    {
      // alert(NWF$('#'+traderDdl).val());
    var id =NWF$('#'+traderDdl).val().split(';')[0];
   // alert(id);
    GetManagerOfTrader(id);
    });
});



var items;
function GetManagerOfTrader(Id)
{
  var ctx = new SP.ClientContext.get_current();
  var list = ctx.get_web().get_lists().getByTitle(traderList);
  var camlQuery = new SP.CamlQuery(); 
  var query = "<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>"+Id+"</Value></Eq></Where></Query></View>";
   
  camlQuery.set_viewXml(query);
  items = list.getItems(camlQuery);
  ctx.load(items);
  ctx.executeQueryAsync(OnSuccess,Onfail);
}
function OnSuccess()
{
 var count = items.get_count();
 if(count > 0)
 {
  var listItems = items.getEnumerator();
  while(listItems.moveNext())
  {
    var item = listItems.get_current();
    var managerName = item.get_item("Approver").get_lookupValue();
    var managerId = item.get_item("Approver").get_lookupId();
             alert(managerName+"-"+managerId);
       
    var approverPicker = new NF.PeoplePickerApi('#' + FirstApprover);
    var waitscreen = SP.UI.ModalDialog.showWaitScreenWithNoClose('Working on it...');  
    approverPicker.search(managerName).done(function (data) {
                //add line manager to people picker field
                approverPicker.add(data[0]);
    waitscreen.close(0);
             });
   
   
  }
 }
}
function Onfail()
{
 alert('failed')
}

No comments:

Post a Comment