Skip Navigation LinksALVAO 7.1ALVAO Asset ManagementSystem Implementation in an OrganizationSettingsUser-Defined Script Skip Navigation Links. Skip Navigation Links Skip Navigation Links.


User-Defined Script

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 different operations.

Example 1. Example of file EpCustomScript.js

function OnNodeMoving(nNodeId,nDestNodeId,nUserId)
{
    return true;
}

function OnNodeRemoving(nNodeId,nUserId)
{
    MessageBox("The object cannot be removed",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

Functions Event
OnNodeCopying Creates a copy of an object. This function is also called if a new object is created based on a template.
OnNodeCopied An object has been copied or a new object has been created based on a template.
OnNodeMoving An object will be moved within the tree.
OnNodeMoved An object has been moved.
OnNodeRemoving An object will be moved to the Recycle Bin or deleted from the tree completely.
OnNodeRemoved An object has been moved to the Recycle Bin or deleted from the tree completely.
OnPropertyModificationEnabled Enable/Disable command - Edit (property).
OnPropertyModifying The property value will been changed.
OnPropertyModified The property value has been changed.

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 sub-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.

Release value

If the function returns 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 not allowed.",0x30);
        return false;
    }
    return true;
}

Example 3. Example – Calling a stored procedure from an SQL Server

The following example uses a stored procedure spOnNodeCopying on the SQL Server for the evaluation. Object copying is allowed, 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("Cannot copy object.",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 copied object, 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.

Release value

none

Examples

see 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.

Release 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

see 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 moved object.

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.

Release value

none

Examples

see 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.

Release 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

see 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 has been 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.

Release value

none

Examples

see OnNodeCopying

OnPropertyModificationEnabled

Enables and disables the command – Edit for property modifications.

Syntax

bool OnNodeModificationEnabled(nPropertyId)

Parameters
nPropertyId

Attribute value (in the database) tblProperty.intPropertyId for the property to be edited.

Release value

If this function returns true, the - Edit command in the menu will be active. Otherwise it will be inactive (greyed out).

Examples

see 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.

Release 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

see 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 has been changed.

Release value

none

Examples

see OnNodeCopying

MessageBox

This function displays a window with a text message.

Syntax

int MessageBox(Text,Type)

Parameters
Text

Message body.

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 values from the table above specify, 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.