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

Set a default value based on other field

Jump to solution

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

Labels: (1)
Tags (1)
Reply
12 Replies
Automation Master
Automation Master

Re: Set a default value based on other field

Jump to solution
Reply
michael_campbel
Nintex Newbie

Re: Set a default value based on other field

Jump to solution

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

Reply
michael_campbel
Nintex Newbie

Re: Set a default value based on other field

Jump to solution

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???

0 Kudos
Reply
michael_campbel
Nintex Newbie

Re: Set a default value based on other field

Jump to solution

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

0 Kudos
Reply
Automation Master
Automation Master

Re: Set a default value based on other field

Jump to solution

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.

0 Kudos
Reply
michael_campbel
Nintex Newbie

Re: Set a default value based on other field

Jump to solution

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)

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.

0 Kudos
Reply
Automation Master
Automation Master

Re: Set a default value based on other field

Jump to solution

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.

0 Kudos
Reply
michael_campbel
Nintex Newbie

Re: Set a default value based on other field

Jump to solution

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

Reply
Automation Master
Automation Master

Re: Set a default value based on other field

Jump to solution

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

0 Kudos
Reply