Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


rdiesel
2010-04-19T17:12:33Z
Hi

First off, could you kindly clarify the runtime scope of user variables defined via the client interface. If 2 jobs are running concurrently and one job changes the value of a variable will this changed value be visible to another job or do i need to use the "Translate to constant when running" to prevent the other job from seeing the changed variable.

Also I am having trouble accessing the variable values at runtime via the API...



      Client vcClient = new Client();

            Connection vcConn = new Connection();

            vcConn.ConnectionType = Connection.ConnectionT.Local;

            Server vcSvr = vcClient.Connect(vcConn, true);

            UserVariableClass uvCls = vcSvr.Variables.Get("AirtimeStockImportLog");

            string ascVal = new ASCIIEncoding().GetString(uvCls.ValueObject);


the uvCls.Value returns a .Net byte[] type which I cannot decode. Also if i wish to set the value of the Variable programatically how should the value be encoded?

regards
Sponsor
Forum information
Support
2010-04-19T17:15:13Z
That value is encrypted. You should use the ToString method on this method:

GetVariableValue
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
rdiesel
2010-04-19T18:07:31Z
Thanks, have been able to retrieve the value, But have just tested (5.5.5) and it seems that these are global variables ie. if a task in Job x uses and changes the global variable, then another task in Job y will see the changed value - which makes life fairly difficult in creating generic jobs!

Also what is the meaning of "Translate to constant when running"
Support
2010-04-19T18:11:37Z
Yes, those are global Variables so they can be reused easily. But that should not stop you for creating unique Variables based on Job Id or similar in the key.

"Translate to constant when running..". Let say you use a current date variable within a user variable. If that box is not checked it will always retrieve the current that - if checked it will be turned into a string (same date as running) and keep that same string.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
rdiesel
2010-04-19T18:55:57Z
Thanks, the JobId prefix will solve my problem.
Luke Watson
2015-01-02T14:26:11Z
Originally Posted by: Support 

That value is encrypted. You should use the ToString method on this method:

GetVariableValue



I am trying to get the value of a Job Variable, but the only reference i can find to GetVariableValue is "VisualCronAPI.Variables._Variables.GetVariableValue" and it requires a UserVariable, not a JobVariable.

we are on version 7.0.5, im sure im just doing something simple, but i cant find anything on search either.

Many thanks
Support
2015-01-05T09:44:26Z
If it is a Job Variable you should use;

serverObj.Jobs.JobVariables.GetValue()
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Eddie Kumar
2022-04-25T08:35:55Z
Hi Henrik,

Could you please provide an example of usage of the GetVariableValue() method.

Call to "GetVariableValue()" returns unexpected error.

FYI: I'm using version 8.5.5.

TIA.
Eddie
Eddie Kumar
2022-04-25T13:23:41Z
Originally Posted by: Eddie Kumar 

Hi Henrik,

Could you please provide an example of usage of the GetVariableValue() method.

Call to "GetVariableValue()" returns unexpected error.

FYI: I'm using version 8.5.5.

TIA.
Eddie




Never mind, I got it:

I used for following PowerShell code (in case someone needs to see an example):
[VisualCronAPI.Variables]::GetVariableValue($myUserVar).ToString();


Note: GetVariableValue() is a Static member/method. Earlier I was inadvertently attempting to call it without success as an instance method which was incorrect:
VisualCronAPI.Variables.GetVariableValue($myUserVar).ToString();


Full Example:
$VCAPIpath = 'C:\Program Files (x86)\VisualCron\PowerShell\VisualCronAPI.dll'
$VCpath = 'C:\Program Files (x86)\VisualCron\PowerShell\VisualCron.dll'

# Load VisualCron API Dlls:
#Add-Type -LiteralPath 'C:\Program Files (x86)\VisualCron\PowerShell\VisualCronAPI.dll'
$VC = [Reflection.Assembly]::LoadFrom($VCpath);
$VCAPI = [Reflection.Assembly]::LoadFrom($VCAPIpath);

# Create Client & Server Objects:
$Global:Client = New-Object -TypeName VisualCronAPI.Client
$Global:Server = New-Object -TypeName VisualCronAPI.Server

# Create Connection Object:
$Conn = New-Object -TypeName VisualCronAPI.Connection

# Set Connection Values:
$Conn.Address = 'localhost'
#AD User:
$Conn.UseADLogon = $true;
$Conn.UserName = $myDomain\myADAccount'
<# #VC User:
$Conn.UserName = 'VCAPI_user'
$Conn.PassWord = '********'
#>
$Conn.Port = 16444
$Conn.ConnectionType = 'Local'

# Ensure VisualCron Service is running (if connecting locally):
If ($Conn.Address -like 'localhost' -and -not (Get-Process VisualCronService -ErrorAction SilentlyContinue)) {
	Write-Output "Error: VisualCron service not running."
	exit
}

# Try Connecting to VisualCron Server:
try {
	$Global:Server = $Client.Connect($conn, $true);
}
catch {
	Write-Output "Error: Could Not Connect to VisualCron Server, check connection parameters."
}

<# #Accessing Variables via API:
#Global User Variables: #>

$myUserVar = $Global:Server.Variables.Get("MyUserVarName");
$myUserVar.Name
#$myUserVar.ValueObject.ToString();   #-> EdNote: returning System.Byte[]  grrrrr.
[VisualCronAPI.Variables]::GetVariableValue($myUserVar).ToString();

<# #Job Variable:
#serverObj.Jobs.JobVariables.GetValue()
#GetServerVariableValue(strVariable, strJobId, strTaskId)
#>
Scroll to Top