Setting adTempus Variables

GuyS (28 posts)
July 28, 2017 08:58 AM
Accepted Answer

Hello World,

 

I'm trying to update adTempus variables using ArticleID: K00000379. 

Let's start with asking, is this the right way?

Purpose:

Read a file like:

XYEAR=2017

XMONTH=07

and create/update the adTempus variable permantly for a specified Group.

I created a new Script Library named 'SetVariables' like described.

When I create a Script, also as described, I get the following errors:

Message Number: ADT005066WMessage: Script compilation error: Namespace or type specified in the Imports 'ArcanaDevelopment.adTempus.Client' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. (BC40056) (Line 2, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'Scheduler' is not defined. (BC30002) (Line 16, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobVariable' is not defined. (BC30002) (Line 17, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobGroup' is not defined. (BC30002) (Line 18, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: 'ClassIDEnum' is not declared. It may be inaccessible due to its protection level. (BC30451) (Line 34, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobVariable' is not defined. (BC30002) (Line 34, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'Scheduler' is not defined. (BC30002) (Line 46, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobGroup' is not defined. (BC30002) (Line 46, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobGroup' is not defined. (BC30002) (Line 59, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobGroup' is not defined. (BC30002) (Line 60, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobGroup' is not defined. (BC30002) (Line 65, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobGroup' is not defined. (BC30002) (Line 65, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobGroup' is not defined. (BC30002) (Line 70, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobVariables' is not defined. (BC30002) (Line 79, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobVariable' is not defined. (BC30002) (Line 79, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobVariable' is not defined. (BC30002) (Line 80, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'Scheduler' is not defined. (BC30002) (Line 93, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'ServerSettings' is not defined. (BC30002) (Line 94, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'JobVariable' is not defined. (BC30002) (Line 95, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: 'ClassIDEnum' is not declared. It may be inaccessible due to its protection level. (BC30451) (Line 109, Column 0)****************************************

Message Number: ADT005066E

Message: Script compilation error: Type 'JobVariable' is not defined. (BC30002) (Line 109, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'Scheduler' is not defined. (BC30002) (Line 119, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'Application' is not defined. (BC30002) (Line 120, Column 0)****************************************

Message Number: ADT005066EMessage: Script compilation error: Type 'Application' is not defined. (BC30002) (Line 121, Column 0)****************************************

Message Number: ADT005074EMessage: Compilation of script library "SetVariables" failed. See previous messages for details.****************************************

Where did I go wrong?

The script I'm running looks like:

Imports SystemImports System.Collections.Generic

Imports ArcanaDevelopment.adTempus.SharedImports ArcanaDevelopment.adTempus.ApplicationIntegration

Imports System.IO 

Imports System.Text.RegularExpressions 

Public Class UserScript   

Inherits ArcanaDevelopment.adTempus.ApplicationIntegration.UserScriptBase

Dim NewLine As Char = "\r\n"     

Public Overrides Function Run() As Object 

Dim FILE_NAME As String = adTempus.JobVariables("FileTrigger.FileName")

        'check to make sure file exists       

If Not File.Exists(FILE_NAME) Then

            adtempus.LogMessage(MessageTypeEnum.Error, 0, "Trigger file niet gevonden: " & FILE_NAME)            Return 8

        End If

Dim TextLine As String

If System.IO.File.Exists( FILE_NAME ) = True Then

Dim objReader As New System.IO.StreamReader(FILE_NAME)

Do While objReader.Peek() <> -1

TextLine = objReader.ReadLine()    

'adtempus.LogMessage(MessageTypeEnum.Error, 0, "Regel: " & TextLine)

Dim parts As String() = Nothing

parts = TextLine.Split("=")

Dim part As String

Dim lpsVar As String = String.Empty

Dim lpsVal As String = String.Empty    

'adtempus.LogMessage(MessageTypeEnum.Error, 0, "----")

For Each part In parts

If (lpsVar.Length <> 0) Then lpsVal = part

If (lpsVar.Length = 0) Then lpsVar = part

Next part

SetGroupVariable("LPS\LPSGS17",lpsVar,lpsVal)

Loop

objReader.Close()

'Else

' MessageBox.Show("File Does Not Exist")

End If       

Return 0   

    End Function

End Class

In another script like above , I use:

  adTempus.JobVariables(lpsVar)= lpsVal

This does work, but then the variables are not stored permanently (are they?).

 

Help would be appreciated,

thank you very much

 

Kind regards,

Guy

the Netherlands

 

 

 

Bill Staff (449 posts)
July 28, 2017 12:54 PM
Accepted Answer

That article was written for adTempus 3. If you're using adTempus 4 the code won't work without some changes, as there were some breaking changes to the API. I can get you updated code, but there's a simpler way using a Variable Update Task or Variable Update Action.

What you want to do is use the version of your script where you're setting the variable like this:

adTempus.JobVariables(lpsVar)= lpsVal

As you note, that's not permanent--it only updates the variable for the instance that's running. To update the variable permanently for the group, add a Response to your step and configure it to run when the task succeeds. Add an action to "Update a Job Variable". In the Variable Update Action properties, you're going to set the variable to itself. So if your variable is "MyVariable", you would set the Variable to Update to

MyVariable

and set the value to

%MyVariable%

with the "Expand variable tokens at runtime" option checked. Set the Scope to "Update definition for job group".

This will update the definition of MyVariable with the current value of MyVariable, which you set in your script. You'll need to add a separate Action for each variable you want to update.

I'll get the updated API code together for you if you'd rather do it that way.

GuyS (28 posts)
July 28, 2017 01:41 PM
Accepted Answer

Wow Bill, you are quick with your answer,  again! 

The thing is, that I have several groups of jobs  running on a daily, weekly,monthly, yearly bases. 

Each group has there own set of variables, which are set by using online screens (using ooRexx), which are read and rewritten to a file (like my example). The file is used as triggerfile,  and processed in the first step. Example is the variable Month, which should be set during the month, only once. The next jobs will be submitted on a daily bases, depending on the situation, using the variables. That's why I can't use responses (I think).

If I need to create steps for each variable, then I lose the flexibility of the file with variables. I think you get the picture!

Maybe there is another way? 

The idea is to keep the user away from adtempus (haha, sorry).

let me know what you think please. 

Have nice weekend, 

Guy

 

(Btw, I'm not a vb.net programmer, so that takes some time to get things running)

We are on version 4.4

 

 

Bill Staff (449 posts)
July 28, 2017 02:24 PM
Accepted Answer

I don't think there's a problem.

What you're saying, I think, is that your file will only contain new settings for some subset of the variables, and those are the only ones you want to update. This should work fine: if your script hasn't set a new (instance) value for a variable, then the Response will just be setting the variable definition to the same value it already has.

So for example you have a Year variable for the group. Each job that runs in the group will have the variable set to "2017" for the instance. If your script changes the instance variable to "2018", the Response would update the definition to "2018". But if your script didn't find that variable in the file, it wouldn't set the instance variable to the new value, so it would still have the value "2017", so that's what the Response would use when updating the definition.

In other words you'll still be running Response Actions for all the variables, but most of the variables won't have their values changed.

But I'll go ahead and get you the updated script code, and you can try both approaches to see what works better.

GuyS (28 posts)
July 28, 2017 02:42 PM
Accepted Answer

Ah, I was thinking about starting other jobs, regarding to Responses. I'll look into that this weekend.

But, a new variable in the file for a job (new or already existing) will need an adtempus Response update using this approach, right?

 

Bill Staff (449 posts)
July 28, 2017 03:06 PM
Accepted Answer

You're thinking about Job Control Actions, which are often the main use for Responses. But Responses can also run other kinds of actions.

You're correct that adding a new variable to your file would require you to add a new Action to your response to handle that variable. So to be more flexible, and since you're already writing code to read your file, maybe the code-based approach is better for you after all.

I've updated the code for the version 4 API. You can find the update here.

GuyS (28 posts)
July 28, 2017 04:30 PM
Accepted Answer

Almost there! Do I have an installation problem? See attachment

Thanks Bill

Bill Staff (449 posts)
July 28, 2017 05:57 PM
Accepted Answer

What version are you running? I'm not sure if earlier 4.x versions automatically added the reference to the client DLL that the code assumes is there. If you have 4.4 it should work.

Otherwise go to the Referenced Assemblies section and click Add. Then Browse to the adTempus program folder and select ArcanaDevelopment.adTempus.Client.dll. That should fix it.