cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Nintex Newbie

JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

Hi Folks,

I am creating a form signature feature on one of my forms and I want to get the current user display name to show up in the signature block. Here is what I have so far:

I have a calculated Value that gets exactly what I want...

I want to get the values from the Calculated Value control into the following JavaScript so I can trigger it with a button click"

function signFormPM() {
    var curDate = new Date();
    NWF$('#'+ jsvar_PMDate).val((curDate.getMonth() + 1) + '/' + curDate.getDate() + '/' + curDate.getFullYear());
    NWF$('#'+ jsvar_PMName).val("[PUT THE CALC VALUE HERE](Current User)");
}

Any thoughts?

0 Kudos
Reply
10 Replies
Highlighted
Automation Master
Automation Master

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

assign a javascript variable to the calculated value control, eg. calcCtrl.

then you should be able to get its value from javascript with

NWF$('#'+calcCtrl).val()

View solution in original post

Reply
Highlighted
Nintex Newbie

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

Hi Marian Hatala,

Does this look like it should work then? The button click is failing when this function is called.

function signFormPM() {
    var curDate = new Date();
    NWF$('#'+ jsvar_PMDate).val((curDate.getMonth() + 1) + '/' + curDate.getDate() + '/' + curDate.getFullYear());
    NWF$('#'+ jsvar_PMName).val(NWF$('#'+ jsvar_CurUserPreferredName_CAL).val() +" (Current User)");
}‍‍‍‍‍‍‍‍‍‍
0 Kudos
Reply
Highlighted
Automation Master
Automation Master

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

yes, seems to.

I tried your line of code for current user and it worked for me.\

what error do you get?

Reply
Highlighted
Nintex Newbie

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

No explicit error, rather, when I clicked the "Sign" button, the page refreshed and no data was rendered in the appropriate fields. When my code does not error, a button click will immediately pop values into my fields.

Also... this code works:

function signFormPM() {
    var curDate = new Date();
    NWF$('#'+ jsvar_PMDate).val((curDate.getMonth() + 1) + '/' + curDate.getDate() + '/' + curDate.getFullYear());
    //NWF$('#'+ jsvar_PMName).val(NWF$('#'+ jsvar_CurUserPreferredName_CAL).val() +" (Current User)");
}

...and this code des not:

function signFormPM() {
    var curDate = new Date();
    NWF$('#'+ jsvar_PMDate).val((curDate.getMonth() + 1) + '/' + curDate.getDate() + '/' + curDate.getFullYear());
    NWF$('#'+ jsvar_PMName).val(NWF$('#'+ jsvar_CurUserPreferredName_CAL).val() +" (Current User)");
}

The only difference being I commented out the line calling the calculated value.

Reply
Highlighted
Automation Master
Automation Master

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

hm, that's weird.

what's the value of calculated control? doesn't it contain any 'possibly dangerous' characters that might break js code?

keep the current user line commented out and try one by one whether following executes correctly

console.log("1: "+NWF$('#'+ jsvar_CurUserPreferredName_CAL).val());

console.log("2: "+NWF$('#'+ jsvar_PMName).val());                                

NWF$('#'+ jsvar_PMName).val("xxx");

Reply
Highlighted
Nintex Newbie

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

Hi Marian,

Calculated Control formula is: userProfileLookup(Current User, "PreferredName")

In my case it would render "Kelligan, Patrick S."

Here are your code results

console.log("1: "+NWF$('#'+ jsvar_CurUserPreferredName_CAL).val()); 
    //Error

console.log("2: "+NWF$('#'+ jsvar_PMName).val());
    //No error but no value population

NWF$('#'+ jsvar_PMName).val("xxx");
     //Populates :XXX" into the signature field
0 Kudos
Reply
Highlighted
Automation Master
Automation Master

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

any details on the error? (developer console message, message popup...)

can you in addition test:

console.log("4: "+NWF$('#'+ jsvar_CurUserPreferredName_CAL).length);

console.log("5: "+jsvar_CurUserPreferredName_CAL);

can you proof-check you have correctly configured js variable for calculated control (eg. some typo)?

what's the dataype is set for calc value control?

what form mode do you test on?

hopefully you tested on published form not only on preview

Reply
Highlighted
Nintex Newbie

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

Hello Marian,

can you proof-check you have correctly configured js variable for calculated control (eg. some typo)?

Funny thing...

I changed a setting on the calc value a while back and it had some unintended consequences. The calculated value control is not meant to be seen so I set the Visible property to No and it made the js variable go away. Is did not delete the variable string but hid the configuration input box.

When I set it back to Yes, the js variable showed up again and the original suggestion you made worked.

NWF$('#'+ jsvar_PMName).val(NWF$('#'+ jsvar_CurUserPreferredName_CAL).val() +" (Current User)");

I am sorry for the false errors. Thanks so much for getting this thing figured out!

0 Kudos
Reply
Highlighted
Automation Master
Automation Master

Re: JavaScript: Put a Calculated Value and Put it in a Text Box

Jump to solution

great!

yes, that's a known 'feature'.

the best way to manage visibility is to place a control into panel and assign rule to the panel.

Reply