Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
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;

     }

}