Skip Navigation LinksALVAO 8.2ALVAO Asset ManagementSystem Implementation in an OrganizationCustom Edits and ExtensionsCustom Scripts
Skip Navigation Links.
Skip Navigation Links
Skip Navigation Links.
%USERPROFILE%\Documents\ALVAO\Doc\Documentation\doc\en\alvao_8_2\alvao_asset_management\implementation\customization\scripting.aspx
|
Custom Scripts
The Config folder can store the EpCustomScript.js with a user script written in JavaScript. The Config folder is located in the ALVAO Asset Management Console installation folder (by default in C:\Program Files\ALVAO\Asset Management Console\Config). If there is no such folder, create one and save a script into that folder. Once you have restarted the AM Console, the script will initialize automatically.
The script can define service functions that are called automatically from the Console to perform various operations.
Example 1. Example of file EpCustomScript.js
function OnNodeMoving(nNodeId,nDestNodeId,nUserId) { return true; } function OnNodeRemoving(nNodeId,nUserId) { MessageBox("Cannot delete object",0x30); return false; }
In the example above, the script contains the functions OnNodeMoving and OnNodeRemoving. The OnNodeMoving function gives the permission to move an object in the tree. The function is called by moving an object and the release value true means that moving the object is permitted. The OnNodeRemoving function is called before deleting an object from the tree and the release value gives permission to delete that object. In the example above, moving an object is always permitted, while deleting an object is always forbidden. If you try to delete an object, an alert window will open with the message "Cannot delete object".
Release Functions
OnNodeCopying
This function is called before copying an object within the tree, i.e. also if a new object is created based on a template.
- Syntax – bool OnNodeCopying(nNodeId, nDestNodeId, nUserId)
- Parameters
- nNodeId – attribute value (in the database) tblNode.intNodeId of the object to be copied, i.e. a sample object.
- nDestNodeId – attribute value tblNode.intNodeId of the object, into which a copy will be inserted as a child object. The 0 value means that the copy will be created in the tree root.
- nUserID – attribute value tblUser.intUserId specifies the user who is currently logged in.
- Return value – if the function returns a value true, the object will be copied. If the function returns false, no copy will be created. In that case it is usually convenient to display an error message with the MessageBox method.
- Examples
Example 2. Example – Disallow copying objects for a selected user
The following example of use of the OnNodeCopying function prevents the user with the Identification Number 15 to copy objects. The user Identification Number depends on a specific database and it first has to be found in the tblUser table, attribute intUserId.
function OnNodeCopying(nNodeId,nDestNodeId,nUserId) { if ( nUserId == 15 ) { MessageBox("Copying this object is disabled.",0x30); return false; } return true; }
Example 3. Example – Calling a stored procedure from an SQL Server
The following example uses a stored procedurespOnNodeCopying on the SQL server. Object copying is enabled, if the stored procedure returns a non-zero value.
function OnNodeCopying(nNodeId,nDestNodeId,nUserId) { var Con=new ActiveXObject("ADODB.Connection"); Con.Open(ConnectionString); var Cmd=new ActiveXObject("ADODB.Command"); Cmd.ActiveConnection=Con; Cmd.CommandText="spOnNodeCopying"; Cmd.CommandType=4; Cmd.Parameters.Refresh(); Cmd.Parameters.Item("@nNodeId").Value=nNodeId; Cmd.Parameters.Item("@nDestNodeId").Value=nDestNodeId; Cmd.Parameters.Item("@nUserId").Value=nUserId; var Rs=Cmd.Execute(); if ( Rs.Fields.Item(0)==1 ) return true; MessageBox("The object cannot be copied.",0x30); return false; }
The stored procedure is defined as follows:
CREATE PROCEDURE [dbo].[OnNodeCopying] @nNodeId int, @nDestNodeId int, @nUserId int AS BEGIN SET NOCOUNT ON; SELECT 1 END
OnNodeCopied
This function is called after an object is copied or after it is created based on a template.
- Syntax – void OnNodeCopied(nNodeId, nNewNodeId, nUserId)
- Parameters
- nNodeId – attribute value (in the database) tblNode.intNodeId of the object that was copied, i.e. a sample object.
- nNewNodeId – attribute value tblNode.intNodeId of a new object that was created by copying.
- nUserID – attribute value tblUser.intUserId specifies the user who is currently logged in.
- Return value – none
- Examples – refer to OnNodeCopying
OnNodeMoving
This function is called before moving an object within the tree.
- Syntax – bool OnNodeMoving(nNodeId, nDestNodeId, nUserId)
- Parameters
- nNodeId – attribute value (in the database) tblNode.intNodeId of the object to be moved.
- nDestNodeId – Attribute value tblNode.intNodeId of the object, into which the object will be moved. The 0 value means that the object will be moved into the tree root.
- nUserID – attribute value tblUser.intUserId specifies the user who is currently logged in.
- Return value – if the function returns true, the object will be moved. If the function returns false, the object will not be moved. In that case it is usually convenient to display an error message with the MessageBox method.
- Examples – refer to OnNodeCopying
OnNodeMoved
This function is called after moving an object within the tree.
- Syntax – void OnNodeMoved(nNodeId, nSrcParentNodeId, nUserId)
- Parameters
- nNodeId – attribute value (in the database) tblNode.intNodeId of the object that has been moved.
- nSrcParentNodeId – attribute value tblNode.intNodeId of the object that was parent to the object nNodeId before it was moved.
- nUserID – attribute value tblUser.intUserId specifies the user who is currently logged in.
- Return value – none
- Examples – refer to OnNodeCopying
OnNodeRemoving
This function is called before deleting an object, i.e. before moving an object into the Recycle Bin, and before deleting the object from the Recycle Bin permanently.
- Syntax – bool OnNodeRemoving(nNodeId, bMoveToBin, nUserId)
- Parameters
- nNodeID – attribute value (in the database) tblNode.intNodeId of the object to be deleted or moved to the Recycle Bin.
- bMoveToBin – if the object should be moved to the Recycle Bin, this parameter uses the value true. If the object should be deleted permanently, this parameter uses the value false.
- nUserID – attribute value tblUser.intUserId specifies the user who is currently logged in.
- Return value – if the function returns true, the object will be deleted or moved to the Recycle Bin. If the function returns false, the action will not be performed. In that case it is usually convenient to display an error message with the MessageBox method.
- Examples – refer to OnNodeCopying
OnNodeRemoved
This function is called after an object has been deleted, i.e. moved to the Recycle Bin, and after the object has been deleted from the Recycle Bin permanently.
- Syntax – void OnNodeRemoved(nNodeId, bMoveToBin, nUserId)
- Parameters
- nNodeID – attribute value (in the database) tblNode.intNodeId of the object that was deleted or moved to the Recycle Bin.
- bMoveToBin – if the object should be moved to the Recycle Bin, this parameter uses the value true. If the object should be deleted permanently, this parameter uses the value false.
- nUserID – attribute value tblUser.intUserId specifies the user who is currently logged in.
- Return value – none
- Examples – refer to OnNodeCopying
OnPropertyModificationEnabled
Enables and disables the command – Edit for property modifications.
- Syntax – bool OnPropertyModificationEnabled(nPropertyId)
- Parameters
- nPropertyID – attribute value (in the database) tblProperty.intPropertyId for the property to be edited.
- Return value – if this function returns true, the - Edit command in the menu will be active. Otherwise it will be inactive (grayed out).
- Examples – refer to OnNodeCopying
OnPropertyModifying
This function is called by the - Edit command, before the edited property is saved to the database.
- Syntax - bool OnPropertyModifying(nPropertyId, strNewValue)
- Parameters
- nPropertyId – attribute value (in the database) tblProperty.intPropertyId for the property to be changed.
- strNewValue – new property value.
- Return value – if the function returns true, the new value will be saved to the database. If the function returns false, the action will not be performed. In that case it is usually convenient to display an error message with the MessageBox method.
- Examples – refer to OnNodeCopying
OnPropertyModified
This function is called after a new property values has been saved to the database following the - Edit command.
- Syntax – void OnPropertyModified(nPropertyId)
- Parameters
- nPropertyId – attribute value (in the database) tblProperty.intPropertyId for the property that was changed.
- Return value – none
- Examples – refer to OnNodeCopying
MessageBox
This function displays a window with a text message.
- Syntax – int MessageBox(Text,Type)
- Parameters
- Text – message text.
- Type – this parameter can contain a combination of the following bit values.
- Buttons
Value |
Symbol |
Description |
0 |
MB_OK |
OK |
1 |
MB_OKCANCEL |
OK, Cancel |
2 |
MB_ABORTRETRYIGNORE |
Abort, Retry, Ignore |
3 |
MB_YESNOCANCEL |
Yes, No, Cancel |
4 |
MB_YESNO |
Yes, No |
5 |
MB_RETRYCANCEL |
Retry, Cancel |
- Icons
Value |
Symbol |
Description |
0x10 |
MB_ICONERROR |
error (red) |
0x20 |
MB_ICONQUESTION |
question mark |
0x30 |
MB_ICONEXCLAMATION |
exclamation mark (yellow) |
0x40 |
MB_ICONINFORMATION |
information |
- Default button – the value in the table above specifies, which button, ordered from the left, will be set as default.
Value |
Symbol |
0 |
MB_DEFBUTTON1 |
0x100 |
MB_DEFBUTTON2 |
0x200 |
MB_DEFBUTTON3 |
0x300 |
MB_DEFBUTTON4 |
- Release value
Value |
Symbol |
Description |
1 |
IDOK |
OK |
2 |
IDCANCEL |
Cancel |
3 |
IDABORT |
Cancel |
4 |
IDRETRY |
Retry |
5 |
IDIGNORE |
Ignore |
6 |
IDYES |
Yes |
7 |
IDNO |
No |
- Examples
Example 4. Using the MessageBox function
The following example will display a window with the question "Do you want to continue?" and with the "Yes" and "No" buttons. The "No" button will be active by default.
if ( MessageBox("Do you want to continue?",4+0x20+0x100) == 6 ) // continue ...
ConnectionString
The ConnectionString variable contains a connection string for the database that is currently open. This variable is read-only.
Note: The connection string is compliant to the ADO rules.
Example 5. Using the ConnectionString variable
In the following example, the Con variable contains a connection to the database which is currently open in the Console.
var Con=new ActiveXObject("ADODB.Connection"); Con.Open(ConnectionString);
UserId
The UserId variable includes the user identifier of the user who is currently logged in the Console. This variable is read-only.
The identifier corresponds to the value of the attribute intUserId in the database table tblUser.
Did not find what you were looking for? Ask our technical support team.
|