Skip to Content
avatar image
Former Member

Is it possible to get the ID of a clicked element via scripting in SAP Personas?

Is there any way to grab the ID of a clicked element in a script? I'm trying to create one script that I can attach to a ton of different clickable objects. Here's a pseudocode example:

var thisid = this.id; // this should return the id of the button, radio button, or clickable area that was clicked. HOWEVER, if you actually write the code like this, it attempts to return the ID of the window itself, not the clicked object.

session.put("triggerID",thisid); // stores the ID as a variable

session.utils.executeScript("wnd[0]/doClickAction"); // executes a script that will read the triggerID and run code depending on the ID

If I'm able to do something like this, I can have one script that I link to ALL clickable objects, rather than creating one for each.

Thanks in advance!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 16, 2016 at 03:25 PM

    The script registered for the onClick event will receive a "source" parameter indicating which object is the source of the event. This is the same object you get from session.findById, so you can use for example "source.id" to get the object ID.

    Is that what you are looking for?

    I'm not completely sure having a single script for all your events is such a great idea. Why do you want to do this rather than having separate scripts for each event?

    Steve.

    Add comment
    10|10000 characters needed characters exceeded

    • Putting everything in one big script feels wrong to me, but I do understand your point. Modularisation is a good idea, but Personas developments aren't always big enough that the upsides outweigh the downsides.

      I wouldn't want to recommend it as standard practice, though.