Nintex – Setting Default Single Line Textbox Text from List Lookup

Your client has a list that they want to use as a lookup to pre-populate a text field with default data based on information from another field’s dropdown value.

In other words, we want to create a cascading dropdown, but instead of the second dropdown being dropdown, we want it to be a text field.

This post has been edited as a better solution to the problem has been found.

Create a calculated field with the formula:

setOfficeNumberControlValue(lookup("Location", "ID", LocationControl, "Phone"));

Then in your custom JavaScript, add the function:

function setOfficeNumberControlValue(value){
     NWF$('#'+OfficeNumberControl).val(value);
}

How does this work?

By including LocationControl (a list lookup control) in the Nintex Runtime lookup function, this calculated field will be run every time the value of LocationControl changes. This retrieves the value from the “Phone” column of the lookup list “Location” and passes the results into setOfficeNumberControlValue

It’s also worth noting that the above is clearly not production ready code. You should be testing for errors and you might want to generalize things a bit, this is merely a demonstration.

As mentioned, this post has been edited, below is the original post. I’ve left it here as reference only.

With a little setup, this is all the JQuery you’ll need to get this functionality.

NWF$(document).ready(function(){
NWF$('#'+LocationControlID).change(function(){
setTimeout( function(){
NWF$('#'+CityControlID).val(NWF$('#'+CityDefaultID).val());
},1000);
});
});

And here’s the little bit of setup required:

  1. Create our initial List Lookup Control, just do this however you want the field set up. Be sure to name your control and in advanced settings, set Store Client ID in JavaScript variable name to Yes and set a variable name (in the example, this is our LocationControlID).
  2. Create our text field, again, be sure to store the Client ID (CityControlID).
  3. Crete a calculated field to actually get our information. Our Formula gets set to: lookup(“ListToLookup”,”ID”,LocationControl, “ColumnToRetrieve”). It’s important to note here that LocationControl is the name of the first control that we created, it might also be worth noting that the field that we’re filtering on is ID, not the displayed value of the lookup control (even if you’ve connected the text to a field). Now place this calculated field on top of the control that we would like to set the default for, and click the ‘Send to Back’ button. This will effectively hide the control. Note that hiding the control with a rule, or setting Visible:No will result in the calculated field not being calculated, and thus your information will not be retrieved. Once again, be sure to set the Client Side ID (CityDefualtID)

Now let’s go over the JQuery in more detail:

NWF$(document).ready(function(){
//on the LocationControl’s change event (this assumes LocationControl is a dropdown)
NWF$('#'+LocationControlID).change(function(){
//wait 1 second for our calculated field to retrieve the value from the list
setTimeout( function(){
//set the value of the control we want prepopulated to the value of the calculated field
NWF$('#'+CityControlID).val(NWF$('#'+CityDefaultID).val());
},1000);
});
});

It is also worth noting that the time that you should be waiting will depend on different factors, the lookup call has to return a value before we proceed, so play around with the number to find what works.

And that’s that, you’ve got a text field that works as a cascading drop down.

Cheers,

Anthony

Advertisements
Nintex – Setting Default Single Line Textbox Text from List Lookup

5 thoughts on “Nintex – Setting Default Single Line Textbox Text from List Lookup

  1. I’m having a hard time writing this formula in the Nintex Office 365 Calculated filed, Please can you write clear steps for this, I’m not able to create this or can you upload your Nintex forms files that I can use.

    Thank You.
    -Sal

    1. Unfortunately I no longer have access to a system using Nintex, so I can’t supply any forms.

      I also have not attempted to use this set up on the Office 365 Nintex products. I have had issues in the past with Nintex & Office 365 though, so this may not be a viable solution to your problem.

      The solution posted above was created with Nintex Forms 2010.

      I’m sorry that I’m not able to give you more info, perhaps the good people on the Nintex Community boards will be able to help you.

  2. Bradley says:

    Thanks for this, I’ve just implemented a variant with great success.

    I wanted to pull specific list data from an external list and populate some form fields with that data (depending on the logged in user).

    I then wanted to display those fields as disabled (but make them appear in “Display” mode) while in the edit view of the Nintex form, and still populate and submit the fields as if they were enabled.

    When Nintex displays fields in “Display” mode, it doesn’t simply disable the field from being editable, it creates an “ms-restate” div to display the input content, so I had to recreate that in NinJquery.

    Anyway, here’s my modified function that I pass the calculated lookup control into;

    function populateFields(content, fieldID) {
    NWF$(“#” + fieldID).val(content)
    .before(”+content+”)
    .hide();
    }

    Here’s a sample lookup formula that I pass into the populateFields function. (I have enabled “Client ID JavaScript variable name” in the text field properties and named it ’employeeName’ to reference it’s DOM ID…

    populateFields(lookup(“Employee Details List”, “ID”, 1, “AD_Employee”), employeeName)

    It worked a treat, thanks again!

  3. Dinesh Jack says:

    Great post!

    Am able to set the multi line text using this approach
    But am not able to get and set the multi value lookup column “Location” using the same approach.
    Can you please help

    setMultiLookupValue(lookup(“ListA”, “ID”, City, “Location”));

    function setMultiLookupValue(value){
    NWF$(‘#’+listBlocationControl).val(value);
    }

    1. If you set a Calculated Field on the form to
      lookup(“ListA”, “ID”, City, “Location”)
      Does the field show the correct value? Is it possible the Location column has a different name?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s