PowerShell Scripts
Abstract
The PowerShell Scripts section explains:
- In which directory to store the PowerShell Scripts
- What JSON Object eLegere supplies to the PowerShell Script and its structure.
- What's the structure of the JSON Object with the PowerShell's results.
- How to specify additional parameters and values.
- Differences in PowerShell scripts behavior according to the usage context.
Tutorials
This document explains how eLegere handles the PowerShell Scripts and their execution.
Tutorials in PowerShell section shows what you can do with PowerShell in eLegere: they are step-by-step use cases that you can customize for your own needs.
- Generate Scheduled Email: The tutorial teaches how to create a scheduled weekly email summarizing the latest application's rows.
Where to Store the Powershell scripts?¶
eLegere stores all the PowerShell scripts in a folder that the installation's administrator has configured.
Contact your eLegere administrator to store your PowerShell script in the dedicated folder on the machine.
JSON Object that eLegere Provides to the PowerShell¶
Learn how to use the JSON Object containing the row's fields in a PowerShell script and how it's structured.
Your PowerShell script must have the $actionContext
parameter to receive a JSON Object from eLegere.
$actionContext
receives a String containing the JSON Data converted to string. So, you can use it to retrieve and read all the values you might need to manipulate or record.
Consider the case where you retrieve the row and pass a field's value to an executable. You can through the stringified JSON that eLegere provides:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
eLegere reads and supplies the rows as strings encoding JSON Objects. If you convert the string to JSON, the object has the following structure:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Follows an explanation of the JSON object's keys:
Items
key lists all the rows' objects to be recorded or modified on the database."956cdabb-b752-4dea..."
The row's Storage Id. This object contains in turn two other objects.NewItem
key is the JSON object containing the row with the latest changes.OldItem
key is the JSON object containing the row's information before the changes.
UserId
key is the logon's username.TimezoneMsOffset
key stands for the time difference between the UTC and the local client executing the action. The value is expressed in milliseconds.
JSON Object with Response's Data¶
Follows an explanation of the object containing the message's info and operation's result that you can encode in your PowerShell script.
Your PowerShell script can optionally return information to the user about the action. eLegere displays in the client a certain message and result according to the keys' values (if added to the PowerShell Script).
1 2 3 4 |
|
Message
: A String containing the message to display in the client to the user.ReturnCode
: The key value specifies how eLegere must behave after the PowerShell execution and what result reports. If not specified and left empty, the value passed is000200
(corresponding to a successful result of the action). See Return Codes for the list of behaviors.
Return Codes¶
Each code specifies a different result to communicate to the user.
Code | Name | Behavior |
---|---|---|
000500 | Failed | eLegere blocks the whole database transaction and restores the previous table's status. Displays an error message. |
000200 | Success | eLegere displays a "Success" (This is the Default value for the ReturnCode parameter.) |
How to Add Additional Parameters¶
Learn how to add additional parameters to a PowerShell in eLegere.
Info
See How to Embed PowerShell Scripts in Your Application from the Designer Guide to learn how to create a Custom Action in eLegere. Choose the Invoke PowerShell from the drop-down list.
You can specify additional parameters and keys for a PowerShell. Click the New in the Custom Action's Parameters settings. The action enables to add a new couple of parameters and values.
Action Type and eLegere Behavior¶
Learn what values the PowerShell script receives through the JSON Object from eLegere according to the action:
- Custom Action with Event Trigger: The JSON Object passed by eLegere has the
Items
values with the row's information. - Custom Action with Manual Trigger: The JSON Object passed by eLegere has the
Items
value with the row's information. - Scheduled Job: The PowerShell script runs outside an application, so the
Items
key has no value.
Action | Items Parameter |
---|---|
Custom Action with Event Trigger | |
Custom Action with Manual Trigger | |
Scheduled Job |
PowerShell Version and Action Type
Note what PowerShell version runs for each type of eLegere Action when you write a script:
- If you write a PowerShell script for the Scheduler, the script will run using a self-hosted version of PowerShell 7.
- If you write a PowerShell script for the Custom Actions, the script will run using the PowerShell version installed with your eLegere installation.