Skip to main content
Nintex Community Menu Bar

Set a default value based on other field

  • October 13, 2016
  • 12 replies
  • 17 views

Forum|alt.badge.img+5

I have a Travel Form, where the user enters the Departure Date in a Date picker field. I want to be able to set andother field (Flight Departure Date) to the previously entered Departure Date. In InfoPath this is easy, but in Nintex it appears I need to write some JavaScript (and I am not a java script coder).


Can anyone help....PLEASE!!!

12 replies

Forum|alt.badge.img+14
  • Scholar
  • October 13, 2016

Forum|alt.badge.img+5

Lots of information but a bit light on actual step by step instruction...but thanks for this suggestions


Forum|alt.badge.img+5

This is why I like InfoPath over Nintex....to set a default date field based on the value of another date field...quick and easy! In Nintex you need to write all the JavaScript....

Surely someone must have a simple solution???


Forum|alt.badge.img+5

Can anyone help me out. I have copied this script but my form simply hangs. I am not a java expert, so I am flying blind. All I want is to have date field default to the another date field....it's can't be that difficult! Please someone help me out


Forum|alt.badge.img+14
  • Scholar
  • October 19, 2016

was it on published form or in preview? try it wiht published form.

check developer console for any errors (press F12 in a browser and switch to console window)

have you correctly configured javascript variables to source and target date controls?

post your configuration and script if you customized it anyhow.


Forum|alt.badge.img+5

OK, so I created a form with two date/time fields: [Startdate] and [Enddate]. What I am trying to achieve is after the users enters a start date, this is then updated into the Enddate field.

This is the script I placed in Form Settings - Custom JavaScript:

NWF.FormFiller.Events.RegisterAfterReady(function () {            NWF$("#"+StartDateVar).change( function () {   //sets the date box                     NWF$("#"+EndDateVar).val(NWF$("#"+StartDateVar).val());                       });   NWF$("#"+StartDateVar).parent().find("select[id*='DateHours']").change(function () {   //sets the hour box             NWF$("#"+EndDateVar).parent().find("select[id*='DateHours']").val(NWF$("#"+StartDateVar).parent().find("select[id*='DateHours']").val());                      }) NWF$("#"+StartDateVar).parent().find("select[id*='DateMinutes']").change (function () {   //sets the minutes box                NWF$("#"+EndDateVar).parent().find("select[id*='DateMinutes']").val(NWF$("#"+StartDateVar).parent().find("select[id*='DateMinutes']").val());                        })  
})

In the StartDate field I put in the Client ID JavaScript variable (in the EndDate field I put the variable EndDateVar)

193430_pastedImage_1.png

I publish the form and then click on New Item (to add a new form). Nintex simply seems to hand with the circle dots just turning with "Please wait" and the form never opens.


Forum|alt.badge.img+14
  • Scholar
  • October 19, 2016

that seems to be correct at first sight.

I just hope you have correctly formatted javascript code and not how it looks like here to be everything on single line.

try to check developer console for an errors - before you click new item press F12 and switch to console tab.

then click new item and watch the console for any errors.


Forum|alt.badge.img+5

I got someone to check the code and he found a few issues with way SharePoint treats Java:

NWF.FormFiller.Events.RegisterAfterReady(function() {

      NWF$("#" + StartDateVar).change(function() { /*sets the date box*/

        NWF$("#" + EndDateVar).val(NWF$("#" + StartDateVar).val());

      });

     

      NWF$("#" + StartDateVar).parent().find("select[id*='DateHours']").change(function() { /*sets the hour box*/

        NWF$("#" + EndDateVar).parent().find("select[id*='DateHours']").val(NWF$("#" + StartDateVar).parent().find("select[id*='DateHours']").val());

      });

      NWF$("#" + StartDateVar).parent().find("select[id*='DateMinutes']").change(function() { /*sets the minutes box */

        NWF$("#" + EndDateVar).parent().find("select[id*='DateMinutes']").val(NWF$("#" + StartDateVar).parent().find("select[id*='DateMinutes']").val());

      });

});

Updated and it now works


Forum|alt.badge.img+14
  • Scholar
  • October 26, 2016

‌, could you clarify what problems have you found in my code?


Forum|alt.badge.img+5

I got an developer to look at it and he told me there where some ";' missing and that in Java SharePoint/Nintex that the // comments were causing an issue so he change // to /*.....*/

Apart from that.....it worked

Thanks


Forum|alt.badge.img+14
  • Scholar
  • October 31, 2016

so I would say it was just an issue of lost formating (line feeds) as you copy&pasted the code.

double slashes are valid comment delimiters in javascript.


Forum|alt.badge.img

emha, I've noticed Nintex Form custom JavaScript doesn't like "//" for comments. I've had to wrap all comments into comment blocks (/* comment */). I assume this is due to Nintex Forms removing the formatting from the script.