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 .