AnsweredAssumed Answered

Problem Statement: Lookup columns on the Nintex forms are displaying Loading message and never loads for the user to select when a custom Javascript is added on the form Description: We have certain fields on the form which will enabled/disabled based on

Question asked by kavyakumar on Apr 19, 2018
Latest reply on Apr 25, 2018 by kavyakumar

Problem Statement: Lookup columns on the Nintex forms are displaying Loading message and never loads for the user to select when a custom Javascript is added on the form Description: We have certain fields on the form which will enabled/disabled based on the user and status [ field from another list] Example: Project Number field will be enabled only if the logged in user is Admin and Coversheet Status[ which comes from “Coversheet” list] is “Approved” We are using rest api and JSOM to query the list and disable .Javascript is working fine but when the form opens in edit mode, all look up fields are displaying as “Loading”… as shown in the screen

 

var pollSP;

var CoversheetId;

var appweburl;

var hostweburl;

NWF.FormFiller.Events.RegisterAfterReady(function () {

  

    pollSP = setInterval(checkSPLoad, 500);

  

});

 

function checkSPLoad() {

    if (clientContext) {

        window.clearInterval(pollSP);

        hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));

        appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));

        var layoutsPath = "/_layouts/15/";

        var scriptbase = appweburl + layoutsPath;

 

        NWF$.getScript(scriptbase + "SP.js",

            function ()

            {

                NWF$.getScript(scriptbase + "SP.RequestExecutor.js", onSPLoad);

            }

        );

      

    }

}

 

function onSPLoad() {

    var spGroups = clientContext.get_web().get_currentUser().get_groups();

    clientContext.load(spGroups);

    clientContext.executeQueryAsync(

        Function.createDelegate(this, function () { OnSuccess(spGroups); }),

        Function.createDelegate(this, this.failed)

    );

}

function getQueryStringParameter(paramToRetrieve) {

    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] == paramToRetrieve)

            return singleParam[1];

    }

}

 

 

 

 

 

 

function OnSuccess(spGroups) {

    try {

        var groupsEnumerator = spGroups.getEnumerator();

        while (groupsEnumerator.moveNext()) {

            var userGroupNames;

            var currentGroup = groupsEnumerator.get_current();

            userGroupNames += currentGroup.get_title() + "\n";

            if (currentGroup.get_title() == "PAAdmin") {

               // var ID = decodeURIComponent(getQueryStringParameter("ID"));

                var ID = "1";

                alert("inside PAAdmin");

     

 

                var web = clientContext.get_web();

 

                //Geting reference to the list

 

                var olist = web.get_lists().getByTitle('Projects');

 

                var oitem = olist.getItemById(1);

 

                //get Title,id,ConfigItem fields

 

                clientContext.load(oitem, "Title", "Id", "Coversheet");

 

                clientContext.executeQueryAsync(function () {

 

 

 

                    var columnFieldValue = oitem.get_item("Coversheet");

                //    alert(columnFieldValue);

                    var lookupValue = columnFieldValue.get_lookupValue();

                    alert(lookupValue);

                    var lookupId = columnFieldValue.get_lookupId();

                    alert(lookupId);

                    var executor = new SP.RequestExecutor(appweburl);

                    alert(appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Coversheet')/items?@target='" + hostweburl + "'" + "&$select=CoverSheet_x0020_Status,Title,Id&$filter=Id eq '" + lookupId + "'");

                    if (lookupId != null) {

 

                      

                        executor.executeAsync({

 

                            url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Coversheet')/items?@target='" + hostweburl + "'" + "&$select=CoverSheet_x0020_Status,Title,Id&$filter=Id eq '" + lookupId + "'",

                            method: "GET",

                            headers: { "Accept": "application/json; odata=verbose" },

                            success: function (data) {

                                alert("success");

                                var result = JSON.parse(data.body).d.results;

                                for (var i = 0; i < result.length; i++) {

                                    var Coversheetstatus = result[i].CoverSheet_x0020_Status;

                                    alert(Coversheetstatus);

                                    if (Coversheetstatus == "Approved") {

                                        NWF$('#' + PrjNo).prop("disabled", false);

                                        NWF$('#' + PrjNo).attr("disabled", false);

                                    }

                                }

 

                                },

 

                            });

                    }

 

                },

                    function (a, b) {

 

                    alert(b.get_message());

 

                });

             

           

              

            

           

 

         

            }

        }

    } catch (err) { alert(err); }

}

 

function onQueryFailed1(sender, args) {

    alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());

}

function OnFail() {

    alert("Failed to load groups")

}

Outcomes