Skip to Content
0

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

Dec 15, 2016 at 06:06 PM

151

avatar image
Former Member

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!

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Steve Rumsby
Dec 16, 2016 at 03:25 PM
1

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

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.

0