cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Set a Field Value with a List Lookup Control

Jump to solution

Hi Folks,

I have successfully configured a list lookup and when a value is selected, I am getting the expected values from the source list item in a series of calculated value controls. My next task is to get some of my list fields/form controls updated with the values that are showing up in the calculated values.

Screenshot

In the image above, I select my name from the dropdown (list lookup control). That loads my last name, first name, and employee ID three calculated value controls currently visible up in the header. I want the values calculated to appear in the appropriate fields below the list lookup control.

I know I could just use the CV controls and bind them to the list fields but I need the user to be able to optionally use manual input if the person is not found I the list.

What is the most straight forward way to do this?

Thanks and Regards,

Patrick Kelligan

Labels: (3)
Reply
43 Replies
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

I think I would write custom JS code that on dropdown change injects these values to proper fields base using their IDs.

But on the other hand, even if you bind these fields to the dropdown, user should still be able to input values manually.. Fields are not disabled in such case. Or am I missing something?

Regards,

Tomasz

Regards, Tomasz Poszytek
Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

Hi Tomasz Poszytek‌!

...even if you bind these fields to the dropdown, user should still be able to input values manually.. Fields are not disabled in such case...

What I meant to say was, if I did not use text controls but rather just used the calc value in their place, the manual input would not be possible.

...I would write custom JS code that on dropdown change injects these values to proper fields base using their IDs.

I thought to use JS but I am not very good with it. Here is what I have done so far. I have loaded the "Client ID JavaScript variable name" for each of the controls I want to populate with 'jsvar_LastName', 'jsvar_FirstName', and 'jsvar_EmpID' respectively. My function so far is below. What else do I need to add to make this work? Also, how to I get the funsction to trigger upon selection or re-selection of the List Lookup control?

BTW, 'cv_LastName', 'cv_FirstName', and 'cv_EmpID' are the names of the calculated value controls.

//=============================;
//  Employee Data Controls;
//=============================;

function populateEmployeeData() {
     NWF$('#'+ jsvar_LastName).val("#" + cv_LastName);
     NWF$('#'+ jsvar_FirstName).val("#" + cv_FirstName);
     NWF$('#'+ jsvar_EmpID).val("#" + cv_EmpID);
}‍‍‍‍‍‍‍‍

Thanks for responding,

Patrick

Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

If you are sure that the "jsvar_" variables hold your values, then to trigger I would suggest to:

  1. Add a JS function to trigger your "populateEmployeeData" function each time your dropdown is changed. To do so:
    NWF$( "#[ID OF YOUR DROPDOWN FIELD]" ).change(function() 
    { 
        populateEmployeeData();
    });‍‍‍‍
  2. Secondly you can try to replace your calculated controls with plain text fields.

Regards,

Tomasz

Regards, Tomasz Poszytek
Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

Thanks for responding Tomasz,

It does not seem to be working. Below it the entirety of my code:

NWF$( "#[llu_Western_Employee]" ).change(function() {
    populateEmployeeData();
});

function populateEmployeeData() {
    NWF$('#'+ jsvar_LastName_CAL).val("#" + jsvar_LastName);
    NWF$('#'+ jsvar_FirstName_CAL).val("#" + jsvar_FirstName);
    NWF$('#'+ jsvar_EmpID_CAL).val("#" + jsvar_EmpID);
}

"llu_Western_Employee" is the control name of my list lookup dropdown.

jsvar_LastName_CAL and the other ..._CAL variables are in the "Client ID JavaScript variable name" fields of their respective Calculated Values controls.

"jsvar_LastName", "jsvar_LastName" and "jsvar_LastName" are in the "Client ID JavaScript variable name" fields of their respective Single Line text box controls.

Do you se where my mistake might be?

Thanks,

Patrick

Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

No, no  Without brackets  So just: "#llu_Western_Employee", instead of "#[llu_Western_Employee]".

Try this:

NWF$( "#llu_Western_Employee" ).change(function() {
    populateEmployeeData();
});

function populateEmployeeData() {
    NWF$('#'+ jsvar_LastName_CAL).val("#" + jsvar_LastName);
    NWF$('#'+ jsvar_FirstName_CAL).val("#" + jsvar_FirstName);
    NWF$('#'+ jsvar_EmpID_CAL).val("#" + jsvar_EmpID);
}

Regards,

Tomasz

Regards, Tomasz Poszytek
Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

Thanks Tomasz!

Ha ha.. what a noob Sorry about that.

Ok, I made the change with still no success. The calc values populate just fine but the single line text controls stay blank.

Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

I might be lost, correct me please if I really am

So you have 6 fields:

  1. 3 calculated, having IDs:
    1. jsvar_LastName_CAL
    2. jsvar_LastName_CAL
    3. jsvar_LastName_CAL
  2. Then you have 3 plain "input type=text" fields:
    1. jsvar_LastName
    2. jsvar_LastName
    3. jsvar_LastName

Now you want to set the values for the NON CAL fields. When your dropdown changes, where do you store the values that you want to put in those fields? In the CAL fields? If so, then your populateEmployeeData() function should look like this:

function populateEmployeeData() {
        NWF$('#'+ jsvar_LastName).val(("#" + jsvar_LastName_CAL).val());
        NWF$('#'+ jsvar_FirstName).val(("#" + jsvar_FirstName_CAL).val());
        NWF$('#'+ jsvar_EmpID).val(("#" + jsvar_EmpID_CAL).val());
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You can as well try to use that sort of selector. I recall I had sometimes issues (dunno why) when just calling fields using their ID from Nintex:

function populateEmployeeData() {
        NWF$('#'+ jsvar_LastName + " input").val(("#" + jsvar_LastName_CAL).val());
        NWF$('#'+ jsvar_FirstName + " input").val(("#" + jsvar_FirstName_CAL).val());
        NWF$('#'+ jsvar_EmpID + " input").val(("#" + jsvar_EmpID_CAL).val());
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Regards,

Tomasz

P.S.

If that still doesn't work try to log out ( using for example console.log(); or alert(); command ) values so that you will be sure, that fields which you want to use as the source really have the value you are going to assign to the other field.

Regards, Tomasz Poszytek
Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

Hi Tomasz Poszytek,

Neither of those worked. I do appreciate your patience with a JavaScript beginner such as myself. I notices the last two snippets had the variable "jsvar_LastName" up from while the one before that had "jsvar_LastName_CAL" (the calculated value controls in the beginning of the lines. Was that intentional?

 NWF$('#'+ jsvar_LastName).val(("#" + jsvar_LastName_CAL).val());

-vs-

NWF$('#'+ jsvar_LastName_CAL).val("#" + jsvar_LastName);

Also, my apologies but I am not sure how to implement the console.log(); or alert(); command; Can you show how I would add them to my code in such a way that they would render the values of the variable and where in the console I would look for the variables?

Thanks,

Patrick

Reply
Workflow Hero

Re: Set a Field Value with a List Lookup Control

Jump to solution

Hey! Don't worry, we all learnt that way

Yes, these two snippets are different because, as I asked you, I'm not certain where you have the values that you want to assign to your text fields.

Generally speaking, the structure of the jQuery command is:

NWF$("#"+ID OF THE FIELD WHERE YOU WANT TO SET A VALUE).val(VALUE TO BE SET);

So you need to replace text "ID OF THE FIELD WHERE YOU WANT TO SET A VALUE" with the ID of the text field AND the text "VALUE TO BE SET" with the value you receive after changing your dropdown, probably already being assigned to the CALCULATED field of yours.

Second thing - to log, or to alert, simply put the line:

console.log(VALUE TO BE LOGGED);

or

alert(VALUE TO BE ALERTED);

console.log will put you a value in the browser console (you can invoke it using F12 key - it names vary - developer console, firebug etc...).

alert will display a monit.

Its really up to you  The reason why I mentioned that is to check, whether you have values in fields, which you'd like to use as the source for your text fields. I'd try the below code:

var LastNameTxt;
var FirstNameTxt;
var EmpIDTxt;

NWF$( "#llu_Western_Employee" ).change(function() {
    LastNameTxt = NWF$('#'+ jsvar_LastName_CAL).val();
    FirstNameTxt = NWF$('#'+ jsvar_FirstName_CAL).val();
    EmpIDTxt = NWF$('#'+ jsvar_EmpID_CAL).val();
    alert (LastNameTxt + " " + FirstNameTxt + " " + EmpIDTxt);
    populateEmployeeData(LastNameTxt, FirstNameTxt, EmpIDTxt);
});

function populateEmployeeData(LastName, FirstName, EmpID)
{
    NWF$('#'+ jsvar_LastName).val(LastName);
    NWF$('#'+ jsvar_FirstName).val(FirstName);
    NWF$('#'+ jsvar_EmpID).val(EmpID);
}

If that alert won't display any values, then that will mean you should check what kind of fields are the one holding your CAL values.

BTW: in one of your first posts you mentioned, that your calculated controls have the following IDs:

Patrick Kelligan napisał(-a):

BTW, 'cv_LastName', 'cv_FirstName', and 'cv_EmpID' are the names of the calculated value controls.

Have you surely changed them into "_CAL"?

Regards,

Tomasz

Regards, Tomasz Poszytek
Reply