How to set value in Choice field based on value of other choice field

  • 21 November 2016
  • 10 replies
  • 166 views

Badge +6

I have two choice fields as mentioned in below screen shot:

195881_pastedImage_1.png

and the requirements is:

    If Original PO available then Source of Order field should contain string as "Not Applicable" and it should be disabled.

I used rules to disable Source of Order if Original PO available is "Yes", but not able to set value for Source of Order as "Not Applicable"

Can any body help? ....

Thank

Sunil


10 replies

Userlevel 5
Badge +14

to set value of choice control based on value/change of other choice control you will have to write javascript code.

assign javascript variable to your choice controls, eg. varOriginalPOAvailable and varSourceOfPO.

then code like this should do the job.

NWF.FormFiller.Events.RegisterAfterReady(function () { 
   NWF$('#'+varOriginalPOAvailable).change(function(){
     if (NWF$('#'+varOriginalPOAvailable + ' input:checked').val() == 'YES'){
        NWF$('#'+varSourceOfPO).val('Not Applicable');
     }
   })
})
Badge +6

Thanks Marian for your quick response.  Will you kindly explain me in brief how and where this can be set.

Thanks

Sunil

Userlevel 5
Badge +14

you have to set javascript variables in control's setting dialog

javascript copy&paste into form settings/custom javascript

Badge +6

Thanks Marian,

As guided copied javascript after making small changes like "YES" changed to "Yes" and putting semicolons for last two parentheses. also copied variables (varOriginalPOAvailable, varSourceOfPO) to the respective controls.  The script runs but the string "Not Applicable" does not appear in Source of Order, instead the field gets blank on selecting Yes for Original PO Available.

195958_pastedImage_1.png

Thanks

Sunil

Userlevel 5
Badge +14

can you post what's the content of  'source of order' dropdown? is 'Not applicable' option listed there?

can you try to deactivate formatting rule that disables the control?

Badge +6

Great.  

'Not Applicable' was not listed in option.  Listed the same in option and now it shows perfectly, also deactivation also work.

195966_pastedImage_1.png

Thanks a lot.

Cheers happy.png

Sunil

Userlevel 3
Badge +8

What if OrigionalPOAvailable was a dropdown selection insead of a check box. Would you have to change "input:checked" to something else? and if so, what?

I have a similar need and believe this could be the solution. Currently, it isn't working.

I've assigned my variables on each field, and tweaked this JS in my form settings to reflect my variables and data. I'm thinking the problem is that I'm setting a checkbox choice field that allows multiple selections from a dropdown choice selection.

Thanks

Kassie

Userlevel 3
Badge +8

edit:

I kind of figured it out. I just left the whole "input:checked' portion off the script.

 NWF.FormFiller.Events.RegisterAfterReady(function () {
   NWF$('#'+varBusRole).change(function(){
     if (NWF$('#'+varBusRole).val ("Yes")){
        NWF$('#'+varEnvi) .val ("Both");
     }
   });
});

Now I'm wondering how I can update multiple field values , not just "varEnvi" My change is in bold below. It isn't working.

 NWF.FormFiller.Events.RegisterAfterReady(function () {
   NWF$('#'+varBusRole).change(function(){
     if (NWF$('#'+varBusRole).val ("Yes")){
        NWF$('#'+varEnvi) .val ("Both")

        NWF$('#'+varSystem) .val ("All");
     }
   });
});

Userlevel 5
Badge +14

What if OrigionalPOAvailable was a dropdown selection insead of a check box.

dropdown for choice or lookup?

scripting for the two will be different.

  if (NWF$('#'+varBusRole).val ("Yes")){

likely, this statement is not correct:  expression NWF$('#'+varBusRole).val ("Yes") sets the value of the NWF$('#'+varBusRole) control, not checks its value being "Yes".

result of assignment is object being modified, so it's always evaluated to boolean true.

My change is in bold below. It isn't working.

as mentioned above, it may depend on type of control

I'd suggest to start new question since this seems to going  to different direction as original question...

Userlevel 3
Badge +8

Thanks for the reply Marian, I did make a new thread. here's the link:

https://community.nintex.com/thread/19971-set-multiple-field-values-based-on-other-field-selection

Thanks happy.png

Kassie

Reply