Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Issue with rawValue data getting repeated

Avatar

Level 2

The Value within Quotes get repeated twice. Any idea?

if(this.rawvalue != null){

     this.rawValue = "/ " + this.rawValue;

}

Desired Result = / SampleData.

Obtained Result = / / Sample Data. The "/ " gets repeated twice.

1 Accepted Solution

Avatar

Correct answer by
Level 10

To test against null you should use the operator !== instead of !=

If (this.rawValue !== null) {

     this.rawValue =  "/ " + this.rawValue;

}

Well, this propably wont avoid the slash gets repeated because the script will add an extra slash every time it is fired.

You'll need to check the current value for an slash atthe beginning using a regular expression like:

/^\//g

The script the could like like:

If (this.rawValue !== null) {

     If (!this.rawValue.match(/^\//g)) {

          this.rawValue =  "/ " + this.rawValue;

     }

}

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

To test against null you should use the operator !== instead of !=

If (this.rawValue !== null) {

     this.rawValue =  "/ " + this.rawValue;

}

Well, this propably wont avoid the slash gets repeated because the script will add an extra slash every time it is fired.

You'll need to check the current value for an slash atthe beginning using a regular expression like:

/^\//g

The script the could like like:

If (this.rawValue !== null) {

     If (!this.rawValue.match(/^\//g)) {

          this.rawValue =  "/ " + this.rawValue;

     }

}