Working days in a bpm

Epicor version 9.05.701

I need to bring in a customised date field (something like porel.date01)…which is the easy bit.
I need this date though to be a calculation that cannot be modified.

So,
porel.date01 = PORel.PromiseDt less 1 working day.

How / Where do i achieve this?

Many thanks in advance.

How “exact” do you need it? Specifically on the definition of a “working day”. Just Exc Sat & Sun? Holidays?Based on your production calendar?

And by “not be changed”, do you mean that if PromiseDt changes, the original calculated value remains unchanged?

Hi Calvin,

Just excluding weekends will be fine. (our production calendar excludes weekends).

Not changed as in…the date01 field cannot be modified by a user (i guess this is to basically make it read only?)…but if the promisedt field is changed the date01 field can move with it.

Calculating date differences used to be a pain, but C# has some functions (VB may as well) for doing the date diff. Just check

In totally pseudo code:
If(DayOfWeek(PromiseDt)= {value of Monday}) Then
Date01 - DateDiff(PromiseDt,-3)
Else If(DayOfWeek(PromiseDt)= {value of Sunday}) Then
Date01 - DateDiff(PromiseDt,-2)
Else
Date01 - DateDiff(PromiseDt,-1)
end if

Do this in a Data Directive on change of PromiseDt

As for making it “read only”, do that at the form level, where ever it is displayed.

1 Like

Just so we’re clear, those functions “DayOfWeek” and “DateDiff” are place holders for actual functions that your language uses.

Your right, its ABL in 9.05
Im not 100% sure of the syntax myself.

def var newDate as Date init Today no-undo.
def var totalDays as Integer init 0 no-undo.
def var validDateFound AS LOGICAL init false no-undo.
def var calName as Character init "MAIN" no-undo.

for each ttQuoteHed no-lock, first QuoteHed where QuoteHed.QuoteNum = ttQuoteHed.QuoteNum.
	if (QuoteHed.Quoted eq false) THEN DO:

			// Initialize
			assign newDate = QuoteHed.DueDate.

			for first ProdCal fields (BeginWeekday WorkWeek) where ProdCal.Company = CUR-COMP and ProdCal.CalendarID = calName no-lock.
						// Search for a Valid WorkDay
						do while validDateFound = false:


							// Make sure the WeekDay is not a Saturday or a Sunday
							if weekday(newDate) <> 1 and weekday(newDate) <> 7 then do:

								// If its not the Weekend make sure it is a WorkingDay
								find first ProdCalDay no-lock where ProdCalDay.CalendarID = calName and ProdCalDay.ModifiedDay = newDate and ProdCalDay.WorkingDay = false no-error.

								// If its not a WorkingDay try going a date back
								if not available(ProdCalDay) then do:
									if ProdCal.WorkWeek[ weekday(newDate) ] = true then do:
										assign validDateFound = true.
									end.
								end.
							end.

							// We dont have a valid date lets try next day
							if (validDateFound eq false) THEN DO:
								assign newDate = newDate + 1.
							END.
						end.
			end.


		// Assign New Due Date
		assign QuoteHed.Date02 = newDate.
		assign QuoteHed.DueDate = newDate.
	END.
end.

Thank you for this.
I don’t really understand ABL but i’ve tried to convert what you had to the PORel table as below:
But it doesn’t appear to trigger

def var newDate as Date init Today no-undo.
def var totalDays as Integer init 0 no-undo.
def var validDateFound AS LOGICAL init false no-undo.
def var calName as Character init “MAIN” no-undo.

for each ttPORel no-lock, first PORel where PORel.PONum = ttPORel.PONum.
if (PORel.Date01 > 01/01/2015) THEN DO:

		/* Initialize*/
		assign newDate = PORel.Date02.

		for first ProdCal fields (BeginWeekday WorkWeek) where ProdCal.Company = CUR-COMP and ProdCal.CalendarID = calName no-lock.
					/* Search for a Valid WorkDay*/
					do while validDateFound = false:


						/* Make sure the WeekDay is not a Saturday or a Sunday*/
						if weekday(newDate) <> 1 and weekday(newDate) <> 7 then do:

							/* If its not the Weekend make sure it is a WorkingDay*/
							find first ProdCalDay no-lock where ProdCalDay.CalendarID = calName and ProdCalDay.ModifiedDay = newDate and ProdCalDay.WorkingDay = false no-error.

							/* If its not a WorkingDay try going a date back*/
							if not available(ProdCalDay) then do:
								if ProdCal.WorkWeek[ weekday(newDate) ] = true then do:
									assign validDateFound = true.
								end.
							end.
						end.

						/* We dont have a valid date lets try next day*/
						if (validDateFound eq false) THEN DO:
							assign newDate = newDate + 1.
						END.
					end.
		end.


	/* Assign New Due Date*/
	assign PORel.Date02 = newDate.
END.

end.

so, …PORel.Date02 is the field i want to populate with 1 working date behind PORel.PrmoseDt

Im not sure of he syntax but might be ale to do this without using ABL.

Isn’t it just something like PORel.PromiseDt - 1 weekday?

Shouldn’t your DD trigger off of a change to PORel.PrmoseDt and not PORel.Date01 ?

Or is something else already updating Date01?

sorry, this is something else.
Date01 is just a user defined field that the user can type in a date.

Ideally, i need Date02 to be 1 working day less than Date01.

In the DD:
image

image

the expresion:

BpmFunc.WeekDay(ttUD05Row.Date01)== 0 ? BpmFunc.AddInterval(ttUD05Row.Date01,-2 , IntervalUnit.Days) 
      : (BpmFunc.WeekDay(ttUD05Row.Date01)== 1  ? BpmFunc.AddInterval(ttUD05Row.Date01,-3 , IntervalUnit.Days) 
        : BpmFunc.AddInterval(ttUD05Row.Date01,-1 , IntervalUnit.Days))

You won’t see Date02 change until the record is saved. If you need to see Date02 change on the screen (when Date01 changes), use a customization triggering off an event tied to Date01’s control. Do the math, and then update Date02’s GUI control.

EDIT: This was done in E10, so the expression might vary. WeekDay==1 for Sunday, ==2 for Monday,

EDIT #2 VERY IMPORTANT !!!
Changed the values in the comparisons. On screen help says Sun=1. When in fact, Sun = 0.
image

I understand the condition and i can match that.
But the Action I think you’ve used a user defined field?

I don’t mind if Date02 only updates when user clicks save.

In E10, there are two different AddInterval functions

image

Maybe you only have the one with just two params. if so, change to that.

To be honest, I didn’t use that one, because I didn’t know the type it wanted for the ‘y’ parameter.

Looks like param 2 should be of type ‘System.TimeSpan’

image

I used UD05 as my test.

Change references of ttUD05Row to ttPORelRow

This is what i’m getting…
I changed the syntax of AddInterval to Add-Interval to match the function

try building that expression using the Variables and functions from the two panes - double click on them to have it inserted into the Editor pane.

Just do a simple expression like

WeekDay(ttPORelRow.Date01) == 0 ? ttPORelRow.Date01 : ttPORelRow.Date01

If that passes Syntax check then you know the WeekDay() function is used properly. Then try adding the

AddInterval()

function, like:

WeekDay(ttPORelRow.Date01) == 0 ? AddInterval(ttPORelRow.Date01,1) : ttPORelRow.Date01

Edit : I find it very odd that the function name ‘Add-Interval’ would contain a dash ‘-’

Maybe the expression doesn’t like the line breaks in the nested condition (x ? y : z)