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

Custom Script on O365

Hi,

I am trying to set a default value to a list lookup using Custom Script but it is not working.

The script is as follows:

NWF$(document).ready(function()  {

NWF$("#" + ddlStaff).val('1'); 

} );

where ddlStaff is the Client ID JavaScript variable name set on the control.

Can anyone provide assistance?

Thanks

Reply
18 Replies
Not applicable

Re: Custom Script on O365

Hi,

Because Nintex Forms online's lookup fetch data asynchronously after page loaded, so you can't set the value on document ready. Try this:

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

    NWF$('#' + ddlStaff).on('change', function (e) {

        if (e.originalEvent == undefined) {

            if (this.value == "") {

                this.value = "1";

            }

        }

    });

});

What is listen to the lookup changes (when data fetched and populated, it's a change), and then we check if is trigger by forms or human (using e.originalEvent check), and if value is empty (means the Please Select... on dropdown list type lookup), then only we set the default value.

Use NWF.FormFiller.Events.RegisterAfterReady instead of document ready to make sure form controls are ready before doing anything. I haven't tested it on cross browsers, hope it help.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Script on O365

Thank you. This worked. Much appreciated.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Script on O365

Hi

Thank you.

I used the above code, Lookup item is getting selected but when i save the item the value is not getting saved.

Please help me on this?

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Script on O365

Hi,

Is the lookup control enabled on the form. I experienced scenarios that any controls on my form that were disabled were not saved.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Script on O365

Yes lookup Control is enabled on the form

0 Kudos
Accept as Solution Reply
Not applicable

Re: Custom Script on O365

What browser are you using?

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Script on O365

Internet explorer version 11.0

0 Kudos
Accept as Solution Reply
Not applicable

Re: Custom Script on O365

Hmm... It's working on my IE 11, can you try insert one more line on the code after line 5 see if it works, so it look like this:

if (this.value == "") { 

     this.value = "1";

     NWF$(this).change();

}

The extra line will force the dropdown list to change.

And also after the form loaded (and when the dropdown list auto selected), can you press ​F12​ and see if there's error in the console?

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Custom Script on O365

Hi,

I included the above code, still the same issue.

Below is the screenshot of the console

0 Kudos
Accept as Solution Reply