Event.Invoke(FID, Event)
Event.Invoke(FID, Event) invokes the script attached to the event on another form element. The Functional ID and event must be contained within the same form that is executing this method. There are two main conditions for this method to work:
-
The form element in the FID parameter must be enabled
-
The event called for the form element must have a script associated with it
-
The script can be as simple as Event.Base();
-
Note: There are two primary reasons Event.Invoke() will not work and they are by design. The Element being invoked is either hidden or disabled. If you plan to dynamically change your form layouts via scripting and you will be using Event.Invoke(), we storngly suggest using the helper function InvokeEvent() below. This helper function takes the same parameters as Event.Invoke().
Note: After extensive development testing of base code and testing via scripting, the Technical Solutions department highly recommends using Event.Invoke() over the Element Property: 'Fire Change Event On Programmatic Change' for two main reasons. This property only works with the change event, while Event.Invoke() works with all events associated with the element and there is not any way within that process for Deacom to "know" which event is currently in play. Therefore, Event.Base(); in a script executed from 'Fire Change Event On Programmatic Change' will often execute the wrong Event.Base();.
Applies To
Properties and Methods
None
Available
The .Invoke(FID, Event) method is available in:
-
15.04.059
-
15.05.034
-
16.00.039
-
16.01.011
-
All newer builds
Note: The .Invoke(FID, Event) method and all sub-classes, properties, and methods are only available in Form Layout scripts.
Type
Method
Syntax
Event.Invoke(FID, Event);
Parameters
|
Parameter |
Required |
Description |
|---|---|---|
|
FID |
Yes |
A string representing the functional ID of a form element. The FID can be found by right-clicking on any caption on a form. Typically, this will start with Input_, Button_, Grid_, or Section_ |
|
Event |
Yes |
A string that represents an event for the given FID. Can be words like: Click, Change, or other event words. |
Example
Event.Base();
Event.Invoke('Button_Save', 'Click');
/*Expected process
Deacom performs the expected base functionality
Invoke the Click Event on the Save button
Note: The Save button must be enabled, and there must be a script on the click event. Event.Base();
*/
Helper Function InvokeEvent()
//--Here is a helper function that can at least check the enabled state of the form element, set it to enabled prior to invoking the event, and then set it back to its original state.
function InvokeEvent(pcFID, pcEvent)
{
let lnType = pcFID.indexOf('_');
let lcType = String.SubString(pcFID, 0, lnType);
let lpFID;
let llEnabled = false;
let llVisible = false;
//--Set the pointer variable to the correct pointer based on the first word of the Functional ID
switch(lcType)
{
case 'Input':
lpFID = Event.Form.Inputs(pcFID);
break;
case 'Control':
case 'Button':
lpFID = Event.Form.Controls(pcFID);
break;
case 'Grid':
lpFID = Event.Form.Grids(pcFID);
break;
default:
return false;
}
//--Get the current enabled and visible state for the Invoked Element
llEnabled = lpFID.Enabled;
llVisible = lpFID.Visible;
//--Make sure the element is visible and enabled
lpFID.Visible = true;
lpFID.Enabled = true;
//--Invoke the event
Event.Invoke(pcFID, pcEvent);
//--Set the enabled and visible state back to the previous settings
lpFID.Enabled = llEnabled;
lpFID.Visible = llVisible;
}
//--If the help function was used instead, it would look like this
//--Be sure to include the helper function in your script!
Event.Base();
InvokeEvent('Button_Save', 'Click');