Community forum

Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
Offline PrimeViewDevelopers  
#1 Posted : Wednesday, July 16, 2014 4:35:12 PM(UTC)
PrimeViewDevelopers

Rank: Paid support

Joined: 2/13/2014(UTC)
Posts: 1

I am currently trying to clone job tasks programmatically to other Jobs. I have the following code:

Code:
            var mytask = s.Jobs.GetJobByName("Template Job").Tasks[0];
            var myclone = mytask.CloneType();
            myclone.Name = "Ping Data Sources Test";
            var myjob = s.Jobs.GetJobByName("Target Job");
            myjob.Tasks.Add(myclone);
            s.Jobs.Tasks.Update(myclone);
            s.Jobs.Update(myjob);


This code executes fine, but causes the VC Client to crash (the server is completely fine). The crash happens because of a duplicated ID number. Do I need to generate a new ID number for the cloned task?
Offline Support  
#2 Posted : Thursday, July 17, 2014 9:02:55 AM(UTC)
Support

Rank: Official support

Medals:
Joined: 2/23/2008(UTC)
Posts: 9,291

Thanks: 565 times
Was thanked: 320 time(s) in 308 post(s)
Yes, please do the following:

Code:
var mytask = s.Jobs.GetJobByName("Template Job").Tasks[0];
var myclone = mytask.CloneType();

myclone.Id = Guid.NewGuid().ToString(); // create new Task Id
myclone.Stats.TaskId = myclone.Id; // copy new Id to this place as well
myclone.ResetStats(); // reset to not run yet etc.

myclone.Name = "Ping Data Sources Test";
var myjob = s.Jobs.GetJobByName("Target Job");

myclone.Order = myjob.Tasks.Count + 1; // update Order property
myclone.JobId = myjob.Id; // if cloning to another Job

myjob.Tasks.Add(myclone);
s.Jobs.Tasks.Update(myclone);
s.Jobs.Update(myjob);

Edited by user Thursday, July 17, 2014 9:05:20 AM(UTC)  | Reason: Not specified

Henrik
Support
http://www.visualcron.com

Please like VisualCron on facebook!
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2016, Yet Another Forum.NET
This page was generated in 0.132 seconds.
Scroll to Top