AnsweredAssumed Answered

Javascript to set value in lookup list control

Question asked by dipetersen on Jul 7, 2016
Latest reply on Aug 3, 2018 by brightlight

I have a lookup-list control on my form tied to a single line text field in SharePoint. In my javascript code, I get customer data from a database and set the default customer data on the form.  On the lookup list control (which is a drop-down list), I use jQuery to set the val() of the control.  This is reflected in the form and I thought it was OK.  When I save the form, nothing is saved to the field. Since this a complicated form, I thought I'd test it out on a regular list.

 

To replicate my environment, create a custom list in SharePoint.

Open the form in Nintex form editor and delete the Title text field.

Place a lookup list control on the form and configure it so that the value is tied to the Title field.

Test your form so that when you create a new item, you get a Drop down list. 

To test my javascript, I wrote the following code:

 

NWF$(document).ready(function(){

            var ddlShipVia = NWF$("#" + tbTitle);

            ddlShipVia.on("change", function(e){

                console.log("Executing ddlShipVia.onChange()");

                if(e.originalEvent == undefined) {

                    if(this.value==""){

                        ddlShipVia.val(286);

                    }

                }

            });

 

});

 

This code works and sets the DDL to the corresponding index value (69).

 

Click Save and I get an error saying that the field is required.  If I manually select a value, then it saves just fine. 

 

Does anyone know how to progamatically set a value in a Lookup List DDL?

Outcomes