getMehodTriggerElementName & getMethodTriggerFormName issue

Hello everybody.

In Servoy developer 5.0 the following methods

  • application.getMethodTriggerElementName()
  • application.getMethodTriggerFormName()

does not appear in the jscript editor writing application. + ctrl + space, but it works if I write the whole sentence.

Does anybody notice this issue?

These methods have been deprecated in Servoy 5 (meaning they still work but are not recommanded to use anymore), from now on you should use the JSEvent equivalent methods:

function eventMethod(event) {
    var frm = event.getFormName();
    var elem = event.getElementName();
    ....
}

Hi Roberto,

These methods are deprecated in 5.0. Which means they stil work but will be fased out over time.
When a method is called from any (form/button/field) event it will get a JSEvent object passed that will have the following (among others) functions:
event.getElementName()
event.getFormName()

You are encouraged to use this new way of coding.

Hope this helps.

Seems Patrick was faster on the reply button. ;)

Thanks for the reply.

After upgrading from 4.1 to 6 I had fixed all the warnings I had for using these deprecated functions. I use the proposed method, however, it does not work in all cases. I’m probably missing something here.

In my onShow script I call a method that hides certain elements on a form. It’s a global method that needs to know by which form it was called.

/**
 * @properties={typeid:24,uuid:"902CF6D6-5F08-4375-8284-BE6ACBF83A7A"}
 * @param {JSEvent} event
 */
function onShow(event)
{
	globals.gmd_hideSearchBtns(null, event);
...

Method to hide buttons:

/**
 * @properties={typeid:24,uuid:"C89FE07F-019F-445F-BD19-B8F534E7374A"}
 * @param {String} frmName
 * @param {JSEvent} event
 */
function gmd_hideSearchBtns(frmName, event)
{
    if ( !frmName ) {
		frmName = event.getFormName();
...

While getMethodTriggerFormName returns the correct form, event.getFormName() does not. The Interactive Control shows:

=>event
true
=>application.getMethodTriggerFormName()
“tab_obj_bp”

I have the same problem, when I use search/find

/**
 * @properties={typeid:24,uuid:"E9D5235E-9542-490D-B10E-F7FDD4A541A8"}
 * @param {JSEvent} event
 */
function onFind(event)
{
	globals.gmd_saveFoundset('tab_obj_bp');
	globals.gmd_showSearchBtns(null, event);
	controller.find();
}

/**
 * @properties={typeid:24,uuid:"F884FAF1-CA24-4C0E-B6BC-BA9F99C18E49"}
 * @AllowToRunInFind
 * @param {JSEvent} event
 */
function onSearch(event)
{
	globals.gmd_onSearch(null, event);
	controller.search();
}

OnFind works (event has all the info), hitting enter to do onSearch just gives me event = true.

Can I change something that lets me use event.getFormName?

If that does not work, I can of course send the the form name in the frmName parameter or use a global variable, which I could set in the onShow method. I previously did not do that, since application.getMethodTriggerFormName() worked and I only needed the parameter for overrides.

Thanks,
Reto

Hi Reto,

You missed a parameter in the onShow, that’s the new declaration:

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"BC03F225-5991-4B93-B280-6126F856883D"}
 */
function onShow(firstShow, event) {

The same for onFind and onSearch. Just create a new form in 6 and make Servoy generate all methods automatically for you so you can see the parameters.

Thanks, works perfectly! The upgrade to Servoy 6 requires quite a lot of effort, but so far I’m very impressed by the improvements. Great work :-) No doubt that I’ll have to ask more questions, though…