Multi select dropdown - lookup from another list

  • 17 September 2019
  • 2 replies
  • 167 views

Hello All,

Here we will create a multiselect dropdown which will lookup another list data.(i.e the fields value is fetching from another list and we can multiple select those values in the nintex form.

Steps:

  • Firstly we should create another list with the data to lookup in the original list.
  • We should use RESTAPI to get the data to the drop down which is not connected to any field in the original list as shown in the code.
  • RESTAPI code below

    NWF.FormFiller.Events.RegisterBeforeReady(function () {
    GetEmpName();
    });

    function GetEmpName()
    {
    var result;
    var RestUrl;
    var hostweburl;
    var appweburl;
    var hostweburl1;
    var appweburl1;
    var pollSP;

     


    if(fn-Or(Is Edit Mode,Is New Mode)){ //editmode, New mode
    pollSP = setInterval(checkSPLoad, 500);
    }
    function checkSPLoad() {
    if (clientContext) {
    window.clearInterval(pollSP);
    GetActionDetails();
    }
    }
    function GetActionDetails() {
    hostweburl1 = "List URL";
    appweburl1 = decodeURIComponent(Utils.getQueryStringParameter('SPAppWebUrl'));

     


    getSomethingWithRESTAction();
    }
    function getSomethingWithRESTAction() {
    var context;
    var factory;
    var appContextSite;
    var listName = "EmployeeProfiles"; // SharePoint list Name
    context = new SP.ClientContext(appweburl1);
    factory = new SP.ProxyWebRequestExecutorFactory(appweburl1);
    context.set_webRequestExecutorFactory(factory);
    appContextSite = new SP.AppContextSite(context, hostweburl1);
    var executor = new SP.RequestExecutor(appweburl1);
    RestUrl = "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listName + "')/items?$select=Full_x0020_Name &$top=1500 &@target='" + encodeURIComponent(hostweburl1) + "'";
    var deferred = NWF$.Deferred();
    var URLL = appweburl1 + RestUrl;
    executor.executeAsync({
    url: URLL,
    method: "GET",
    headers: {
    "Accept": "application/json; odata=verbose"
    },
    success: function (data) {
    var obj = JSON.parse(data.body);
    var results = obj.d.results;
    var response = "";
    if (results.length != 0) {
    for (var i = 0; i < results.length; i++) {
    if (results[i].Full_x0020_Name != null) {
    deferred.resolve(data);
    response += results[i].Full_x0020_Name+';';
    response = response.trim();
    }
    }
    response = response.slice(0,response.length-1);
    var res = response.split(';');
    var res1=res.sort();
    //alert(res.length);
    for (var j = 0; j < res.length; j++) {
    NWF$("#" + EmployeeNameChoiceVar).append("<option value="+res[j]+">"+res[j]+"</option>");
    }
    }
    else {
    //alert("Number,Country not yet available for this user...");
    console.log(results);
    }
    },
    error: function (err) {
    alert(JSON.stringify(err));
    deferred.reject(data);
    },
    });
    };
    var Utils = {
    getQueryStringParameter: function (param) {
    var params = document.URL.split('?')[1].split('&');
    var strParams = '';
    for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split('=');
    if (singleParam[0] == param) {
    return singleParam[1];
    }
    }
    },
    };
    }

     

  • On the form load the data will be fetched and attached to the dropdown.
  • Then we have to append multiselect code to the dropdown as shown below
  • /* Employee dropdown on change event */
    NWF$("#"+EmployeeNameChoiceVar).change(function(){
    var Empdropdown = NWF$('#' + EmployeeNameChoiceVar).find("option:selected").text();
    var Empname = NWF$('#' + EmployeeNameVar).val();
    if(Empname=="")
    {
    NWF$('#' + EmployeeNameVar).val(Empdropdown);
    NWF$("#" + EmployeeNameChoiceVar).val("");
    }
    else{
    NWF$('#' + EmployeeNameVar).val(Empname+';'+Empdropdown);
    NWF$("#" + EmployeeNameChoiceVar).val("");
    }
    });

2 replies

Hello,


 


What would be the benefit of using this method instead of a list lookup control?

Hello,


 


If we use list lookup we cannot achieve multiple select dropdowns in another form. In my code we can achieve that.

Reply