Schedule Job in C#

I was reading this thread and was trying to do what OP wanted to do. The thread doesn’t have the up front solution, here is what I have done.

My problem, I want job to be Scheduled when user tick Engineered.

So I added a Data directive, so when user change the JobEngineered field from any to True, the BPM fires.

Here is the code for the Custom Code block,

Make sure Usings:

using Erp.Tablesets;
using Ice.Tablesets;

and References :
Erp.Contracts.BO.ScheduleEngine


      // Declare variable hScheduleEngine
      Erp.Contracts.ScheduleEngineSvcContract hScheduleEngine = null;
      hScheduleEngine = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ScheduleEngineSvcContract>(Db); 
      

      
      if(hScheduleEngine != null)
      {
          
          var ttJobHead_xRow = (from ttJobHead_Row in ttJobHead
                            where string.Equals(ttJobHead_Row.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase)
                            || string.Equals(ttJobHead_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase)
                            select ttJobHead_Row).FirstOrDefault();
        
          ScheduleEngineTableset scheduleEngineTableset = new ScheduleEngineTableset();
          
          if(ttJobHead_xRow != null)
          {
            // Get the ScheduleEngineTableset
            
            hScheduleEngine.GetScheduleRecord(ref scheduleEngineTableset);
            var schedEng = (ScheduleEngineRow) scheduleEngineTableset.ScheduleEngine.First();
            

            schedEng.Company = callContextClient.CurrentCompany;
            schedEng.JobNum =ttJobHead_xRow.JobNum;
            schedEng.AssemblySeq = 0;
            schedEng.OprSeq = 0;
            schedEng.OpDtlSeq = 0;
            schedEng.StartDate = DateTime.Today;
            schedEng.StartTime = 0;
            schedEng.EndDate = ttJobHead_xRow.ReqDueDate;
            schedEng.EndTime = 0;
            schedEng.WhatIf = false;
            schedEng.Finite = false;
            schedEng.SchedTypeCode = "JJ";
            schedEng.ScheduleDirection = "End";
            schedEng.SetupComplete =false;
            schedEng.ProductionComplete = false;
            schedEng.OverrideMtlCon = false;
            schedEng.OverRideHistDateSetting = 2;
            schedEng.RecalcExpProdYld = false;
            schedEng.UseSchedulingMultiJob = false;
            schedEng.SchedulingMultiJobIgnoreLocks=false;
            schedEng.SchedulingMultiJobMinimizeWIP = false;
            schedEng.SchedulingMultiJobMoveJobsAcrossPlants = false;
            schedEng.RowMod = "A";
           

            bool finished = false; 
            string txt = "";
            
            hScheduleEngine.MoveJobItem(scheduleEngineTableset, out finished, out txt); 
            
            hScheduleEngine.AcceptChanges(string.Empty,scheduleEngineTableset);
            
            if(finished == true)
            {
              this.PublishInfoMessage("Job has been scheduled via BPM (DD) successfully", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
            }      
          }
      }

So when the Engineered tick box is ticked, the job will be scheduled based on code. Hope this helps others .

4 Likes

Thanks for sharing this. For me it is scheduling the job and giving the job a due date, but the required materials are not having a due date assigned, and therefore not creating any PO suggestions. Did you run into this?

This setting might be affecting your due dates being assigned to materials. Play with that and see if you get some different results.

Thanks for this post. I created an external C# program and couldn’t figure out why I couldn’t get the scheduler to reschedule. It seemed like it was but it wasn’t. Key to it is the Accept changes. SMH :smile:
To answer the other question that was asked, here this is what returns from the getschedtypecode.it was one string and separated by the infamous ~

first string is for all codes
JJJob - All Jobs ~JPJob - Successors Jobs
~JCJob - Predecessors Jobs ~JAJob - All Operations
~BPBranch - Preceding Operations ~BSBranch - Subsequent Operations
~AA`Assembly - All Operations

Second is operation only codes
JAJob - All Operations ~BPBranch - Preceding Operations
~BSBranch - Subsequent Operations ~AAAssembly - All Operations
~APAssembly - Preceding Operations ~ASAssembly - Subsequent Operations
~oo`Operation Only

I hope this helps someone else.

Have a great day!
Matt

2 Likes