Button parameters?

Is it possible to add a parameter to a buttons onAction event?

I would like to run basically the same function from several buttons on a form without have to make a custom method for each button. Passing a parameter would allow the function to decide the appropriate action from there. Currently, when I click in the onAction space in developer, I can only select an existing method.

Jim

Jim,

If I understand what you’re tyring to do, the following should work.

  1. Name all buttons (i.e. btn_1, btn_2, etc.)
  2. Attach the following method to all buttons.
var btnName = application.getMethodTriggerElementName()

//perform any action that is the same for all buttons here

if (btnName == 'btn_1')
{
	//perform actions specific to button 1
}

if (btnName == 'btn_2')
{
	//perform actions specific to button 2
}

Thanks Airmark!

This community continues to impress me!
I posted this question barely an hour ago and you have already come it to help!

Jim,

I would recommend creating separate methods for each button. If you have a lot of buttons, the method could get very long. If your buttons do not perform many of the same actions, it does not make sense to use a single method.

When you select a button and double click the onAction property in Developer, you can select an existing method or create a new method. You can also select a button and use CTRL + double click the onAction method name to open the method.

What you also might consider: instead of using several buttons doing more or less the same (like “new letter”, “new email”, “new appointment”, …) you could also

  • use a global variable,
  • put that on a form,
  • attach a value list showing the “actions” that you want
  • attach a (global) method to the onDataChange event (properties of that field)

in that global method you do whatever has to be done. This does not change the situation you initially described, but saves screen space, can be easily copied anywhere and works like a charm.