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

Formatting Dates in JavaScript on a Form

Jump to solution

Hi Folks,

 

I am just getting my feet wet in Forms and JS. I am trying to make the following function run against a form button click to fill out some fields in a form.

 

function signFormPM() {
NWF$('#'+ jsvar_PMDate).val(fn-FormatDate(Current Date, MM/dd/yyyy));
NWF$('#'+ jsvar_PMName).val("Last NameFirst Name (Current User)");
}

The name works ok but the date is loading a decimal into the text field. Can anyone assist?

 

 

Thanks!

Tags (1)
Reply
7 Replies
Highlighted
Nintex Newbie

Re: Formatting Dates in JavaScript on a Form

Jump to solution

I moved this over to Dev Talk since it dealt with JavaScript.

Reply
Highlighted
Automation Master
Automation Master

Re: Formatting Dates in JavaScript on a Form

Jump to solution

try to enclose date formula into apostrophes like

NWF$('#'+ jsvar_PMDate).val("fn-FormatDate(Current Date, MM/dd/yyyy)");

I'm not sure why do you get a number there, but in my env. your formula didn't work at all.

the reason is that fn-FormatDate() inline function is evaluated at render time and my env. is setup with spaces in date. so those space broke up javascript code.

could be that in your env. the output is evaluated as a math expression and so you see result of 3 digits divided.

View solution in original post

Reply
Highlighted
Nintex Newbie

Re: Formatting Dates in JavaScript on a Form

Jump to solution

Hi Marian,

When I added double quotes or single quotes around the function, I got the literal string of the function populating my text box.

Thanks,

Patrick

Reply
Highlighted
Automation Master
Automation Master

Re: Formatting Dates in JavaScript on a Form

Jump to solution

Hi ,

I verified your formula and indeed it saved it as a decimal. I'm not sure why and haven't been able to find the formula to put the literal value. Hopefully someone from can point us in right direction.

Reply
Highlighted
Nintex Newbie

Re: Formatting Dates in JavaScript on a Form

Jump to solution

Hi Kapil Joshi‌,

I worked with it some more and it turns out that Marian Hatala‌'s solution worked for me. Not sure why it did not work the first time I tried it. Perhaps I was troubleshooting too many issues at once on the form.

//this line renders a deciaml:
    NWF$('#'+ jsvar_PMDate_txt).val(fn-FormatDate(Current Date, MM/dd/yyyy));

//This line renders the propper date format:
    NWF$('#'+ jsvar_PMDate_txt).val("fn-FormatDate(Current Date, MM/dd/yyyy)");

Here is where and how it rendered...

Reply
Highlighted
Automation Master
Automation Master

Re: Formatting Dates in JavaScript on a Form

Jump to solution

Great. Good to know!!!

Reply
Highlighted
Automation Master
Automation Master

Re: Formatting Dates in JavaScript on a Form

Jump to solution

I've tested my assumption of date being evaluated as math formula and it really seems to be so

Reply