Expand my Community achievements bar.

SOLVED

Javascript to concatonate two fields

Avatar

Level 2

Hi,

I'm trying to get variable outputs from two fields and combine the results into one field.

1. If both fields are blank (CHANNEL_NO_P1 and CHANNEL_NO_P2), the concatonated field is blank.

2. If the first field has content but the second field does not, the concatonated should just show the content of the first field (CHANNEL_NO_P1)

3. Else the concatonated field shows the joining of both fields.

I have the part 1 and 3 working but when i add part 2, it screws up the script. (shown below.)

if

(RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P1.isNull || RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P2.isNull) {
    this.rawValue = "";
}
else if (!(RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P1.isNull) || RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P2.isNull} {
    RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P1;
}
else {
    this.rawValue = RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P1.rawValue + RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P2.rawValue;
}

I'm sure it's just syntax around the 'not null' part but i can't seem to get it working. Can anyone help?


Cheers

Rob

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Rob,

The second if statement is not assigning the P1 value to "this.rawValue".  Also you are missing the .rawValue after the P1 object's reference.

{

     this.rawValue = RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHA NNEL_NO_P1.rawValue;

}

I would be inclined to test each objects .rawValue == null or .rawValue != null.

Hope that helps.

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi Rob,

The second if statement is not assigning the P1 value to "this.rawValue".  Also you are missing the .rawValue after the P1 object's reference.

{

     this.rawValue = RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHA NNEL_NO_P1.rawValue;

}

I would be inclined to test each objects .rawValue == null or .rawValue != null.

Hope that helps.

Niall

Avatar

Level 2

Thank Niall.

I've tidied up the script as below.

if (RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P2.rawValue == null)

{this.rawValue = RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P1.rawValue;}

else {this.rawValue = RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P1.rawValue + RadioDuplexer.RadioDuplexerAssetPage1.RadioDuplexerDetailsSubForm.CHANNEL_NO_P2.rawValue;}

And made CHANNEL_P2 field invisible until CHANNEL_P1 is entered.

Thanks again for your help.

Cheers


Rob