Form Button Javascript

  • 1 September 2016
  • 11 replies
  • 54 views

Userlevel 4
Badge +10

Hi Folks,

I am still learning Nintex Forms. On a button click, I would like to have the click fill out a couple of fields on the form. I want a date field to show the current date and I want a text field to show the current user's display name. Does anyone know how this is done?

190570_pastedImage_1.png

Thanks and Regards,

Patrick Kelligan


11 replies

Badge +11

Hi, Patrick Kelligan,

See the references here:

Setting current date and time on control

Nintex Forms - Querying User Profiles - Vadim Tabakman

Using Vadim's blog, you just need to return the current user name in the text field. So you would need a small piece of that script. Let us know if you need more details.

Userlevel 4
Badge +10

Hi Kapil Joshi‌ and thanks for the response.

Regarding Vadim's post, his is not exactly what I am looking for as I want to program a button to leverage the "Current User" reference (if this is possible) and his solution is dependent on loading JS libraries to gather profile data on form load. That may end up being a sort of workaround if I cannot get this button to do what I want but it is not quite what I am looking for.

Regarding the "Setting current date and time on control" post, it looks a little more hopeful but, as I was trying to emulate it on my form, I ran into the issue I posted about here. I cannot get the variable to load in the "Client ID JavaScript variable name" field in the control configuration. Any idea why this will not work?

Badge +11

Hi Patrick,

Here is an easier way to populate current user. See the screen below.

Choose Javascript button and add the function showName(). In the text box field, add the Client ID Javascript variable MyName. Here is the code to populate the text box. Add this to Custom Javascript in Settings.

function showName()
{
//alert("hello");
NWF$('#'+ MyName).val("Current User");
}

Current User is the reference added from the Common variable. Note, this will populate the account ID and not the display name. To do so, you have to use one of the methods described in Vadim's blog.

The date function also works the similar way. 

Instead of calling the function on ready like this: NWF$(document).ready(function()

call it when the button is clicked like this: function SetDate() { }

client id in javascript variable not getting created..what might br the reason? 

I'm not sure why you are unable to enter the client ID JS variable. Can you remove the field and try again?

Userlevel 4
Badge +10

This looks promising. I will check it out. As for entering the client ID JS variable, I tried reloading the control. No good. I can enter it in some control types and not others. I did a test of all that I have available. Here are the results:

No=Cannot Input Client ID JavaScript variable name, Yes=Can Input Client ID JavaScript variable name, N/A=Option not available on this control.

Border: N/A
Button: N/A
Calculated Value: No
Choice: Yes
Date/Time: No
Geolocation: N/A
Hyperlink: Yes
Image: N/A
Label: N/A
Multi Line Textbox: Yes
Page Break Guide: N/A
Page Viewer: N/A
Rich Text: N/A
Single Line Textbox: Yes
Sql Request: No
Web Request: No
Yes/No: Yes
Attachments Control: N/A

Userlevel 4
Badge +10

This got me most of the way there and showed me some fundamental JS in forms principles that I can certainly build on. I modified the code to suit and created an Undo button with the additional code.

function signFormPM()
{
//alert("hello");
NWF$('#'+ PMName).val("Last Name, First Name (Current User)");
}
function resetSignaturePM()
{
//alert("hello");
NWF$('#'+ PMName).val("");
}

190594_pastedImage_2.png

Sign, fills the signature field out and Undo clears it. I still need to sort out the data and the Display name with Vadim's post but this is a great start. I will reach out vi this post if I have further questions. Thanks ‌!!

Userlevel 4
Badge +10

Hi Kapil,

I tried to make this function also clear the comments field on Undo button click. It did not work. Is there anything wrong with the following code:

function resetSignaturePM() {
  NWF$('#' + jsvar_PMName).val("");
  NWF$('#' + jsvar_PMComment).val("");
}

UPDATE: 09/02/2016 at 1348 EST...

I figured this out. The list fields were set for "Enhanced rich text". When I changes them to Plain Text, the function worked with no other changes.

Badge +11

Hi Patrick Kelligan,

It looks fine to me. I tested it and it cleared both the fields for me.

function clearName()
{
//alert("hello");
NWF$('#'+MyName).val("");
NWF$('#'+multiText).val("");
}

Add that alert and un-comment it. See if the function is being called when you click the button. Earlier you mentioned that you are unable to provide JS variable to Multi Line Text field. Is it working now or Comments is a different type of field.

Userlevel 4
Badge +10

Hi Kapil,

I was mistaken with MLT. I corrected the post above. MLT works. The two that I need to work on my current projects are Calc Value and Date controls.

I got the following function to work.

function resetSignaturePM() {
  NWF$('#' + jsvar_PMName).val("");
  NWF$('#' + jsvar_PMComment).val("");
}

The list fields were set for "Enhanced rich text". When I changes them to Plain Text, the function worked with no other changes.

Badge +4

Patrick,

Were you just looking to put the persons name into the field as opposed to the actual user? I think I have a similar issue where I am trying to add an actual person object to a form field that's connected to a person column in an Office 365 list.

Userlevel 4
Badge +10

Hi Trang,

The original example in my post would actually have the Sys Admin field showing something like this:

Kelligan, Patrick S. (MyDomain.com/kelliganp)

This would be a composite of the display name and the account name following in parentheses.

Badge +4

,

Thanks for the update. I'll have to create a new issue outlining my problem, I thought this might be a solution for my requirements.

Reply