How can we help?

Search for answers or browse our knowledge base

< All Topics
Print

Automation via PowerShell API

Introduction

Automation via the API does not offer any graphical interface.

It is done with the .NET Calame.Automation.dll assembly.
This assembly is installed with GTAnswer
This assembly is compiled for the 3.5 framework and can be called :

  • from the PowerShell (version 2)
  • from any .NET program
  • from Python

All objects in the assembly are in the Calame.Automation namespace.

Commands are passed to GTServer via classes named CmdXXXX. Two types exist:

  • Action execution commands which are inherited from the CmdExecuteAction class
  • The others are static classes (e.g., CmdDoPolling)

In both cases, the execution is done via the Execute method, whose parameters and return type differ according to the command. This method always has at least one parameter, which is the instance connection information.

The user specified in the connection information will decide which rights are possible on the GTServer objects in the context of the automation.
It is often better to specify the login of an administrator or a developer for the connection.
Thus, he will be able to execute all actions, view all campaigns, etc…

Note :

Each of these commands actually encapsulates several GTServer commands (including login/logout).

Connection information

Connection information is passed via a ConnectionInfo object which contains the following fields:

Connexion

  • Host (string) : name of the instance server
  • Port (string) : the port of the instance
  • SslProtocol (of the System.Security.Authentication.SslProtocols type): SSL protocol (default None)
  • CertificateServerName (string) : server certificate name
  • Login (string) : name of the user connecting to the instance
  • Password (string) : user’s password (<= 3.9 if this field is empty, SHA1Password is used)
  • SHA1Password (string) : SHA1 of the password, used if Password is empty (deprecated in 3.95 and above)

As mentioned before, it is often simpler to connect for automation with an Administrator or Developer login to avoid rights restrictions.

Examples :

  • PowerShell (with SSL)
$connectioninfo = New-Object -typeName Calame.Automation.ConnectionInfo
$connectioninfo.Host = "myserver"
$connectioninfo.Port = 6000
$connectioninfo.Login = "Admin"
$connectioninfo.Password = "MyPassword"
$connectioninfo.SslProtocol = [System.Security.Authentication.SslProtocols]::Tls
$connectioninfo.CertificateServerName = "myserver"
  • C# (without SSL)

Calame.Automation.ConnectionInfo connectioninfo = new Calame.Automation.ConnectionInfo();
connectioninfo.Host = “myserver”;
connectioninfo.Port = 6000;
connectioninfo.Login = “Admin”;
connectioninfo.Password = “MyPassword”;

Action classes

These classes are derived from CmdExecuteAction and execute an action via one of the following two methods:

Calame.Automation.ActionResult Execute(Calame.Automation.ConnectionInfo AInfo, bool AWaitTerminated, int AMaxWaitMin);

// overload for which AWaitTerminated = true and AMaxWaitMin = 60
Calame.Automation.ActionResult Execute(Calame.Automation.ConnectionInfo AInfo);

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • AWaitTerminated (bool) : Boolean indicating if we await the end of the execution of the action
  • AMaxWaitMin (int) : number of minutes to wait

The return type is ActionResult :

Résultat de l'action

The fields are the following:

  • AcsId (long) : action execution identifier
  • ErrCode (int) : GTServer error code
  • ErrMsg (string) : error message
  • HasWarning (bool) : indicates that the execution has produced warnings
  • Status (ActionStatus) : status of the ActionStatus execution which is an enum taking the following values:
NoneDans le cas ou on n’attend pas la fin de l’exécution (AWaitTerminated = false)
WaitTimeOutl’exécution ne s’est par terminée après AMaxWaitMin minutes
WaitErrorla demande de statut de l’exécution a généré une erreur (via une exception EActionException)
Pendingl’exécution est en attente de la fin d’une autre action
InProgressl’exécution est en cours
Terminatedl’exécution est terminée
Error l’exécution est terminée et il y a une erreur (via une exception EActionException)
Preparedl’action a été préparée (non disponible en automatisation)
Diagnostic l’action en mode diagnostique est terminée (non disponible en automatisation)

When an action execution error occurs, an EActionException is triggered. This type of exception contains an ActionResult field whose Status field is Error or WaitError. An ECommandException can also occur (if the login information is not valid). For more details see the paragraph on error handling.

If Status is set to WaitTimeOut, the execution status of the action must be checked again by the CmdGetActionStatus command.

! Note: SQL, integration, combined actions, deletion of the right of reply, creation of users do not use the Message

Examples:

  • PowerShell :
function LaunchMyCampaign
{

$action = New-Object -typeName Calame.Automation.CmdActionCampaignLaunch
$action.Name = "The name of my action"
$action.StatementDate = "2012-03-31
$action.UseCypher = $true
$action.Message = [Calame.Automation.CmdGetMessageFromName]::Execute($connectioninfo, "The template name of my action", "The name of the message");
$action.Message.Subject = "The new subject of the message".
try
{

$result = $action.Execute($connectioninfo, $true, 10)
if ($result.Status -eq [Calame.Automation.ActionStatus]::WaitTimeOut)
{ 
echo "Timeout: $result"
}
return $result
}
catch [Calame.Automation.EActionException]
{
$e = $_.Exception;
Write-Host $e.Message.ToString() -foregroundcolor red -backgroundcolor yellow
return $e.ActionResult 
}
catch [Calame.Automation.ECommandException] 
{
$e = $_.Exception;
Write-Host $e.Message.ToString() -foregroundcolor red -backgroundcolor yellow
return $e.ErrCode
} 
}

Launch Collection Action : CmdActionCampaignLaunch

Fields :

  • Name (string): name of the action
  • Message (Calame.Automation.Message): message, if null use of the first message found.
  • StatementDate (DateTime): statement date, this field is only used if the action does not have a statement date source
  • GlobalRedirectAddress (string): global redirect address
  • UseCypher (bool): encryption of the response (if the instance has a certificate), false by default

Integration action : CmdActionCampaignIntegration

Fields :

  • Name (string): name of the action
  • StatementDate (DateTime): statement date, this field is only used if the action does not have a statement date source

Action for launching the report : CmdActionReportingQst

! Note : GT >= GT 3.7

Fields :

  • Name (string): name of the action
  • Message (Calame.Automation.Message): message, if null use of the first message found.
  • StatementDate (DateTime): statement date, this field is only used if the action does not have a statement date source.
  • GlobalRedirectAddress (string): global redirect address
  • UseCypher (bool): encryption of the response (if the instance has a certificate), false by default

SQL script action : CmdActionSQL

Fields :

  • Name (string): name of the action

Campaign close action : CmdActionCampaignClose

Fields:

  • Name (string): name of the action, not used: the name of the template must be used
  • Message (Calame.Automation.Message): message, if null use of the first message found.
  • StatementDate (DateTime): statement date
  • ModelName (string): name of the template
  • UseDefaultActionSettings (bool): use default action settings
  • DoSendMessage (bool): send the close message (ignored if UseDefaultActionSettings = true)
  • AttachQst (bool): attach the last response or qst sent (ignored if UseDefaultActionSettings = true)
  • AttachPDF (bool): attach the last response as a PDF (ignored if UseDefaultActionSettings = true)
  • AttachHisto (bool): attach history (ignored if UseDefaultActionSettings = true)

Re-send action : CmdActionCampaignFollowup

Fields :

  • Name (string): action name, not used: the name of the template must be used
  • Message (Calame.Automation.Message): message, if null use of the first message found.
  • StatementDate (DateTime): statement date
  • ModelName (string): name of the template
  • UseDefaultActionSettings (bool): use default action settings
  • AttachQst (bool): attach the last response or qst sent (ignored if UseDefaultActionSettings = true)
  • AttachPDF (bool): attach the last response in PDF (ignored if UseDefaultActionSettings = true)
  • AttachHisto (bool): attach history (ignored if UseDefaultActionSettings = true)
  • SelectNoAnswers (boolean): restart unanswered entities
  • SelectPending (bool): restart entities waiting for validation
  • SelectInvalidated (bool): restart invalidated entities
  • SelectEntities (List of AnswerEntity) – to select the relaunch entities (version >= 2019)

Examples :

  • PowerShell :

Relaunch by selecting the entities (version >= 2019)

function RelanceParEnt
{
  $private:datearrete = [DateTime]::Parse("26/09/2018")
  $private:modelname = "Test"
  $private:entities = [Calame.Automation.CmdListAnswer]::Execute($conn, $modelname, $datearrete)
  $private:selected = New-Object 'System.Collections.Generic.List[Calame.Automation.AnswerEntity]'

  foreach ($private:ent in $entities)
  {
    if (($ent["Pays"] -eq "CH") -or ($ent["Pays"] -eq "IT"))
    {
      $selected.Add($ent)
    }
  }

  $private:cmd = New-Object -typeName Calame.Automation.CmdActionCampaignFollowup
  $cmd.ModelName = $modelname
  $cmd.StatementDate = $datearrete
  $cmd.UseDefaultActionSettings = $false
  $cmd.AttachQst = $true
  $cmd.SelectedEntities = $selected
  return $cmd.Execute($conn, $true, 15)
}

Combined action : CmdActionCombined

! Note : GT >= GT 4.0.0

Champs :

  • StatementDate (DateTime): date d’arrêté, ce champ n’est utilisé que si l’action n’a pas de source de date d’arrêté

User creation action : CmdActionCreateMassUser

! Note : GT >= GT 4.0.0

Right answer removal action : CmdActionRemoveAnswerRights

! Note : GT >= GT 4.0.0

Messages

The action classes have a Calame.Automation.Message field. There are two ways to create a message:
  • Directly by calling the constructor and filling in the fields
  • Via the command class CmdGetMessageFromName which returns a message from the template name and the message name (see the example above).

Once we have a message object, we can modify its fields (subject,…)

Messages

Note:

  • The message field for SQL and integration actions is ignored
  • A message created directly by the constructor has no type. On the contrary, the message returned by CmdGetMessageFromName is typed. If this message is passed to an action whose type does not match (for example a launch action with a return message), a generic exception is triggered when the action is executed. The message type is an internal property that cannot be accessed.
  • from GT 3.7: MessageAutoTo.OverrideTo enum value is only available for retry messages. It allows the "To" field to be overridden via the OverrideTo property

Static classes

Message handling : CmdGetMessageFromName

Returns the message from the template name and the message name:

Calame.Automation.Message Execute(Calame.Automation.ConnectionInfo AInfo, string AModelName, string AMessageName)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • AModelName ( string) : name of the template
  • AMessageName ( string) : message name

Polling management : CmdDoPolling, CmdIsPolling and CmdGetPollingLog

Polling request

Polling request via the CmdDoPolling class :

bool Execute(Calame.Automation.ConnectionInfo AInfo, bool AWaitTerminated, int AMaxWaitMin)

Parameters :

  • param AInfo : connection information
  • type AInfo : ConnectionInfo
  • param AWaitTerminated : boolean indicating if we wait for the end of the polling
  • type AWaitTerminated : bool
  • param AMaxWaitMin : number of minutes to wait (if AWaitTerminated is true)
  • type AMaxWaitMin : int
  • rtype : bool

Examples :

  • PowerShell :
$res = [Calame.Automation.CmdDoPolling]::Execute($connectioninfo, $true, 30)
  • C# :
bool res = Calame.Automation.CmdDoPolling.Execute(connectioninfo, true, 30);

Advanced polling request

Polling request with results via the CmdDoPolling class :

Calame.Automation.PollingResult ExecuteEx(Calame.Automation.ConnectionInfo AInfo, bool AWaitTerminated, int AMaxWaitMin)

The parameters are the same as for the previous method:

  • AInfo (ConnectionInfo) : connection information
  • AWaitTerminated (bool) : boolean indicating if we wait for the end of the polling
  • AMaxWaitMin (int) : number of minutes to wait (if AWaitTerminated is true)

The result is an object of type PollingResult :

Objet PollingResult

Polling in progress

To know if a polling is in progress we use the CmdIsPolling class :

bool Execute(Calame.Automation.ConnectionInfo AInfo)

Polling log

The CmdGetPollingLog command returns the polling log:

string Execute(Calame.Automation.ConnectionInfo AInfo, long APollId)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • APollId (long) : value of the PollId field of the object returned by CmdDoPolling.ExecuteEx
  • rtype : string

PowerShell example :

$res = [Calame.Automation.CmdDoPolling]::ExecuteEx($connectioninfo, $true, 30)
$log = [Calame.Automation.CmdGetPollingLog]::Execute($connectioninfo, $res.PollId)

Action management : CmdGetActionStatus and CmdGetActionLog

The CmdGetActionStatus class returns the same ActionResult as the execution of an action via the AcsId field:

Calame.Automation.ActionResult Execute(Calame.Automation.ConnectionInfo AInfo, long AAcsId)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • AAcsId : action execution identifier

The CmdGetActionLog class returns the portion of the instance logs corresponding to the execution of the action.

string Execute(Calame.Automation.ConnectionInfo AInfo, long AAcsId)

The parameters are the same as for CmdGetActionStatus. The returned log is a string containing XML.

Important: if the action has generated an error, the returned log does not contain it (but it is present in the instance log files). It is accessible via the ActionResult of the execution command or CmdGetActionStatus.

Campaign management : CmdDeleteCampaign and CmdListCampaign

CmdDeleteCampaign: Deleting a campaign

The CmdDeleteCampaign class is used to delete a closed campaign:

void Execute(Calame.Automation.ConnectionInfo AInfo, string AModelName, DateTime AStatementDate, bool ADeleteHisto)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • AModelName: campaign template name
  • AStatementDate: Statement date of the campaign
  • ADeleteHisto : true to delete the history of this campaign

The function returns nothing. If an error occurs, it will be via an ECommandException exception.

Example:

  • PowerShell :
[CmdDeleteCampaign]::Execute($connectioninfo, "MyPattern", [DateTime]::Parse("2014-02-29"), $true)
CmdListCampaign: list of campaigns

The CmdListCampaign class returns the list of campaigns:

List Execute(Calame.Automation.ConnectionInfo AInfo)

The Campaign class is defined as follows:

Classe Campaign

Example :

  • PowerShell

This function displays the list of closed campaigns. Note the syntax with + to access a nested type.

function ListCampaignsClosed
{
$list = [Calame.Automation.CmdListCampaign]::Execute($connectioninfo)
foreach ($camp in $list)
{
if ($camp.Status -eq [Calame.Automation.Campaign+CampStatus]::Closed)
{
echo $camp
}
}
}

Response and Questionnaire Management

Last response date : CmdLastAnswerDateForCampaign

! Note: For GT >= 3.1 build 1862

The CmdLastAnswerDateForCampaign command returns the date the correspondent sent the last response received by GTServer.

This command must be executed if you wish to monitor the arrival of new responses and trigger certain actions (integration, restitution, etc.) according to these new responses.
The triggering of these additional actions must be subject to the actual arrival of a new response in order to avoid executing these actions too frequently.

DateTime Execute(Calame.Automation.ConnectionInfo AInfo, string AModelName, DateTime AStatementDate)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • AModelName (string) : campaign template name
  • AStatementDate (DateTime) : Statement date of the campaign

Example (PowerShell):

[CmdLastAnswerDateForCampaign]::Execute($connectioninfo, "Template", [DateTime]::Parse("2014-02-29"))
List of responses : CmdListAnswer

! Note: For GT >= 3.9

The CmdListAnswer command returns a list of responses (by entity) for a campaign.

AnswerEntities Execute(Calame.Automation.ConnectionInfo AInfo, string AModelName, DateTime AStatementDate)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • AModelName (string) : campaign template name
  • AStatementDate (DateTime) : Statement date of the campaign

The returned object of type AnswerEntities describes the responses of the campaign by entities:

AnswerEntities

C# example

// Retrieve the list
AnswerEntities entities = CmdListAnswer.Execute(info, "Test", DateTime.Parse("07/02/2012"));

// Display diffusion axes + additional validation axes + visualisations axis
// Here we have two diffusion axes: Country and City
foreach (AnswerEntities.Axis axis in entities.ValidationAxes)
{
Console.WriteLine("Axis: {0}, Usage: {1}, Type .NET: {2}", axis.Name, axis.Usage, axis.DataType);
}

// for each entity
foreach (AnswerEntity ent in entities)
{
Console.WriteLine("===========================");
// Display the entity, here we have two diffusion axes: Country and City
Console.WriteLine("Country: {0} City: {1}", ent["Country"], ent["City"]);

// Number of responses
Console.WriteLine("Number of answers: {0}", ent.Answers.Count);

// Sort the answers by ascending date of sending
ent.Answers.Sort(
delegate (Answer left, Answer right)
{
return DateTime.Compare(left.DateAnswerSent, right.DateAnswerSent);
});

// For each answer, display the status in the order it was sent
// And the Region visualisation axis
for (int i = 0; i < ent.Answers.Count; i++)
{
Answer a = ent.Answers[i];
Console.WriteLine("Answer #{0} of Id {1} sent on {2}, status: {3}", 
i + 1, a.AnwserId, a.DateAnswerSent, a.ValidationStatus);
object visu = a.GetVisualizationAxisValue("Region");
if (visu != null)
Console.WriteLine("Visualization axis Region {0}", visu);

}

// Last answer or validated
Answer ans = ent.GetLastOrValidated();

if (ans != null)
{
Console.WriteLine("The Id of the last answer is {0}", ans.AnwserId);
}
else
{
Console.WriteLine("No response");
}
}
Getting the Questionnaire from an Answer : CmdGetAnswer

! Note : GT >= 3.5

Allows you to retrieve a response.

The CmdGetAnswer command writes the questionnaire (.qst file) of an answer to disk.

bool Execute(Calame.Automation.ConnectionInfo AInfo, string ADestinationFileName, long AAnswerId, bool AForAnswer=false)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • ADestinationFileName (string) : Name of the destination file to save the response
  • AAnswerId (long) : Id of the response (AnswerId field for an object of the Answer class obtained from CmdListAnswer.Execute)
  • AForAnswer (bool) : if this parameter is true, the qst file corresponding to the sent answer is functional: a new answer can be transmitted by opening this questionnaire in Answer. Otherwise, the sending of the answer is blocked. This parameter depends on the “Open a response with Answer” right.
Getting a Sent Questionnaire : CmdGetQstSent
! Note : GT >= 3.7
Allows you to retrieve a sent questionnaire.

The CmdGetQstSent command writes a sent questionnaire (.qst file) to disk.

bool Execute(Calame.Automation.ConnectionInfo AInfo, string ADestinationFileName, long AQstSentId, bool AForAnswer=false)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • ADestinationFileName (string) : name of the destination file to save the answer
  • AQstSentId (long) : Id of the sent qst ( QstSentId field for an object of the Answer class or the QstSent class obtained from CmdListAnswer.Execute)
  • AForAnswer (bool) : if this parameter is true, the qst file corresponding to the sent questionnaire is functional: a response can be transmitted by opening this questionnaire in Answer. Otherwise, the sending of the response is blocked. This parameter depends on the right “Open a questionnaire sent with Answer”.
Closing a questionnaire : CmdCloseQst

Permits the closing of a sent questionnaire by refusing past and future responses or only future responses.

void Execute(ConnectionInfo AInfo, long AQstId, bool APastAndFuture)

Parameters:

  • AInfo (ConnectionInfo) : connection information
  • AQstId ( long) : Id of the qst ( QstSentId field for an object of the Answer class or the QstSent class).
  • APastAndFuture (bool) : Boolean indicating if past responses are also deleted
Deleting a response : CmdDeleteAnwser

Allows to delete a specific response according to its identifier (obtained by the AnswerId field of the Answer class).

The deletion of responses is irreversible.

void Execute(ConnectionInfo AInfo, long AAnswerId)

Parameters :

  • AInfo (ConnectionInfo) : connection information
  • AAnswerId ( long) : response Id (AnswerId field for an object of the Answer class).

Managing models

! Note : GT >= GT 4.0.0

All parameters are set by the GtModel class (including the rights):

  • Id (long) – model Id
  • Name (string) – model name
  • Description (string) – model description
  • Type (ModelType) – model type
List models : CmdListModel

The CmdListModel command list all models :

list Execute(Calame.Automation.ConnectionInfo AInfo)

Parameters

  • AInfo (ConnectionInfo) – connexion informations
Returns
  • users list
  • Returned type:List of GtModel

Managing  projects

! Note : GT >= GT 4.0.0

All parameters are set by the GtProject class (including the rights):

  • Id (long) – project Id
  • Name (string) –  project name
  • Description (string) – project description
  • PublicationsCount (int) – number of project publications
  • ModelCount (int) – number of project models
  • ActionCount (int) – number of project actions
List projects : CmdListProject

The CmdListProject command list all models :

list Execute(Calame.Automation.ConnectionInfo AInfo)

Parameters

  • AInfo (ConnectionInfo) – connexion informations
Returns
  • users list
  • Returned type:List of GtProject

User management

Creation of new users and assignment of rights for these new users

The CmdInsertUser command allows to insert a new user:

void Execute(Calame.Automation.ConnectionInfo AInfo, Calame.Automation.NewUser AUser)

All parameters are set by the NewUser class (including the rights):

Classe NewUser

C# example

// creation of the object
NewUser user = new NewUser();

// Login/Password
user.Login = "New_User";
user.Password = "password";

// Privilege
user.Privilege = NewUser.UserPrivilege.None;

// rights on templates via a list of pairs (Template, Group)
// NB: here, the user is part of two groups for "Modele2"
user.Rights = new List();
user.Rights.Add(new NewUser.ModelGroupCouple("Modele1", "Manager"));
user.Rights.Add(new NewUser.ModelGroupCouple("Modele2", "Viewer"));
user.Rights.Add(new NewUser.ModelGroupCouple("Modele2", "Validator"));

// call the command
CmdInsertUser.Execute(info, user);
Checking the password: CmdCheckPassword

The CmdCheckPassword command allows to check the validity of a password against the constraints configured at the instance level (see GtAdmin).

void Execute(ConnectionInfo AInfo, string APwd)

Parameters :

  • AInfo : connection information
  • APwd : Password whose validity must be checked
Editing users

The CmdEditUser command allows to modify the information of a user.

void Execute(ConnectionInfo AInfo, User AUser)

The User object passed in parameter must contain a valid Id, this Id can be obtained thanks to the CmdListUser command.

Deleting users

The CmdDeleteUser command allows to delete a user from the database.

void Execute(ConnectionInfo AInfo, int AUserId)

The Id of the user can be obtained using the CmdListUser command.

List of users

The CmdListUser command returns the list of users of the instance.

List Execute(ConnectionInfo AInfo)

Error management

Error management is done via exceptions which are derived from EAutomationException :

Classe EAutomationException

The error code (ErrCode field) of the exception is the GTServer error code (the same as the one displayed by GTAnswer). ErrMsg contains the error message. ECommandException are raised for static commands.

An EActionException is triggered during the execution of an action if the action was able to start. Otherwise, an action execution can raise an ECommandException because it encapsulates among others the logon command to GTServer.

Other .NET framework exceptions can also be raised, notably System.Net.Sockets.SocketException for communication errors with the server (for example, if it is not started).

The following C# code is a template for executing an action passed as a parameter (as a reminder, action classes derived from CmdExecuteAction):

// returns true if no error, otherwise ErrMsg contains the error message
bool ExecuteAction(ConnectionInfo AInfo, CmdExecuteAction AAction, out string ErrMsg)
{
ErrMsg = "";
try
{
ActionResult resAction = AAction.Execute(AInfo, true, 60);
// do whatever we want with resAction
return true;
}
catch (ECommandException ECmd)
{
ErrMsg = String.Format("Error while executing a command:\nCode: {0}\nMessage: {1}", 
ECmd.ErrCode, 
ECmd.Message);
return false;
}
catch (EActionException EAct)
{
ErrMsg = String.Format("Error while executing action {0}:\nCode: {1}:\nMessage: {2}",
AAction.Name,
EAct.ErrCode,
EAct.Message);
return false;
}
catch (System.Net.Sockets.SocketException ES)
{
ErrMsg = String.Format("Server communication error:\nType: {0}\nMessage: {1}",
ES.GetType(),
ES.Message);
return false;
}
catch (Exception E)
{
ErrMsg = String.Format("Other error:\nType: {0}\nMessage: {1}",
E.GetType(),
E.Message);
return false;
}
}

NB: a Powershell script must include the following command so that errors can be intercepted when the script is executed

$ErrorActionPreference = "Stop"

This command can also be present in the user’s profile script.

This command should be added at the very beginning of the script.

Securing login information

Using a Powershell script will leave the connection information to GTServer or to the database (if the script has to connect to the database) in clear text.

The script should be run on a restricted machine.
If the fact that the connection information (to GTServer or the database) is not acceptable for the security policy of the infrastructure, then it is preferable to use for example a .NET assembly that will read or write the connection/configuration information in a text file in an encrypted form.

Multiple requests to execute actions or polling

GTServer never simultaneously executes a polling and/or any action (qst launch or restitution or qst-based restitution, campaign integration, SQL action).

If a polling is requested while an action or another polling is being executed, the polling request will be rejected.

Each time a new action is requested, regardless of the source of the request (automation or any user), a thread is created on the server waiting for a specific mutex to be available on the server.
When the action being processed finishes, the semaphore is released and the Windows system on the server launches one of the threads currently waiting for the mutex.

It is therefore advisable in the context of automation :

  • always wait for the end of the execution of the action that has been requested by the script or assembly. If the ActionResult has the WaitTimeOut status, the execution status can be queried again via CmdGetActionStatus after a waiting time.
  • to reiterate the polling request some time later if it was rejected.
  • to execute the automation scripts outside the usual time slots used by the managers/validators, to avoid the influx of requests to the server.
  • to regularly clean the mailbox associated with GTServer to avoid a too long polling time (by preserving Answer’s response mails), to check the connection times of GTServer’s reception to the mail server, or even to switch to http response (and delete the mail polling configuration) to reduce polling times.

Finally, it is strongly recommended to take the precaution of executing the integration action only when new responses have been received by GTServer, when integration actions are executed at short intervals (less than two hours).

More generally, it is strongly recommended to execute actions (campaign launch, integration, sending of feedback) only when necessary: new responses, new data in the database, status change, etc… If these conditions are not respected, an optimal functioning of GTServer cannot be guaranteed.

Therefore, the operations to be implemented are generally the following:

  • Request for a polling
  • Extraction of the last response date for the campaign
  • Comparison of this date with the last response date integrated in the database. This last operation requires direct access (via ODBC/OleDb) or indirect access (via file production and reading) to the Client database.
  • Execution of the integration action if a new response has arrived
  • Execution of one or more additional operations as required

Loading the automation assembly with a Powershell script

Loading the Calame automation assembly is done simply through the static Reflection.Assembly.LoadFrom method or one of its derivatives.

[void] [system.reflection.assembly]::loadfrom("C:\Program Files (x86)\CalameCalame.Automation.dll")

This command should be added at the very beginning of the script.

Authorisation to run Powershell scripts

By default Powershell scripts are not allowed to run.

You can check this by using the following command from the command line prompt via the console.

powershell Get-ExecutionPolicy

You can allow all Powershell scripts to be executed by using the following command from the command line prompt as an administrator. However, it is preferable to fine-tune the execution permission to certain scripts only.

powershell Set-ExecutionPolicy Unrestricted

You can also allow one-time execution of a powershell script via the following command row
powershell -ExecutionPolicy Bypass -File

The following powershell execution command line arguments may be of interest
-NoLogo -NonInteractive

See Microsoft’s Powershell Help for more information

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
How Can We Improve This Article?
Table of Contents