Automatically add Misc Charge to Order

Team, I am stumped. I have a working BPM that appears to be working completely, but does not actually create any records. :weary:

E9.05.702 (not 702a)

The Order is being created via DMT and the OrderComment field is loaded with text that needs to be split up and made into Header Misc Charges.
I have added messages to the log to ensure everything is working and it appears to be perfect. Butā€¦ Nothing. I am testing this by simply changing the text of the Comment.

I have moved things around quite a bit, but I am willing to try anything againā€¦

Here is an example of the Comment:

Discount (none) : $0.0 |  Shipping : $10.0 | Tax (NY State Tax,Dutchess County Tax 0.04,0.04125) : $2.44

Pre-Processing:
image

Post-Processing code:

def var orderNum like OrderHed.OrderNum no-undo.
def var custNum like OrderHed.CustNum no-undo.
def var orderComment as char no-undo.
def var logMsg as char no-undo.

def var lContinue as log no-undo.
def var cResponseMsg as char no-undo.
def var cDisplayMsg as char no-undo.
def var cCompliantMsg as char no-undo.
def var cResponseMsgOrdRel as char no-undo.

def var iEntry as int no-undo.
def var sEntry as char no-undo.
def var dAmount as dec no-undo.
def var miscCode as char no-undo.

def var hSO as handle no-undo.
RUN bo\SalesOrder\SalesOrder.p PERSISTENT SET hSO.

for each ttOrderHed:
	assign orderNum = ttOrderHed.OrderNum
		custNum = ttOrderHed.CustNum
		orderComment = ttOrderHed.OrderComment
		logMsg = "Shopify Misc (Order: " + STRING(ttOrderHed.OrderNum) + ") ".
end.
message logMsg + "Start".

repeat iEntry = 1 to NUM-ENTRIES(orderComment,'|'):
	assign sEntry = TRIM(ENTRY(iEntry, orderComment, '|')).
	if sEntry BEGINS "Shipping" then miscCode = "FRT".
	if sEntry BEGINS "Tax" then miscCode = "SLTX".

	assign dAmount = DECIMAL(ENTRY(2, sEntry, "$")).

	if miscCode <> "" and dAmount > 0 and not CAN-FIND(first ttOHOrderMsc where ttOHOrderMsc.MiscCode = miscCode) then do:

		message logMsg + "Get Order".
		run GetByID in hSO (input orderNum, {&output_dataset_SalesOrderDataSet}).

		run GetNewOHOrderMsc in hSO ({&input-output_dataset_SalesOrderDataSet}, orderNum, 0).
		message logMsg + miscCode + " Get New".
		
		for first ttOHOrderMsc where ttOHOrderMsc.RowMod = "A".
			ttOHOrderMsc.MiscCode = miscCode.
			message logMsg + miscCode + " Set Code".
		end.
		run ChangeMiscCode in hSO ({&input-output_dataset_SalesOrderDataSet}, "OHOrderMsc").

		for first ttOHOrderMsc where ttOHOrderMsc.MiscCode = miscCode.
			ttOHOrderMsc.Freqcode = "F".
			ttOHOrderMsc.DocDspMiscAmt = dAmount.
			ttOHOrderMsc.RowMod = "A".
			message logMsg + miscCode + " Set Amount: " + STRING(dAmount).
		end.
		run ChangeMiscAmount in hSO ({&input-output_dataset_SalesOrderDataSet}, "OHOrderMsc").

		run MasterUpdate in hSO (input true, input "OHOrderMsc", input custNum, input orderNum, input false, output lContinue, output cResponseMsg, output cDisplayMsg, output cCompliantMsg, output cResponseMsgOrdRel, {&input-output_dataset_SalesOrderDataSet}).
		message logMsg + miscCode + " Update Order".
	end.
end.
message logMsg + "END".
run GetByID in hSO (input orderNum, {&output_dataset_SalesOrderDataSet}).

Log output:

[20/11/12@18:18:44.767-0800] P-009136 T-002312 2 AS AS -- TRACE: SINGLE-RUN Procedure 'bo/SalesOrder/Sink.p:MasterUpdate' START (14244)
[20/11/12@18:18:44.927-0800] P-009136 T-002312 1 AS BAQ        Parameterized execution of '' query on behalf of manager user is started.
[20/11/12@18:18:44.990-0800] P-009136 T-002312 2 AS FILEID     Open d:\EpicorData\baq9136203658007.p ID=11
[20/11/12@18:18:44.990-0800] P-009136 T-002312 2 AS FILEID     Close d:\EpicorData\baq9136203658007.p ID=11
[20/11/12@18:18:44.991-0800] P-009136 T-002312 2 AS FILEID     Open d:\EpicorData\baq9136203658007.p ID=11
[20/11/12@18:18:44.998-0800] P-009136 T-002312 2 AS FILEID     Close d:\EpicorData\baq9136203658007.p ID=11
[20/11/12@18:18:44.998-0800] P-009136 T-002312 2 AS FILEID     Open d:\EpicorData\baq9136203658007.p ID=11
[20/11/12@18:18:45.006-0800] P-009136 T-002312 2 AS FILEID     Close d:\EpicorData\baq9136203658007.p ID=11
[20/11/12@18:18:45.007-0800] P-009136 T-002312 2 AS FILEID     Open d:\EpicorData\baq9136203658007.r ID=11
[20/11/12@18:18:45.010-0800] P-009136 T-002312 2 AS FILEID     Close d:\EpicorData\baq9136203658007.r ID=11
[20/11/12@18:18:45.011-0800] P-009136 T-002312 2 AS FILEID     Open d:\EpicorData\baq9136203658007.r ID=11
[20/11/12@18:18:45.011-0800] P-009136 T-002312 2 AS FILEID     Close d:\EpicorData\baq9136203658007.r ID=11
[20/11/12@18:18:45.012-0800] P-009136 T-002312 1 AS BAQ        Parameterized execution of the query is finished.
[20/11/12@18:18:45.638-0800] P-009136 T-002312 2 AS FILEID     Open d:\Epicor905\bpmExec\LiveBPM\bo\SalesOrder\SalesOrder.r ID=11
[20/11/12@18:18:45.644-0800] P-009136 T-002312 2 AS FILEID     Close d:\Epicor905\bpmExec\LiveBPM\bo\SalesOrder\SalesOrder.r ID=11
[20/11/12@18:18:45.681-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14822) Shopify Misc (Order: 1198100) Start
[20/11/12@18:18:45.681-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14833) Shopify Misc (Order: 1198100) Get Order
[20/11/12@18:18:46.340-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14837) Shopify Misc (Order: 1198100) FRT Get New
[20/11/12@18:18:46.340-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14841) Shopify Misc (Order: 1198100) FRT Set Code
[20/11/12@18:18:46.404-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14849) Shopify Misc (Order: 1198100) FRT Set Amount: 10
[20/11/12@18:18:46.728-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14854) Shopify Misc (Order: 1198100) FRT Update Order
[20/11/12@18:18:46.729-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14833) Shopify Misc (Order: 1198100) Get Order
[20/11/12@18:18:47.775-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14837) Shopify Misc (Order: 1198100) SLTX Get New
[20/11/12@18:18:47.775-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14841) Shopify Misc (Order: 1198100) SLTX Set Code
[20/11/12@18:18:47.838-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14849) Shopify Misc (Order: 1198100) SLTX Set Amount: 2.44
[20/11/12@18:18:48.415-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14854) Shopify Misc (Order: 1198100) SLTX Update Order
[20/11/12@18:18:48.416-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14857) Shopify Misc (Order: 1198100) END
[20/11/12@18:18:49.980-0800] P-009136 T-002312 3 AS AS -- TRACE: SINGLE-RUN Procedure END SUCCESS. (14265)

What Method Directive are you using?
Iā€™m pretty sure you have to use the xxxxx.UpdateExt Method when interacting with DMT loads.

Iā€™m using SalesOrder.Update which is called inside UpdateExt. The event triggers just fine. The code validates, runs without error and executes every line of code. It simply does not write anything to the DB.

Jason Woods
http://LinkedIn.com/in/jasoncwoods

After this line (run ChangeMiscAmount in hSO ({&input-output_dataset_SalesOrderDataSet}, ā€œOHOrderMscā€)), add a message to see the value of RowMod

Code snippet:

...
		run ChangeMiscAmount in hSO ({&input-output_dataset_SalesOrderDataSet}, "OHOrderMsc").

		for first ttOHOrderMsc where ttOHOrderMsc.MiscCode = miscCode.
			message logMsg + miscCode + " Amount RowMod: " + ttOHOrderMsc.RowMod.
		end.

		run MasterUpdate in hSO (input true, input "OHOrderMsc", input custNum, input orderNum, input false, output lContinue, output cResponseMsg, output cDisplayMsg, output cCompliantMsg, output cResponseMsgOrdRel, {&input-output_dataset_SalesOrderDataSet}).
...

Looks good:

[20/11/12@19:43:32.158-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14822) Shopify Misc (Order: 1198100) Start
[20/11/12@19:43:32.159-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14833) Shopify Misc (Order: 1198100) Get Order
[20/11/12@19:43:33.077-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14837) Shopify Misc (Order: 1198100) FRT Get New
[20/11/12@19:43:33.077-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14841) Shopify Misc (Order: 1198100) FRT Set Code
[20/11/12@19:43:33.144-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14849) Shopify Misc (Order: 1198100) FRT Set Amount: 10
[20/11/12@19:43:33.212-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14854) Shopify Misc (Order: 1198100) FRT Amount RowMod: A
[20/11/12@19:43:33.315-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14858) Shopify Misc (Order: 1198100) FRT Update Order
[20/11/12@19:43:33.315-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14833) Shopify Misc (Order: 1198100) Get Order
[20/11/12@19:43:34.526-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14837) Shopify Misc (Order: 1198100) SLTX Get New
[20/11/12@19:43:34.526-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14841) Shopify Misc (Order: 1198100) SLTX Set Code
[20/11/12@19:43:34.591-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14849) Shopify Misc (Order: 1198100) SLTX Set Amount: 2.44
[20/11/12@19:43:34.657-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14854) Shopify Misc (Order: 1198100) SLTX Amount RowMod: A
[20/11/12@19:43:35.141-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14858) Shopify Misc (Order: 1198100) SLTX Update Order
[20/11/12@19:43:35.141-0800] P-009136 T-002312 1 AS -- (Procedure: 'UpdatePost42_A1 bo/SalesOrder/SalesOrder.p' Line:14861) Shopify Misc (Order: 1198100) END

Any thoughts?

Add an Update after your GetNew and the rest would remain the same

		run GetNewOHOrderMsc in hSO ({&input-output_dataset_SalesOrderDataSet}, orderNum, 0).
		message logMsg + miscCode + " Get New".
		
		for first ttOHOrderMsc where ttOHOrderMsc.RowMod = "A".
			ttOHOrderMsc.MiscCode = miscCode.
			message logMsg + miscCode + " Set Code".
		end.
RUN Update IN hSO({&input-output_dataset_SalesOrderDataSet}).

Still no luck. I instead moved to UpdateExt and suddenly it worked. Here is the working code:

/* Create Misc Charges
Jason Woods (jason@jasonwoods.me)
11/11/2020 */

def var orderNum like OrderHed.OrderNum no-undo.
def var custNum like OrderHed.CustNum no-undo.
def var orderComment as char no-undo.

def var errorsOccured as log no-undo.

def var iEntry as int no-undo.
def var sEntry as char no-undo.
def var dAmount as dec no-undo.
def var miscCode as char no-undo.

def var hSO as handle no-undo.
RUN bo\SalesOrder\SalesOrder.p PERSISTENT SET hSO.

for each ttOrderHed:
	assign orderNum = ttOrderHed.OrderNum
		custNum = ttOrderHed.CustNum
		orderComment = ttOrderHed.OrderComment.
end.

repeat iEntry = 1 to NUM-ENTRIES(orderComment,'|'):
	assign sEntry = TRIM(ENTRY(iEntry, orderComment, '|')).
	if sEntry BEGINS "Shipping" then miscCode = "FRT".
	if sEntry BEGINS "Tax" then miscCode = "SLTX".

	assign dAmount = DECIMAL(ENTRY(2, sEntry, "$")).

	if miscCode <> "" and dAmount > 0 and not CAN-FIND(first ttOHOrderMsc where ttOHOrderMsc.MiscCode = miscCode) then do:

		create ttOHOrderMsc.
		run ZeroizeBuf(temp-table ttOHOrderMsc:default-buffer-handle). /* Is this simply extra code?*/
		ttOHOrderMsc.Company = cur-comp.
		ttOHOrderMsc.DocDspMiscAmt = dAmount.
		ttOHOrderMsc.DocMiscAmt = dAmount.
		ttOHOrderMsc.DspMiscAmt = dAmount.
		ttOHOrderMsc.MiscAmt = dAmount.
		ttOHOrderMsc.MiscCode = miscCode.
		ttOHOrderMsc.OrderLine = 0.
		ttOHOrderMsc.OrderNum = orderNum.
		ttOHOrderMsc.SeqNum = 0.
		ttOHOrderMsc.FreqCode = "F".
		ttOHOrderMsc.RowMod = "A".
		for each MiscChrg fields (Description) no-lock where MiscChrg.Company = cur-comp and MiscChrg.MiscCode = miscCode.
			ttOHOrderMsc.Description = MiscChrg.Description.
		end.
	end.
end.

run UpdateExt in hSO(input-output dataset SalesOrderDataSet, true, true, output dataset BOUpdErrorDataset, output errorsOccured).

run GetByID in hSO (input orderNum, {&output_dataset_SalesOrderDataSet}).

delete procedure hSO.

Odd - the code snippet I added from working code in E9 that does just this but it triggered from a different source - not a DMT. Just for laughs I added your code above with this change and it worked! The only difference is that I am forwarding to a procedure vs. embedding in Widget.

An External ā€œPā€ file would act differently to some degree as it is outside the current BO.
Thanks for the help either way!