Community forum

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


rloesche
2016-04-12T16:04:35Z
Hello,

I'm creating a job with a Loop and a condition. When I open the job in the GUI it looks fine. When I start it it does not loop.

When I manually remove the condition in the GUI and then add it again in the GUI everything is fine. It seems I'm missing something when adding the condition in code. What could that be ??

The C# script I'm using is this:

public static void createHttpTask(string servername)
{
Console.WriteLine("ASDF");

JobClass job = new JobClass();
job.Name = "job3http";
job.Group = "rl cj";
job.Description = "mein zweiter Job";

TaskClass task = job.AddTask(TaskClass.TaskT.HTTP);
task.Name = "T1";
task.HTTP.Method = "GET";
task.HTTP.ContentTypeHeader = "application/x-www-form-urlencoded; charset=UTF-8";
task.HTTP.URL = "http://server/.....";

JobLoopSettingsClass jls = new JobLoopSettingsClass();
jls.LoopSettings.LoopType= LoopSettingsClass.LoopT.WhileLoop;
jls.LoopSettings.MaxIterations = 300;
jls.LoopSettings.ValueX = "asdf";
jls.LoopSettings.ValueY = "asdf";

jls.LoopSettings.Wait.Use = true;
jls.LoopSettings.Wait.Seconds= 30 ;
jls.StartTaskId = task.Id;
jls.EndTaskId = task.Id;
jls.Name = "myloop";
job.AddLoop(jls);
List<ConditionSetClass> cscs = server.Conditions.GetAll();
foreach (ConditionSetClass csc in cscs)
{
Console.WriteLine(csc.Description);
Console.WriteLine(csc.Id);
if (csc.Description == "X4 ArcIn Jobs bis 21:00 Uhr")
{
task.Conditions.Add(csc.Id);
}
}
server.Jobs.Update(job);
}


my environment is:

VC 8.0.4
Win 2012 R2 64bit
Sponsor
Forum information
bbusse
2016-04-12T18:32:58Z
I have not yet dove into creating Jobs/Tasks/Conditions/etc... with the API. Just used it for general data retrieval a few times. But is there also a call you have to make to 'update' the task(s) as well as the job like you did: server.Jobs.Update(job);

One would think updating the Job would update it all properly. Just asking because i haven't looked at all the methods yet.

Brian
rloesche
2016-04-13T07:38:55Z
That is exactly my suspicion, Brian. But I did not find a method like this ...

Ralf
Support
2016-04-14T12:49:04Z
The code is correct and worked for me. Only thing I can think of is that the hard coded description is wrong. Try removing it and you should have at least one.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
rloesche
2016-04-14T15:57:16Z
Hi Hendrik

after i generated the job I checked that the condition has a tick in the box - so no typo.
I generated the job without the condition and my expectation was that the loop would start - it did not. One execution and finito. Just opening the task definition window and closing it again changes the behaviour: the loop runs as expected.

I started digging a little bit.
1. after generation of the job I exported the visualcron settings as NEW ( the job starts and ends nearly immediately )
2. in the gui I opened the condition dialog, did nothing and simply closed the dialog
3. I exported the settings as OLD ( job runs as expected )

A comparison shows one difference ( besides some timestamps ) in the OnError settings of the single task.
So maybe I have to set the OnError things in the task explicitly. I'll try that this evening or tomorrow.

The is shown below:

NEW

<OnError>
<CausesError>NotSet</CausesError>
<ErrorList />
<ErrorAction>NotSet</ErrorAction>
<RetryTimes>0</RetryTimes>
<RunFollowingTasks>true</RunFollowingTasks>
<Minutes>0</Minutes>
<Seconds>0</Seconds>
<ExitCodeCollectionId />
<RaiseErrorAction>NotSet</RaiseErrorAction>
<ExitCode>77777</ExitCode>
<EventCondition>IfOutputError</EventCondition>
<ValueType>String</ValueType>
<ConditionType>Equal</ConditionType>
<ConditionValue1 />
<ConditionValue2 />
</OnError>

OLD

<OnError>
<CausesError>Selected</CausesError>
<ErrorList>
<ErrorT>Unhandled</ErrorT>
<ErrorT>TaskTimeout</ErrorT>
</ErrorList>
<ErrorAction>NotSet</ErrorAction>
<RetryTimes>0</RetryTimes>
<RunFollowingTasks>true</RunFollowingTasks>
<Minutes>0</Minutes>
<Seconds>0</Seconds>
<ExitCodeCollectionId>746c95ce-d394-491c-925c-8bd50e4daa8e</ExitCodeCollectionId>
<RaiseErrorAction>NotSet</RaiseErrorAction>
<ExitCode>77777</ExitCode>
<EventCondition>IfOutputError</EventCondition>
<ValueType>String</ValueType>
<ConditionType>Equal</ConditionType>
<ConditionValue1 />
<ConditionValue2 />
</OnError>

Support
2016-04-14T19:00:15Z
I misunderstood you, I thought you did not get it checked.

You may need to add default behavior. On success->Continue to next Task and On error->Exit Job.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Support
2016-04-14T19:57:42Z
I think we have found the problem now. It is related to On error as you say.

Try adding this:


       task.OnError.ExitCodeCollectionId = ExitCodeCollectionClass.WindowsDefaultCollectionId;


We will change this behavior in the next build so you do not need to set this. When it is not set it will not continue to next Task because it cannot resolve the result properly.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
rloesche
2016-04-14T20:13:29Z
Hi Hendrik

just tried it:
task.OnError.ExitCodeCollectionId = ExitCodeCollectionClass.WindowsDefaultCollectionID;

c# tells me that there is no definition for WindowsDefaultCollectionID and does not compile :(

kind regards

ralf
Support
2016-04-14T20:15:25Z
You are right, we have moved it now in latest build. You can either hard code it to: "746c95ce-d394-491c-925c-8bd50e4daa8e"

Or use VisualCronAPI.ExitCodes.WindowsDefaultCollectionId

Just note that it will be moved to ExitCodeCollectionClass.WindowsDefaultCollectionID in next build.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
rloesche
2016-04-14T20:27:46Z
Hi Henrik

task.OnError.ExitCodeCollectionId = "746c95ce-d394-491c-925c-8bd50e4daa8e";

works :)

thx - i'm not on facebook otherwise i would like you - next time i'll try chat

kind regards

ralf
Support
2016-04-14T21:49:05Z
Originally Posted by: rloesche 

Hi Henrik

task.OnError.ExitCodeCollectionId = "746c95ce-d394-491c-925c-8bd50e4daa8e";

works :)

thx - i'm not on facebook otherwise i would like you - next time i'll try chat

kind regards

ralf



Great - thanks for the report!
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top