Skip to Content

Personas Javascript Get button name

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    May 17 at 08:33 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • May 16 at 04:35 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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