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

Form Button Javascript

Jump to solution

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?

Thanks and Regards,

Patrick Kelligan

Labels: (3)
Tags (3)
Reply
11 Replies
Workflow Hero

Re: Form Button Javascript

Jump to solution

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.

0 Kudos
Reply
Workflow Hero

Re: Form Button Javascript

Jump to solution

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?

0 Kudos
Reply
Highlighted
Workflow Hero

Re: Form Button Javascript

Jump to solution

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?

Reply
Workflow Hero

Re: Form Button Javascript

Jump to solution

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

0 Kudos
Reply
Workflow Hero

Re: Form Button Javascript

Jump to solution

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("");
}

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 ‌!!

0 Kudos
Reply
Workflow Hero

Re: Form Button Javascript

Jump to solution

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.

0 Kudos
Reply
Workflow Hero

Re: Form Button Javascript

Jump to solution

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.

Reply
Workflow Hero

Re: Form Button Javascript

Jump to solution

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.

0 Kudos
Reply
Workflow Hero

Re: Form Button Javascript

Jump to solution

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.

Reply