cancel
Showing results for 
Search instead for 
Did you mean: 

Personas Javascript Get button name

0 Kudos
380

Hi,

When many script buttons are used in a flavor for the same usage, is it possible to pass the linked button text attribute into the script Javascript ? If yes, the button text becomes a variable for the script and I can reduce the number of scripts by using the same script for all buttons. I need this possibility in many projects.

Thanks,

Pierre

Accepted Solutions (1)

Accepted Solutions (1)

alexandreourth
Active Participant
0 Kudos

Hi Pierre,

I've done something like this in my project. You link all your buttons with the same script, and inside the script you do :

var machine_number;
switch (source.id) {

  case button1.id:
  machine_number = 517;
  break;

  case button2.id:
  machine_number = 518;
  break;
}

var orderList = getOrders(machine_number);

This was my thread : get_id_button_pushed

0 Kudos

Hi Alexandre,

That's exactly what I need.

I just created a example :

My script 'SCRIPT_X1' is linked to 3 script buttons : 'BUTTON01', 'BUTTON02', 'BUTTON03'.


// SCRIPT_X1
var button_text = session.findById(source.id).text;
session.utils.alert(button_text);

When I click on a script button, alert send me the button name : BUTTON01, BUTTON02 or BUTTON03.

Very simple and usefull.

Magnifique et merci.

Pierre

Answers (1)

Answers (1)

cris_hansen
Advisor
Advisor
0 Kudos

Hi Pierre,

The Script Button have the "text" property, that you can use to pass to your scripts, if you want to compare the text of the button with something. You can also change it.

Is this what you are looking for? If not, then please give me more details about what exactly you need.

Kind regards,

Cris

0 Kudos

Thank for your quick answer Cris, I can give you 2 examples.

The first one concerning a PP application. I've let's say 30 production machines, Each one have a number : 517, 518, 534, 555 .. I've created one script button per machine. The user simply push the machine number to receive a list of production orders for he's machine. The script is 30 times the same for all machines. Just the machine number in the first line of the script is different. If I can retrieve the machine number directly from the button, I need only one script affected to the 30 buttons.

A second example relates the transaction ME21N to create a purchase order. I've planned to add an alphabetic list to search the vendors as you can see in the Amazon web site for example. : A B C D E F G H ... Each character is a script button that is used to search the vendor by filling the vendor search field in the header of the transaction. I don't want to create 26 scripts, but always use the same script by retrieving the character from the text property of the pushed button.

I never found a solution in Javascript for that.

Today, if I want to read the text of the button I need to indicate the object ID of the button in the script.
But it's not the goal. The script must be neutral without relation with the button. The link between the button and the script must only assigned to the button in the designer.

It's may be simple, but I'm not a Javascript expert.

Thank you for your help.

Pierre

cris_hansen
Advisor
Advisor
0 Kudos

Hi Pierre,

For the first example, related to the production machines, I have two suggestions:

a) If you want to stick with 30 buttons, then you can use the text property to pass to a single script, so it knows the production machine number. You can use the very same script for all buttons, the script will act upon the text value to determine the production machine.

b) Have a dropdown box, with all the production machine numbers. The user would select a number, then click on a single script button, which would take the value selected from the dropdown box to execute the script for that particular production machine.

Are these approaches feasible for you?

Kind regards,

Cris