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

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

Jump to solution

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

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

0 Kudos
Reply
10 Replies
Workflow Hero

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

Jump to solution

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');
     }
   })
})
Reply
Workflow Hero

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

Jump to solution

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

Thanks

Sunil

0 Kudos
Reply
Workflow Hero

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

Jump to solution

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

javascript copy&paste into form settings/custom javascript

0 Kudos
Reply
Workflow Hero

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

Jump to solution

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.

Thanks

Sunil

0 Kudos
Reply
Workflow Hero

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

Jump to solution

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?

0 Kudos
Reply
Workflow Hero

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

Jump to solution

Great.  

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

Thanks a lot.

Cheers

Sunil

0 Kudos
Reply
Workflow Hero

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

Jump to solution

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

0 Kudos
Reply
Workflow Hero

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

Jump to solution

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");
     }
   });
});

0 Kudos
Reply
Workflow Hero

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

Jump to solution

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

0 Kudos
Reply