Skip to main content
InSource Solutions

TN MES101 MES Client Control - Managing Client Sessions Example

insource logo large.jpg



The following code example can be used to keep the MES Client Control session in synch with the current owning object of an Archestra Graphic hosting the MES Client control.  In the example below the owning object reference is made to an InTouch tag "ActiveLine" that corresponds to the object name that hosts the Achestra Graphic.  To make this script work, replace the InTouch:ActiveLine.Value reference with a string value for hosting object name. 


  • Author: Michael Walker
  • Published: 04/20/2015
  • Applies to:
    • System Platform 2014 R2 (Application Server and InTouch)
    • ​MES 2014​




The code below performs four major  functions:


  1. Sets the owning object.
  2. Gets the client session of the MES Client Controls.
  3. Logs off all Entities
  4. Performs logon to new entity.


A few notes:


  1. The embedded MES control has auto-logon enabled.
  2. OEE.OwningObject is used because the embedded Archestra Symbol element name is "OEE".  This will most likely need to be replaced on another system.


Here is a screenshot of the code:





OEE.OwningObject = InTouch:ActiveLine.Value;



dim oResult as aaFactMES.Result;

dim oClientSession as aaFactMES.aaClientSession;

dim oEnt as aaFactMES.aaEnt;

dim sEntity as string;

dim iEntityID as integer;


'Set current Entity from InTouch

sEntity = InTouch:ActiveLine.Value;


'Get Client Session

oResult = aaFactMES.aaClientSession.GetInstance();


if (oResult.Success == false) then

LogMessage("WARNING -:- unable to get Client Session" );


oClientSession = oResult.Value;


'Logoff Entities if needed

if ( oClientSession <> null ) then

              if ( oClientSession.curUser <> null) then

                    oResult = oClientSession.curUser.LogoffEnt( -1 );

            if ( oResult.Success == true ) then

                                  LogMessage("INFO -:- " + oClientSession.curUser.userName + " has logged off all entities" );


                                  LogMessage("WARNING -:- " + oClientSession.curUser.userName + " logon attempt failed");





'Get entity ID and logon

if (oClientSession <> null and sEntity <> "") then

oResult= aaFactMES.aaEnt.EntIdFromName(sEntity.ToString());

iEntityID = oResult.Value;

oResult = oClientSession.curUser.LogonEnt(iEntityID, "", 100.0);

if (oResult.Success == true) then

LogMessage("INFO -:- " + "logon success for user:" +  oClientSession.curUser.userName + " entity:" + oClientSession.curUser.curEnt.EntName.ToString());