cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

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.

Former Member
0 Kudos

Hi Steve,

source.id works perfectly, thanks!

In my use-case, we have a lot of radio buttons whose actions are similar but slightly different. By combining these into one file, I'm able to avoid a ton of code duplication, plus copying and pasting code snippets (such as long IDs) is dramatically easier when it's spread out among less files. Unless I run into big problems with this approach I'd encourage lots of users to consider working like this!

Thanks again!

-Dan

Former Member
0 Kudos

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.

Answers (0)