Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Should this be a function?


Level 2

Hi all, I have the code below attached to about 3000 small boxes that insert a text when clicked, it works very well, but I can't help thinking that it's not very efficient!

I've tried fragments, but each box needs to be referenced and I assume that if you change one fragment you change them all.

I also looked at functions and script objects, but I'm lost as it seems to me that you can't use (if - then) etc. within a function.

Would someone be kind enough to tell me if it's possible to convert this to a function and roughly how, please.

Many thanks..Sean

var deleted = substr(Header.currnturl[0].rawValue,64,150)

if (Header.currnturl[0].rawValue == null and $.rawValue == null) then"Please paste a valid URL link into the first page", "No URL Link?", 0, 0)


($.rawValue == null) then

$.rawValue = deleted

$.access = "readOnly"

Rectangle10.assist.toolTip = deleted


var urljoin = concat((Header.urlstart[0].rawValue),



1 Reply


Level 10


It can be a function, which will make it easier to maintain. Script objects only accept javascript, so you would need to change your script to suit.

The click event would look something like:


Then the script object (yourScriptObject) would contain a function (called urlScript):

function urlScript(fldValue) {

     var vDeleted = Header.currnturl[0].rawValue.substring(64,150) // the second parameter is one greater than the last character you want from the string

     if (Header.currnturl[0].rawValue == null && fldValue == null)


"Please paste a valid URL link into the first page", "No URL Link?", 0, 0);


     else if (fldValue == null)


          this.rawValue = vDeleted;

          this.access = "readOnly";

          Rectangle10.assist.toolTip = vDeleted;




          var urljoin = Header.urlstart[0].rawValue.toString() + fldValue;



} // this is the closing bracket in the function         

You will probably need to adapt / change / test...

Good luck,


The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now