The following script monitors a supplied folder for XML files that include job definitions.
This could be run as a windows scheduled task that acts as middleware to read data from some other system and creates relevant jobs in 12d Synergy.
using System; using System.Linq; namespace CreateJobs { class Program { static void Main(string[] args) { // assume first arg is server address, second arg is location of data files var server = args[0]; var directory = args[1]; // initialise SynergyClientAPI.General.Initialise(); // connect to the server var resp = SynergyClientAPI.General.Connect(server); if (!resp.Ok) { Console.WriteLine("Error during connection: " + resp.Message); return; } // look for some xml files var xml_files = System.IO.Directory.GetFiles(directory, "*.xml"); var attribs_resp = SynergyClientAPI.Attributes.Attribute.GetAttributes(); if (!attribs_resp.Ok) { Console.WriteLine("Error during attribute retrieval: " + resp.Message); return; } var job_number_attrib = attribs_resp.Attributes.FirstOrDefault(x => x.name == "JobNumber"); var job_type_attrib = attribs_resp.Attributes.FirstOrDefault(x => x.name == "JobType"); if (job_number_attrib == null || job_type_attrib == null) { Console.WriteLine("Unable to find required attributes!"); return; } // read through all the xml files foreach (var f in xml_files) { // read from the XML file var xml = System.Xml.Linq.XDocument.Load(f); var job_info = xml.Descendants("Job").Select(x => new { Name = x.Attribute("JobName").Value.ToString(), JobNumber = x.Attribute("JobNumber").Value.ToString(), Description = x.Attribute("Description").Value.ToString(), JobType = x.Attribute("JobType").Value.ToString(), }).FirstOrDefault(); if (job_info == null) continue; // check it doesn't exist var existing_resp = SynergyClientAPI.Projects.Project.GetProjectInfo(job_info.Name); if (!existing_resp.Ok) { Console.WriteLine("Error determining if a job already exists - " + existing_resp.Message); continue; } if (existing_resp.data != null) { Console.WriteLine("Job " + job_info.Name + " already exists - Skipping!"); continue; } // set up job parameters SynergyClientAPI.Projects.CreateProjectParameters parameters = new SynergyClientAPI.Projects.CreateProjectParameters(); parameters.name = job_info.Name; parameters.description = job_info.Description; // set up attributes parameters.attributes = new Contracts.Data.AttributeValueCollection(); parameters.attributes[job_number_attrib.id] = new Contracts.Data.AttributeValue(job_info.JobNumber); parameters.attributes[job_type_attrib.id] = new Contracts.Data.AttributeValue(job_info.JobType); var proj_resp = SynergyClientAPI.Projects.Project.CreateProject(parameters); if (!proj_resp.Ok) { Console.WriteLine("Error during job creation: " + proj_resp.Message); return; } Console.WriteLine("Job " + parameters.name + " has been created"); } } } }
This language is not supported or no code example is available.