Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

I need to apply the same long "if" statement to multiple objects in my form...

Avatar

Level 2

How would I add this script as a "Variable," and what text would I have to input into the events for all my objects in order to get the script to run? Right now, I'm just manually copy/pasting the script to the appropriate event for each object in my form.

This is the script I'm currently copying/pasting into various events for 5 different objects on my form.

//Put this code on the following objects: Promo/Adju buttons, New Job Grade, Current Job Grade, Req. Change Percentage
var nNumber = partiii.PromotionFields.NumericField4.rawValue - partiandii.partii.NumericField5.rawValue;

if (partiii.RadioButtonList.rawValue == 1 && partiii.PromotionFields.NumericField4.rawValue <= 22 && nNumber > 2 || partiii.RadioButtonList.rawValue == 1 && partiii.PromotionFields.NumericField4.rawValue <= 22 && partiv.nonflow.DecimalField1.rawValue > 5) {
     partiv.partvandvi.partv.Approval23.presence = "visible";
     partiv.partvandvi.partv.Approval24.presence = "hidden";
     partiv.partvandvi.partv.Approval25.presence = "hidden";
     partiii.PromotionFields.presence = "visible";
}

else if (partiii.RadioButtonList.rawValue == 2 && partiandii.partii.NumericField5.rawValue <= 22) {
     partiv.partvandvi.partv.Approval23.presence = "visible";
     partiv.partvandvi.partv.Approval24.presence = "hidden";
     partiv.partvandvi.partv.Approval25.presence = "visible";
     partiii.PromotionFields.presence = "hidden";
}
else if (partiii.RadioButtonList.rawValue == 1 && partiii.PromotionFields.NumericField4.rawValue <= 22) {
     partiv.partvandvi.partv.Approval23.presence = "hidden";
     partiv.partvandvi.partv.Approval24.presence = "hidden";
     partiv.partvandvi.partv.Approval25.presence = "hidden";
     partiii.PromotionFields.presence = "visible";
}
else if (partiii.RadioButtonList.rawValue == 2 && partiandii.partii.NumericField5.rawValue >= 23) {
     partiv.partvandvi.partv.Approval23.presence = "visible";
     partiv.partvandvi.partv.Approval24.presence = "visible";
     partiv.partvandvi.partv.Approval25.presence = "visible";
     partiii.PromotionFields.presence = "hidden";
}
else if (partiii.RadioButtonList.rawValue == 1 && partiii.PromotionFields.NumericField4.rawValue >= 23) {
     partiv.partvandvi.partv.Approval23.presence = "visible";
     partiv.partvandvi.partv.Approval24.presence = "visible";
     partiv.partvandvi.partv.Approval25.presence = "visible";
     partiii.PromotionFields.presence = "visible";
}
else if (partiii.RadioButtonList.rawValue == 1) {
     partiii.PromotionFields.presence = "visible";
     partiv.nonflow.salarystructure.presence = "visible";
}
else {
     partiv.partvandvi.partv.Approval25.presence = "hidden";
     partiv.partvandvi.partv.Approval24.presence = "hidden";
     partiv.partvandvi.partv.Approval23.presence = "hidden";
     partiii.PromotionFields.presence = "hidden";
     partiv.nonflow.salarystructure.presence = "hidden";
     
}

1 Reply

Avatar

Level 10

Hi,

Maybe place a hidden textfield on the form and call this "controller". Then in the calculate event place the if/else script.

You could make the script a little leaner, by hiding ALL of the objects before the if/else statements AND then in each statement just make the relevant objects visible.

Hope that helps,

Niall