Scripting

<< Click to Display Table of Contents >>

Navigation:  General questions >

Scripting

 

Questions and answers about OMNITRACKER ↦ General questions ↦ Scripting:

 

How to handle Error in WRP_ConfigurationMapping at line 350, char 2: Unknown drop down value '56' (IOtUserField)

Initial situation:

The Global Script WRP_ConfigurationMapping

$INCLUDE 'WRP_ConfigurationMapping'
Call main()

shall be started to get to a Configuration Update of the structure of all request folders and their fields. The result is copied into the folder "Configuration" in the OMNITRACKER folder tree:

14. Output to Word\ 03. Settings\ 01. OT Configuration\ 01. Field Definitions (and 02. Folder Definitions)

The scripts ends with this error: Error in WRP_ConfigurationMapping at line 350, char 2: Unknown drop down value '56' (IOtUserField)

The solution:

Open the folder definition of folder 01. Field Definitions and add a new value to field "Type":

Value: otUfImage
Alias: 56
Description: Image field

 

How to create a link to the current object to be offered for access by web client?

A single link to an object to be accessed with web client has to look like:

http://<hostname>/<virtualroot>Login.aspx?id=<id>&singleton=<singleton>[&guestlogin_id=<gid>][&lang=<xx>]

Please refer to OMNITRACKER Web Gateway Help, chapter Navigation: Using the Web Gateway > Login > URLs for detailed information.

The UniqueId of the object has to be used -> ActiveRequest.UniqueId to get to the single object. To offer this single link in a message template this has to be done by inline-scripting:

http://MyOT-Server/OTWG/Login.aspx?id=<%%Output ActiveRequest.UniqueId %%>&singleton=1

 

How to handle Runtime error: ActiveX Component Can't Create Object: "OtAut.OtApplication" in Windows 7 system?

You are using the Windows 7 64-bit Edition. OtAut.dll is a 32bit-application, whereas Windows 7 uses the 64bit-ScriptEngine. So you have to use C:\Windows\SysWOW64\cscript.exe (32bit) instead of C:\Windows\System32\cscript.exe" (64bit).

 

How to handle runtime error: Invalid procedure call or argument: "Left" (or "Right" respectively)?

In OMNITRACKER Service Control Panel, please go to "File" > "Special Configuration Parameters..." and choose the button "Add Parameter".

Create a new integer value with name:

FullTextSearch\DebugLog
Value: 2.

Then restart the OtIndex service. Now you will find the file index_<datum>.log and the file with the name C:\Temp\dtsearch.log (= logfile of the der dtSearch Engine) in the Logging directory .

Possible Values:

  • "0" – Do not generate debug information
  • "1" - Generate a trace log of the OtIndex process in the file "index_.log" in the OMNITRACKER server log directory (or in C:\Temp if no directory has been defined).
  • "2" – Instruct the dtSearch Engine to generate a log file with the name C:\Temp\dtsearch.log. This log file might be requested by the dtSearch Support team when we report a problem to them.
  • "3" – For each document that is indexed, store an *.XML file in the OMNITRACKER server log directory (or in C:\Temp if no directory has been defined).
Level 2 includes the actions for level 1.
Level 3 includes the actions for level 1 and 2.

 

How to expand the name of a page to indicate number of elements in this tab dynamically?

Add the following lines to an OnOpen Script of the form:

TabControl.Pages(7).Name = TabControl.Pages(7).Name & " (" & _ActiveRequest.Fields("Comments").TValue.Count & ")"
TabControl.Pages(8).Name = TabControl.Pages(8).Name & " (" & _ActiveRequest.Fields("Attachments").TValue.Count & ")"

"7" and "8" is the position of the zero-based index of the tab page. Please see OMNITRACKER Form Editor > Scripting Reference > Button control > Properties > Name Property.

 

What are the differences between OMNINET Scripting Engine and MS Scripting Engine?

If released with version 10.1.100 OMNITRACKER will use a new scripting engine. Please view the documentation for more details.

Our aim is to provide a Scripting Engine that behaves 100% like the original Microsoft Engine.

During a transitional phase, the old scripting engine can be reactivated with the special configuration parameter „UseOldScriptingEngine“ = 0 (Integer). However, there are some very minuscule differences (that should not invalidate the above statement for practical purposes):

  • Line numbers start at "1“ instead of "0“ both in the new engine and the script editor. There is 1 line displacement if the new script editor is used in conjunction with the original Microsoft Engine as this Engine uses zero-base line numbers.
  • Syntax Errors might be different (e.g. might contain additional information). Runtime Error Codes remain the same.
  • Random Number Generator: We use a different random number generator, so the series of pseudo random numbers will be different as well.
  • The call stack of the new engine can be ten times deeper than the call stack in the original Microsoft Engine.

OMNINET Scripting Engine:

The implementation was done by OMNINET. Default was the specification of the behavior of Microsoft and Microsoft engine. There, where the Microsoft engine should have been 'buggy' (particularly deviates from the specification), we have reproduced the bugs 1:1. Any difference (except those shown in the release notes) would be a defect in the behavior of the new engine.

The implementation was necessary because

  • Support Microsoft
  • New editor (10.1)
  • Profiling Tool (10.2)
  • Debugger (10.4)
  • Scripting the Web (10.x, 11.x)
  • Scripts are not interpreted, but (pre-)compiled.

 

How to limit memory consumption when using "for each" in VBScripts on OtRequests collections?

When using a "For Each loop", the script will cache the data for each object until the loop ends. So you may run into memory problems, when using a "For Each loop" on a large collection of objects.

But there is an easy workaround:

use:

For i = 0 To reqs.count -1
Set req= reqs(i)
'... do your stuff, here
Next

instead.

A For - Next loop frees its memory after each object.

 

How to set a value of a dropdown field independent of the used client language?

Please work with the Alias of the value that is defined in the field definition of the drop down field.

Example:

given a field of type Drop-Down that has alias = RequestType;
given a DropDown value that has alias = StandardRequest

The code lines should look like:

Set objReq = ActiveSession.GetRequestByUniqueId(ActiveRequest.UniqueId)
objReq.Fields("RequestType").TValue.Alias = "StandardRequest"
objReq.Save

 

What are the three golden rules of action- and form-scripting?

Rule 1:

In After Creation/Modification Action – Scripts load a copy of the ActiveRequest and do modifications on the copied object.

Example

Set objReq = ActiveSession.GetRequestByUniqueId(ActiveRequest.UniqueId) ' creates a local copy
objReq.UserFields("Title").Value = "Modification Script 1"
objReq.Save ' writes back the changes to the database

Rule 2:

In Before Creation/Modification Action –Scripts you can access the ActiveRequest object both reading and writing. The changes you make to the object during the script will be discarded unless you call the function UseModifiedRequest at any place of the script. Calling UseModifiedRequest has another effect: After the saving is complete, the Form Window will be updated.

In client-side scripting in forms (OnOpen, OnChange, OnAfterFieldChanged, ...) never use ActiveRequest.Save or ActiveRequest.SaveEx, because otherwise parts of the object form handling will be skipped. This may lead to unpredictable effects. Use the client-side function Save instead.

In server-side scripting (rule 1) always use objReq.Save/Ex:

Set objReq = ActiveSession.GetRequestByUniqueId(ActiveRequest.UniqueId)
objReq.Save / bzw. objReq.SaveEx ...

For more information see also topic ActiveRequest Property and Action Lists in the OMNITRACKER Automation Interface Help.

 

Why does my filter definition look different from what I have saved?

After having saved a filter definition, OMNITRACKER automatically simplifies the filter conditions. Unnecessary brackets will be removed. OMNITRACKER follows the normal rules for arithmetic operations.

Example: A OR (B AND C) is the same as A OR B AND C.

 

Why is sorting by column "<name of object>" not supported?

The <name of object> is not saved as a field in a table of the database. It is built during the runtime with the rules defined in the naming scheme. Due to this, a modification of the name of an existing object is easily done, but sorting is not possible.

Alternatively, add the corresponding columns of the referenced objects used in the naming scheme and sort by multiple columns.

 

How to control a view and/or a filter in a select object window?

If you want to have a certain view to be used in a select object window, you have to define a Standard View with View Condition: view context = 255.

Please see OMNITRACKER Administrator Guide for more information : Navigation: User Interface > Views > The View Context.

Please be aware of the following:

If there is a Restriction Filter defined in the field definition of the field (type: Reference to Object) then the view will be controlled by this restriciton filter. If the flag "Only use restriction Filter for selecting Objects" is checked then initially all objects are listed in the selection window, that fullfill the restriction: <user defined> will be displayed then. In this case the user individually is able to change the filter.

See OMNITRACKER Administrator Guide: Navigation: User Interface > Fields > Field Types > Reference >>> Restrictions.

 

How to insert a link to the current object in the message template for the Web client?

A direct link to an object via Web-client looks as follows:

http://<hostname>/<virtualroot>/Login.aspx?id=<id>&singleton=<singleton>[&guestlogin_id=<gid>][&lang=<xx>]

For more details, please refer to the WebGW Help (Start -> All Programs -> OmniTracker -> Documentation -> ...)

The ID of the object must be added in the message template via inline script. In the message template, this would look like this:

http://MyOT-Server/OTWG/Login.aspx?id=<%%Output ActiveRequest.UniqueId %%>&singleton=1

 

How can the following runtime error in Microsoft VBScript be fixed? "ActiveX components cannot create an object: 'OtAut.OtApplication' in Windows 7"?

OtAut.dll is 32-bit, whereas Windows7 uses the 64-bit ScriptEngine by default. Please use C:\Windows\SysWOW64\cscript.exe (32bit) instead of C:\Windows\System32\cscript.exe (64bit).

 

How to hide a specific page of a TabControl control?

Add the following code lines in an OnOpen script of the form:

TabControl.Pages(2).Hidden = True

Note: the index starts at "0", so "2" is the third tab on the form. Please also see OMNITRACKER Form Editor > Scripting Reference > Page object > Properties > Hidden Property for more information.

 

OTClientAut.InvokeAction: What does error code: 0x8001010D signify when running a VBA-script?

The error code 0x8001010D stands for "An outgoing call cannot be made since the application is dispatching an input-synchronous call".

The call of InvokeAction() leads to a communication between the COM-object of OtClient.OTClientAut and the OMNITRACKER client. Windows does not allow an external COM-object to be created during the synchronous processing of a Windows communication. With an Excel import, however, exactly this is the case: The OMNITRACKER client receives the call, executes the global, client-side script and returns the result. If now an additional COM-object in this client-side script is not created within the DLL but as an independent application, the error code: 0x8001010D is provoked.

Suggestions for alternative solutions can be found in the OMNITRACKER Automation Interface Help: Navigation: Getting Started > Visual Basic for Applications (VBA) > Example: Visual Basic for Applications (VBA).

 

How to implement an error handling in VB-Script?

VB-Script basically offers two different On Error statements:

  • On Error {Goto 0|Resume Next}
  • On Error Goto xyz is NOT supported by VB-Script

Example:

On Error Resume Next ' -> trigger error handling
[get error number and corresponding error handling in an if or case statement related to Err.Number, get information about error message by using Err.Description & Err.Source]
[reset error by using Err.Clear]
[continue with the script]
On Error Goto 0 ' -> stop error handling

If you do not want to code the error handling within the script, you can also do this by a subroutine HandleErrorInfo, for instance:

On Error Resume Next
[statement with error]
If Err.Number = 0 Then
[go on]
Else
HandleErrorInfo
End If

Sub HandleErrorInfo
WScript.Echo Err.Number
[Error Handling]
Err.Clear
End Sub

 

How to add an image into a form via scripting?

To do this, please execute a command as follows on a static control:

StaticControl.Picture = LoadPicture("C:\Temp\mypicture.jpg)

 

OtAut: Is it possible to use several OtSession objects in a thread?

No, it is not possible. Only one OtSession object per thread can be used. Furthermore, it is not possible to use one single OtSession object in several threads or to asynchronously call a method of an OtSession object and call another method of this OtSession object within a single thread.

 

How to handle time-scheduled tasks?

When executing automatic operations using the Schedule data type, the following procedure is recommended:

  • Create a new Scheduled Tasks folder.
  • Only two fields are required: Title (Text) and Schedule
  • In the field definition of the field Schedule, implement a script that checks the title of the ActiveRequest (i.e. the task) in a Select Case statement and then executes the corresponding actions.

Define several tasks in the new Scheduled Tasks folder. Each task is displayed as an object in this folder. These tasks have a title, for example "Export FolderX to Access" or "Recreate Index". All these tasks use the same script that is defined in the field definition of the Schedule field. However, since each task is supposed to do different things, the task title must be checked in the script in order to then perform the corresponding actions.

The schedule script for all actions will look something like this:

Select Case ActiveRequest.Fields("Title").Value
Case "Export FolderX to Access"
Set fld = ActiveSession.RequestFolders("FolderX")
'here follow actions in FolderX
Case "Recreate Index"
ActiveSession.GetIndex().RecreateIndex()
Case Else
LogMessage "No valid title --> " & ActiveRequest.Fields("Title").Value
End Select

Further help can be found in the Online Administrator Help under "Schedule".

 

External Script: How to send reports without affecting the OMNITRACKER Server?

A server-side script starts an external VB-script and is terminated immediately after the start. The external VB-script opens a session on the OMNITRACKER server (via MakeSessionEx) and generates the report task via OtTask.Execute. This way, a regular client application is "simulated" without affecting the server. In case of an error, this affects only the client application and not the server environment.

The following is an example of how the scripts are constructed:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("C:\myexternalscript.vbs")

und das externe VB-Skript: (C:\myexternalscript.vbs)

Set objApp = CreateObject("OtAut.OtApplication")
Set objSess = objApp.MakeSession("MyOT-Server.com", 5085, "DailyReportUser", "Password")

' Task "daily report incidents"
Set objFso = CreateObject("Scripting.FileSystemObject")
strTmpName = objFso.GetTempName + ".xls"

Set objFld = objSess.RequestFolders("Incidents")
Set objTask = objFld.Tasks("daily report incidents")
objTask.Execute objFld.CreateRequestList, strTmpName, 3

' Mail to group "Recipients daily incident report"
Set recipients = objSess.CreateEmailAddresses
recipients.AddUserOrGroup objSess.Groups("Recipients daily incident report"), 1

Set attachments = objSess.CreateEmailAttachments
attachments.AddFile strTmpName, "DailyIncidentReport.xls"

objSess.SendEmailToMultipleRecipients recipients, "Daily Incident Report", _ "Attachment: Daily Incident Report.", attachments

objFso.DeleteFile strTmpName

 

How to dynamically add the number of elements on a form on behalf of the tab?

Complete the ff. code lines in an OnOpen (OnChange) script of the form:

TabControl.Pages(7).Name = TabControl.Pages(7).Name & " (" & _ ActiveRequest.Fields("Comments").TValue.Count & ")" TabControl.Pages(8).Name = TabControl.Pages(8).Name & " (" & _ ActiveRequest.Fields("Attachments").TValue.Count & ")"

Note: The index starts at "0", so "7" is the eighth tab on the form. For further information see also OMNITRACKER Form Editor > Scripting Reference > Button control > Properties > Name Property.