Schedule A New Stock Job Via C# Directive

Hi eveyone,

I did some preliminary digging before creating this post and didn’t see anything of specific help so hopefully I have not missed something. I am looking for some help or potentially a headstart on some C# Code for a Post Processing Method Directive to completely Schedule an Unscheduled stock workorder job entirely through C#. I already ran a trace log on the scheduling process from Job Entry and I am starting there-- but I am unfortunately in some extreme crunch time on figuring this out for my client and I was hoping there might be a snippet of code out there that could give me a head start.

I already have access to the obviously necessary data like Company/Plant/JobNum and the Date I am trying to (forward) Schedule the job to.

I assume I will have to use either the JobEntry service contract, JobScheduling service contract, or the SchedulingEngine contract-- so I have grabbed all of these references to start.

Any assistance on this topic is greatly appreciated-- Will update with any progress or other questions as I go.

Thank you,
Dylan

Easiest way would probably to run a trace through Quick Job Entry that will for sure cut down on the code needed to do it.

I would walk through that process quick see if you get the result you are looking for then run a trace if you do. The number of fields required is heavily reduced.

2 Likes

I use this in a dashboard.

try
						{
							var schedDS = new Erp.Tablesets.ScheduleEngineTableset() ;
							var sp = schedDS.ScheduleEngine.NewRow() ;
							sp["Company"]	 	   = callContextClient.CurrentCompany ;
							sp["JobNum"]		     = jobNum ;
							sp["AssemblySeq"] 	 = 0 ;
							sp["OprSeq"]      	 = 0 ;
							sp["OpDtlSeq"]    	 = 0 ;
							sp["StartDate"]   	 = startDate ;
							sp["StartTime"]   	 = 0 ;
							sp["EndDate"]     	 = dueDate ;
							sp["EndTime"]     	 = 0 ;
							sp["WhatIf"] 		    = false ;
							sp["Finite"] 		    = false ;
							sp["SchedTypeCode"]  	  = "jj" ;
							sp["ScheduleDirection"]  = "End" ; //"Start" ;
							sp["SetupComplete"]  	  = false ;
							sp["ProductionComplete"] = false ;
							sp["OverrideMtlCon"]	   = true ;
							sp["OverRideHistDateSetting"] = 2 ; 
							sp["RecalcExpProdYld"] 	     = false ;
							sp["UseSchedulingMultiJob"]   = false ;
							sp["SchedulingMultiJobIgnoreLocks"]  = false ;
							sp["SchedulingMultiJobMinimizeWIP"]  = false ;
							sp["SchedulingMultiJobMoveJobsAcrossPlants"] = false ;
							sp["SysRowID"] 		 = Guid.NewGuid() ;
							sp["RowMod"]        = "A" ;
							schedDS.ScheduleEngine.Add( sp );
							Ice.Diagnostics.Log.WriteEntry("In MoveJobitem " + jobNum.ToString() + " pn " + dueDate.ToString());
							boSched.MoveJobItem( schedDS, out finished, out Msg  ) ;
							ttr.Calculated_Status = "Scheduled - " + Msg ;
						} catch (Exception ex) {
							ttr.Calculated_Status = string.Format("Error: {0} Scheduling Job: {1}", ex.Message, jobNum) ;
						}

1 Like

Thank you Greg very much, this will help me greatly. I will get cracking.

Greg, if you don’t mind me asking, how did you define / declare the variable “ttr” in your example?

ttr is just the dashboard results to send back a status. You can just do a messagebox

1 Like

Ah! Got it! Thank you so much man. You are a lifesaver. I was halfway there when I got your response earlier and it is taking me over the finish line my friend.

1 Like

Marked Greg’s helpful response as solution to my Original Post.

Basic summary of how this is done for future help seekers:

  • using Ice.Assemblies;
    using Erp.Contracts;

  • ref ScheduleEngine assembly

  • create new var for ServiceRenderer.GetService<Erp.Contracts.ScheduleEngineSvcContract>(Db)

  • create new TableSet for Erp.Tablesets.ScheduleEngineTableset

  • create new row with ScheduleEngine.NewRow()

  • set all columns in the new row as follows sp[“Company”] = jh.Company;

  • add row to ScheduleEngine tableset like: schTs.ScheduleEngine.Add(sp);

  • call “MoveJobItem” method on the ScheduleEngine BO Contract like: sch.MoveJobItem( schTs, out b, out msg );

Once I have my code more finalized I will post what I can of it here.