Sunday, April 11, 2021

Create charges on sales order line in AX

    salesLine = source;
	salesCurrency = salesLine.CurrencyCode;
	moduleCategory = HeadingLine::Line;
	itemCode = TableGroupAll::Table;
				
	while select markupAutoLine
	  index hint TableIdx
	  where markupAutoLine.TableTableId    == markupAutoTable.TableId   &&
			markupAutoLine.TableRecId      == markupAutoTable.RecId     &&
			markupAutoLine.CurrencyCode    == salesCurrency

	{
		markupTrans.clear();
		markupTrans.initFromMarkupTable(markupAutoLine.markupTable());
		markupTrans.initFromMarkupAutoLine(markupAutoLine);

		switch (source.TableId)
		{
			case tableNum(SalesTable)       :
				markupTrans.initFromSalesTable(source);
				break;
			case tableNum(SalesLine)        :
				markupTrans.initFromSalesLine(source);
				if (salesLine.ReturnDispositionCodeId)
				{
					markupTrans.IsAutoCharge = true;
				}
				break;
		}
		// Preserve original set up currency
		if (markupTrans.markupTable().CustType != MarkupType::CustVend &&
			markupTrans.markupTable().VendType != MarkupType::CustVend)
		{
			markupTrans.CurrencyCode    = markupAutoLine.MarkupCurrencyCode;
		}

		markupTrans.TransTableId    = source.TableId;
		markupTrans.TransRecId      = source.RecId;
		markupTrans.LineNum         = MarkupTrans::lastLineNum(source.TableId, source.RecId) + 1;

		if (languageId)
			markupTrans.Txt = LanguageTxt::languageId(tableNum(MarkupAutoTable), markupAutoLine.RecId, languageId);

		if (! markupTrans.Txt)
			markupTrans.Txt = MarkupTable::find(markupAutoLine.ModuleType, markupAutoLine.MarkupCode).Txt;

		markupTrans.insert();
	}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8