Expand my Community achievements bar.

Adding Multiple field rawValues into another field based on conditions?

Avatar

Former Community Member

Sorry for the bad description, hard to explain what I'm trying to do...I'm trying to combine the data in several fields into another text field.

For example:

Field.DropDown1

Field.DropDown2

Field.DropDown3

In another text field under calculate I have a script that says:

this.rawValue = "Make-" + Field.DropDown1.rawValue + " Model-" + Field.DropDown2.rawValue + " Year-" + Field.DropDown3.rawValue  <- this works great

Where i'm struggline is how can I vary whats included based on an if statement? So say I only wanted to return the rawValue if the field has a value I want?

this.rawValue = "Make-" + Field.DropDown1.rawValue + if(Field.DropDown2.rawValue !=null) {"Model" + DropDown2.rawValue} + if(Field.DropDown3.rawValue != null) {"Year" + Field.DropDown3.rawValue

This is purely an example, I know my syntax with the IF function above is really bad, i'm not sure how to write this properly. In my actual form i've got about 10 check boxes the user completes. Each check has bindings to something more intuitive than a "Yes/No"... what i'm doing is trying to pull out the selections that are selected and put data into the text field as appropriate.

So bascially how can I add an IF in the midde of my expression without breaking it?

Thanks!

1 Reply

Avatar

Level 10

Hi,

you can use an array to collect and combine the values of filled fields.


var aValues = [];


if (!DropdownList1.isNull) {


  aValues.push("Make-" + DropdownList1.rawValue);


}


if (!DropdownList2.isNull) {


  aValues.push("Model-" + DropdownList2.rawValue);


}


if (!DropdownList3.isNull) {


  aValues.push("Year-" + DropdownList3.rawValue);


}


this.rawValue = aValues.length > 0 ? aValues.join(" ") : "";