Showing posts with label Tutorial Projects. Show all posts
Showing posts with label Tutorial Projects. Show all posts

Tuesday, September 1, 2026

Skip Inventory reservation on Sales order lines in D365FO

[ExtensionOf(classStr(InventUpd_Reservation))]

final class InventUpd_ReservationCls_SAN_Extension

{

    void updateNow()

    {

        if(movement != null && movement.buffer())

        {

            curBuffer = movement.buffer();

            switch(curBuffer.TableId)

            {

                case tableNum(SalesLine) :

                    salesLine = curBuffer;

                    salesTable = salesLine.salesTable();

                    break;

            }

            

            if(salesLine && salesTable)

            {

                    if()// add requires if needed for reservsation skip

                    {

                              reservation = 0; //To stop reservation

                    }

                }

        next updateNow();

    }

Wednesday, April 1, 2026

WMS Mobile app flow - Adding Detour fields for Process guided framework custom implementation

 WMS Mobile app flow

=> Adding Detour fields for Process guided framework custom implementation

Before fix:



Adding code fix to get thos requires field.

/// <summary>

/// WHS APP FLOW Detour fields implementation SAN_WHSMobileAppFlowPOLMovementLPCreation

/// Run Create Default setup from Mobile device steps

/// </summary>

[WHSWorkExecuteMode(WHSWorkExecuteMode::SAN_MovementLP)]

class SAN_WHSMobileAppFlowPOLMovementLPCreation extends WHSMobileAppFlow

{

    protected void initValues()

    {

        // add available fields

        this.addAvailableField(extendedTypeNum(InventSerialId));

        this.addAvailableField(extendedTypeNum(WHSLicensePlateId));

        this.addAvailableField(extendedTypeNum(ItemId));

    }

}


Post fix:



Thursday, January 1, 2026

Dynamically setting entire Form security access through Extension in D365FO

/// <summary>

/// To check if user can get access to the Parameter form

/// </summary>

class SAN_ParamFormsAccessCtrl

{

    protected void new()

    {

        super();

    }


    static SAN_ParamFormsAccessCtrl construct()

    {

        return new SAN_ParamFormsAccessCtrl();

    }


    public boolean validateUserRoleAccess()

    { 

        #characters

        UserId                  userId = curUserId();

        container               tmpValues; 

        SecurityRole            securityRole;

        SecurityUserRole        securityUserRole;

        int                     idx;

        boolean                 isValidated = false;

        Str                     secRoleList;

        //Created new custom parameter to have which roles alone should have EDIT access, apart from this any roles would have only READ access even System admin

        secRoleList = SAN_IntegrationParameters::find().ParametersAccessSecurityRole;


        if(secRoleList)

        {

            tmpValues = str2con(secRoleList, #semicolon);


            for(idx=1; idx<=conLen(tmpValues); idx++)

            {

                securityRole.clear();

                select firstonly securityRole

                where securityRole.Name == conPeek(tmpValues, idx);


                if(securityRole.RecId && !isValidated)

                {

                    securityUserRole.clear();

                    select firstonly RecId from securityUserRole

                    where securityUserRole.User == userId

                        && securityUserRole.SecurityRole == securityRole.RecId;


                    if (securityUserRole.RecId)

                    {

                        isValidated = true;

                    }

                }

            }

        }


        return isValidated;

    }


    public void disableFormDataSources(FormRun _callingForm)

    {


        FormBuildDataSource frmBuildDS;

        int i;

        for(i = 1; i<= _callingForm.form().dataSourceCount(); i++)

        {

            frmBuildDS = _callingForm.form().dataSource(i);

            frmBuildDS.allowEdit(false);

        }


    }


    public boolean checkRoleCtrlAccess(FormRun _callingForm)

    {

        boolean userHasAccess = this.validateUserRoleAccess();


        if(!userHasAccess)

        {

            this.disableFormDataSources(_callingForm);

        }


        return userHasAccess;

    }


}



[ExtensionOf(formStr(LedgerParameters))]

final class LedgerParametersFrm_SAN_Extension

{

    public void init()

    {

        next init();


        SAN_ParamFormsAccessCtrl paramFormsAccessCtrl;

        paramFormsAccessCtrl = SAN_ParamFormsAccessCtrl::construct();


        if(!paramFormsAccessCtrl.checkRoleCtrlAccess(this))

        {

            this.san_lockControls();

        }

    }


    void san_lockControls()

    {

        FormBuildControl  formBuildControl;

        int i;


        for (i=1;i<=this.form().design().controlCount(); i++)

        {

            formBuildControl = this.form().design().controlNum(i);

            this.control(formBuildControl.id()).enabled(false);

        }

    }


}

Tuesday, December 2, 2025

Override custom dimension value on posting sales invoice in X++

 Requirement:

1. Override custom dimension value on posting sales invoice

2.  Ledger posting type as "Cost of goods, invoiced" & "Sales revenue"

3. Reason: Requirement is to default for certain orders type, these account has to be changed. 

4. Why can't we acheive in Customer or item level dimension. [Reason: Currently it was managed in item level, but requirement is to for same item if order type met certain criteria on posting, this need to defaulted with this dimension value for ledger reporting]


Class 1:

 

/// <summary>

///    The <c>LedgerVoucherTransObject</c> class represents a single transaction in an individual voucher. COC

/// </summary>

/// <remarks>

///    The transaction is stored in a temporary instance of a <see cref="T:LedgerTrans" /> record buffer.

///    The temporary transaction is inserted into the database during posting and made a permanent record.

/// </remarks>

[ExtensionOf(ClassStr(LedgerVoucherTransObject))]

final class LedgerVoucherTransObjectCls_SAN_Extension

{

    /// <summary>

    ///    Initializes a new instance of the <c>LedgerVoucherTransObject</c> class by using a transaction COC POL

    ///    currency amount and a ledger posting reference for defaulting.

    /// </summary>

    /// <param name="_defaultLedgerPostingReference">

    ///    The ledger posting reference to use for defaulting.

    /// </param>

    /// <param name="_postingType">

    ///    The posting type of the general journal entry.

    /// </param>

    /// <param name="_ledgerDimensionId">

    ///    The dimension attribute value combination of the general journal entry.

    /// </param>

    /// <param name="_transactionCurrencyCode">

    ///    The currency code of the general journal entry.

    /// </param>

    /// <param name="_transactionCurrencyAmount">

    ///    The amount in the transaction currency.

    /// </param>

    /// <param name="_exchangeRateHelper">

    ///    The accounting currency amount and secondary currency amount exchange rates.

    /// </param>

    /// <returns>

    ///    A new instance of the <c>LedgerVoucherTransObject</c> class.

    /// </returns>

    /// <remarks>

    ///    The default ledger posting reference is used to set the transaction type and exchange rate date.

    /// </remarks>

    public static LedgerVoucherTransObject newTransactionAmountDefault(

        LedgerVoucherObject _defaultLedgerPostingReference,

        LedgerPostingType _postingType,

        LedgerDimensionAccount _ledgerDimensionId,

        CurrencyCode _transactionCurrencyCode,

        Money _transactionCurrencyAmount,

        CurrencyExchangeHelper _exchangeRateHelper)

    {

        LedgerVoucherTransObject polpostingTrans;

        LedgerDimensionAccount  ledgerDimensionAccount, tempLedgerDimenionAcc;

        ledgerDimensionAccount = _ledgerDimensionId;

 

        if(ledgerDimensionAccount && (_postingType == LedgerPostingType::SalesConsump

            || _postingType == LedgerPostingType::SalesRevenue))

        {

            SAN_SalesInvoiceDimensionMockContext contextCur = SAN_SalesInvoiceDimensionMockContext::current();

            if(contextCur != null)

            {

                if(contextCur.isParameterActive && contextCur.isValidToOverride && contextCur.polproductLineToOverride)

                {

                    tempLedgerDimenionAcc = _ledgerDimensionId;

 

                    ledgerDimensionAccount = SalesInvoiceJournalPost::SAN_buildDefaultAndLedgerDimension(tempLedgerDimenionAcc,contextCur.polproductLineToOverride);

                }

            }

        }

 

        polpostingTrans = next newTransactionAmountDefault(_defaultLedgerPostingReference, _postingType, ledgerDimensionAccount, _transactionCurrencyCode, _transactionCurrencyAmount, _exchangeRateHelper);

 

        return polpostingTrans;

    }

 

}

 

 

Class 2:

/// <summary>

/// To hold the value of SAN_SalesInvoiceDimensionMockContext through out the runtime.

/// </summary>

class SAN_SalesInvoiceDimensionMockContext implements System.IDisposable

{

    public  boolean  isParameterActive;

    public  boolean  isValidToOverride;

    public  SalesTable      polsalesTable;

    public  str             polsmmSegmentId;

    public  str             polproductLineToOverride;

    static  SAN_SalesInvoiceDimensionMockContext   instance;

 

    protected void new ()

    {

        if (instance)

        {

            throw Error('Nesting of SAN_SalesInvoiceDimensionMockContext is not supported');

        }

 

        instance = this;

    }

 

    /// <summary>

    ///  To Create the instance wherever the method is called during the run time.

    /// </summary>

    /// <returns>current new instance</returns>

    Public static SAN_SalesInvoiceDimensionMockContext createInstance()

    {

        SAN_SalesInvoiceDimensionMockContext newInstance = new SAN_SalesInvoiceDimensionMockContext();

        instance = newInstance;

 

        return instance;

    }

 

    /// <summary>

    /// Dispose the instance once the Aging snapshot batch is run.

    /// </summary>

    public void dispose()

    {

        instance = null;

    }

 

    /// <summary>

    ///  To get the instance wherever the method is called during the run time.

    /// </summary>

    /// <returns>Current instance</returns>

    public static SAN_SalesInvoiceDimensionMockContext current()

    {

        return instance;

    }

 

}

 

 

Class 3:

/// <summary>

/// Extension of class SalesInvoiceJournalPost

/// </summary>

[Extensionof (classstr(SalesInvoiceJournalPost))]

Public Final class SalesInvoiceJournalPostCls_SAN_Extension

{

    /// <summary>

    ///     Posts to inventory.

    /// </summary>

    protected void postInventory()

    {

        using(SAN_SalesInvoiceDimensionMockContext contextSet = SAN_SalesInvoiceDimensionMockContext::createInstance())

        {

            if(SalesParameters::find().SAN_OverrideDimensionValue)

            {

                contextSet.isParameterActive = true; 

                SalesTable      salesTable;

                salesTable =  salesLine.SalesTable();

                if(salesTable && salesLine)

                {

                     contextSet.polsalesTable = salesTable;

                        contextSet.isValidToOverride = true;

                        contextSet.polproductLineToOverride = '09';

                }

            }

            next postInventory();

        }

    }

 

    /// <summary>

    ///     Posts one journal line.

    /// </summary>

    protected void postLine()

    {

        using(SAN_SalesInvoiceDimensionMockContext contextSet = SAN_SalesInvoiceDimensionMockContext::createInstance())

        {

           if(SalesParameters::find().SAN_OverrideDimensionValue)

            {

                contextSet.isParameterActive = true;

 

                SalesTable      salesTable;

                salesTable = salesParmLine.SalesLine().SalesTable();

                if(salesTable && salesParmLine  )

                {

                   contextSet.polsalesTable = salesTable;

                        contextSet.isValidToOverride = true;

                        contextSet.polproductLineToOverride = '09';

                }

            }            

            next postLine();

        }

    }

 

    /// <summary>

    /// buildDefaultAndLedgerDimension for govt and non-govt segment

    /// </summary>

    /// <param name = "_ledger">LedgerDimensionAccount</param>

    /// <param name = "_overridePL">overridePL</param>

    /// <returns>ledgerDimensionAccount</returns>

    Static ledgerDimensionAccount  SAN_buildDefaultAndLedgerDimension(LedgerDimensionAccount   _ledger, str _overridePL)

    {

        DimensionAttributeValueSetStorage   dimensionAttributeValueSetStorage;

        DimensionAttributeValue             dimensionAttributeValue;

        DimensionDefault                    dimensionDefault;

        LedgerDimensionAccount              ledgerDimensionAccount;

        DimensionAttributeLevelValueAllView dimAttrValueallview;

        dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();

        RefRecId            mainAccountRecId, LedgerDimensionAcc;

        mainAccountRecId = LedgerDimensionFacade::getMainAccountRecIdFromLedgerDimension(_ledger);

        LedgerDimensionAcc = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(mainAccountRecId);

 

        while select dimAttrValueallview 

            where dimAttrValueallview.ValueCombinationRecId == _ledger

        {

            if(DimensionAttribute::find(dimAttrValueallview.DimensionAttribute).Name != "MainAccount")

            {

                if(DimensionAttribute::find(dimAttrValueallview.DimensionAttribute).Name == "ProductLine")

                {

                    dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(

                                    DimensionAttribute::find(dimAttrValueallview.DimensionAttribute),

                                    _overridePL, false, true);

                }

                else

                {

                    dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(

                                    DimensionAttribute::find(dimAttrValueallview.DimensionAttribute),

                                    dimAttrValueallview.DisplayValue, false, true);

                }

                dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue);

                dimensionDefault = dimensionAttributeValueSetStorage.save();

            }

        }

        ledgerDimensionAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(LedgerDimensionAcc,dimensionDefault);

        return ledgerDimensionAccount;

    }

 

}

Wednesday, November 19, 2025

DMF export using X++

Base class for extract

 /// <summary>

/// Class for extract data

/// </summary>

class SAN_SalesReportDailyService

{

    Filename                filename;

    int                     recordCnt;


    /// <summary>

    /// Import warranty claims

    /// </summary>

    /// <param name = "_contract">Contract of type <b>SAN_SalesReportDailyContract</b></param>

    [SysEntryPointAttribute(false)]

    public void processImport(SAN_SalesReportDailyContract _contract)

    {

        contract            = _contract;


        try

        {

            this.exportSalesInvoiceData();

              

            if (recordCnt)

            {

                info(strFmt("@SANaris:FileExportInfo", filename));

            }

        }

        catch

        {

            error("@SYP4861341");

        }


    }


    public void exportSalesInvoiceData()

    {

        #DMF

        SharedServiceUnitFileID fileId;

        SAN_DataEntityExporter exporter = new SAN_DataEntityExporter();


        DMFDefinitionGroupName definitionGroupName = SalesParameters::find().SAN_SalesDailyReportDefinitionGroup; //TODO create new parameter field to get DMF execution

        DMFDefinitionGroupEntity dmfDefinitionGroupEntity = SAN_SalesReportDailyService::findDMFDefinitionGroupEntity(definitionGroupName);


        if (dmfDefinitionGroupEntity)

        {

            this.updateQueryData(dmfDefinitionGroupEntity);

            this.setFileName();

 

            exporter.parmFilename(filename);

            exporter.exportDataEntity(definitionGroupName, dmfDefinitionGroupEntity.Entity);

        }

        else

        {

            throw error(strFmt("@SANaris:DataEntityMapError", definitionGroupName));

        }

    }


    public str setFileName()

    {

        #File

        str priFix;


        priFix = 'SalesReportSAN_';


        filename = priFix +

            date2str(systemDateGet(),123,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4) + #xlsx;


        return filename;

    }


    private void updateQueryData(DmfDefinitionGroupEntity _dmfDefinitionGroupEntity)

    {

        container queryData = _dmfDefinitionGroupEntity.QueryData;


        if (queryData == connull())

        {

            queryData = DMFUtil::getDefaultQueryForEntityV3(_dmfDefinitionGroupEntity.Entity, _dmfDefinitionGroupEntity.DefinitionGroup);

        }


        QueryRun queryRun = new QueryRun(queryData);

        Query query = queryRun.query();


        QueryBuildDataSource qbds = query.dataSourceTable(tableNum(SAN_SalesReportDailyEntity));

        SysQuery::findOrCreateRange(qbds, fieldNum(SAN_SalesReportDailyEntity, InvoiceDate)).value(queryRange(fromDate, toDate));

        if (warehouseId)

        {

            SysQuery::findOrCreateRange(qbds, fieldNum(SAN_SalesReportDailyEntity, Warehouse)).value(queryValue(warehouseId));

        }


        queryRun = new QueryRun(query);

        queryData = queryRun.pack();

        

        recordCnt = SysQuery::countTotal(queryRun);

        if (recordCnt < 1)

        {

            throw error("@SYS4205");

        }


        ttsbegin;

        _dmfDefinitionGroupEntity.reread();

        _dmfDefinitionGroupEntity.selectForUpdate(true);

        _dmfDefinitionGroupEntity.QueryData = queryData;

        _dmfDefinitionGroupEntity.update();

        ttscommit;

    }


    /// <summary>

    /// Finds the <c>DMFDefinitionGroupEntity</c> record in the given definition group for the Line active view record entity.

    /// </summary>

    /// <param name = "_definitionGroupName">The name if the definition group</param>

    /// <returns>the <c>DMFDefinitionGroupEntity</c> record if found, otherwise null</returns>

    public static DMFDefinitionGroupEntity findDMFDefinitionGroupEntity(DMFDefinitionGroupName _definitionGroupName)

    {

        DMFDefinitionGroupEntity definitionGroupEntity;

        DMFEntity dmfEntity;

        str targetEntityName;


        targetEntityName = 'SAN_SalesReport';


        select firstonly RecId, Entity, DefinitionGroup from definitionGroupEntity

            exists join dmfEntity

                where definitionGroupEntity.DefinitionGroup == _definitionGroupName

                    && dmfEntity.EntityName == definitionGroupEntity.Entity

                    && dmfEntity.TargetEntity == targetEntityName;


        return definitionGroupEntity;

    }


}



Helper class:

/// <summary>

/// Data entity data export helper class.

/// </summary>

public class SAN_DataEntityExporter

{

    Filename filename;

    

    /// <summary>

    /// set file name

    /// </summary>

    /// <param name = "_filename">file name to export data</param>

    /// <returns>file name</returns>

    public Filename parmFilename(Filename _filename = filename)

    {

        filename = _filename;


        return filename;

    }


    /// <summary>

    /// Export an entity to file

    /// </summary>

    /// <param name = "_definitionGroupName">Definition group to reuse</param>

    /// <param name = "_entityName">Entity label</param>

    public void exportDataEntity(DMFDefinitionGroupName _definitionGroupName, DMFEntityName _entityName)

    {

        #DMF

        SharedServiceUnitFileID fileId;


        try

        {

            DMFEntityExporter exporter = new DMFEntityExporter();

            fileId = exporter.exportToFile(_entityName,

                                            _definitionGroupName,

                                            '',

                                            BudgetPlanningConstants::Excel,

                                            #FieldGroupName_AllFields,

                                            conNull(),

                                            curExt()

                                            );

 

            if (fileId != '')

            {

                this.sendFileToDestination(fileId);

            }

            else

            {

                // DMF execution failed and details were written to the execution log.

                throw error("@CashManagement:DMFExportCallFailedToExecutionLog");

            }

        }

        catch

        {

            error("@SYP4861341");

        }

    }


    /// <summary>

    /// Creates a stream, puts it into temp storage (like SendFileToTempStore), and redirects the user to that file to cause it to be downloaded by the user's browser.

    /// </summary>

    /// <param name = "_fileId">The file name of the stream.</param>

    public client void sendFileToDestination(SharedServiceUnitFileID _fileId)

    {

        str downloadUrl = DMFDataPopulation::getAzureBlobReadUrl(str2Guid(_fileId));

        

        System.IO.Stream stream = File::UseFileFromURL(downloadUrl);

        File::SendFileToUser(stream, filename);

    }


}

Tuesday, October 14, 2025

Update Blob storage file data key value using ADF pipeline

 

Activity: Web activity

URL: @concat(pipeline().globalParameters.gp_blobServiceEndpoint,'adf/dealerPortalConfigs/ReleaseDatesConfig.json')
Method: Put

Body: @concat('{
    "value_ReleaseDate":"',variables('v_NewReleaseDate'),'"
}')
Headers:
x-ms-version => 2017-11-09
x-ms-blob-type => BlockBlob

Tuesday, July 1, 2025

Set visibility of menu item based on Feature or parameter options in D365FO

 [SubscribesTo(classstr(SysMenuNavigationObjectFactory), staticdelegatestr(SysMenuNavigationObjectFactory, checkAddSubMenuDelegate))]

public static void menuItemVisibilityHandler(SysDictMenu _rootMenu, SysDictMenu _subMenu, SysBoxedBoolean _subMenuVisibility)

{

    if (_subMenu.isMenuItem())

    {

        var metadataElement = _subMenu.GetMenuItemMetaElement();

        if (metadataElement != null)

        {

            SAN_HelperCls::santst_setVisibilityMenuItems(metadataElement.Name, _subMenuVisibility);

        }

    }

}


public class  SAN_HelperCls
{

private static void santst_setVisibilityMenuItems(str _menuItemName, SysBoxedBoolean _subMenuVisibility)

{

    const str menuItemsPrefix = "SAN_TEST";


    if (strScan(_menuItemName, menuItemsPrefix , 0, strLen(_menuItemName)))

    {

        _subMenuVisibility.value = SAN_HelperCls::isEnabled();

    }

}


 public static boolean isEnabled()

 {

     return isConfigurationkeyEnabled(configurationkeynum(Trade)) && 

             FeatureStateProvider::isFeatureEnabled(SAN_DevFeature::instance());

 }

}


Parameter control (Yes/No)

or

Feature class:

using System.ComponentModel.Composition;

using Microsoft.Dynamics.ApplicationPlatform.FeatureExposure;


/// <summary>

/// The <c>SAN_DevFeature</c> class defines the enable advanced order hold feature.

/// </summary>

[ExportAttribute(identifierstr(Microsoft.Dynamics.ApplicationPlatform.FeatureExposure.IFeatureMetadata))]

[Microsoft.Dynamics.BusinessPlatform.SharedTypes.InternalUseOnlyAttribute]

public final class SAN_DevFeature implements IFeatureMetadata, IFeatureLifecycle

{

    private static SAN_DevFeature instance;


    private void new()

    {

    }


    [Hookable(false)]

    public WebSiteURL learnMoreUrl()

    {

        return 'https://learn.microsoft.com/en-us/';

    }


    private static void TypeNew()

    {

        instance = new SAN_DevFeature();

    }


    /// <summary>

    /// Obtains the singleton object instance.

    /// </summary>

    /// <returns>The <c>SAN_DevFeature</c> instance.</returns>

    [Hookable(false)]

    public static SAN_DevFeature instance()

    {

        return SAN_DevFeature::instance;

    }


    [Hookable(false)]

    public FeatureLabelId label()

    {

        return literalStr("SAN DEV tool features");

    }


    [Hookable(false)]

    public int module()

    {

        return FeatureModuleV0::SalesAndMarketing;

    }


    [Hookable(false)]

    public FeatureLabelId summary()

    {

        return literalStr("SAN DEV tool features");

    }


    [Hookable(false)]

    public boolean isEnabledByDefault()

    {

        return false;

    }


    [Hookable(false)]

    public boolean canDisable()

    {

        return true;

    }


    [Hookable(false)]

    public FeatureLifecycleStage FeatureStage()

    {

        return FeatureLifecycleStage::Released;

    }


}

Wednesday, May 14, 2025

Upload file CSV/TXT using SysOperation in D365 X++

Upload CSV/TXT using SysOperation X++


Contract:
/// <summary>
/// Contract class upload through excel for PO inbound journals
/// </summary>
[DataContractAttribute,
    SysOperationContractProcessingAttribute(classStr(SAN_POImportUIBuilder))]
public class SAN_POImportContract extends SysOperationDataContractBase 
                    Implements SysOperationInitializable, SysOperationValidatable
{
    FileName                    fileName;
    private System.IO.Stream    inputDataStream;
    NoYes                       hasColumnNames;
    Str1260                     layout;

    /// <summary>
    /// Validates the parameters.
    /// </summary>
    /// <returns>
    /// true if successful; otherwise, false.
    /// </returns>
    public boolean validate()
    {
        return true;
    }

    public void initialize()
    {
        hasColumnNames = NoYes::Yes;
    }

    /// <summary>
    /// Gets or sets the value of the data contract parameter fileName.
    /// </summary>
    /// <param name="_fileName">
    /// The new value of the data contract parameter fileName.
    /// </param>
    /// <returns>
    /// Returns the current value of data contract parameter fileName.
    /// </returns>
    public Filename parmFileName(FileName _fileName = fileName)
    {
        fileName = _fileName;
        return fileName;
    }

    /// <summary
    /// Gets or sets the value of the data contract parameter hasColumnNames.
    /// </summary>
    /// <param name = "_hasColumnNames">
    /// The new value of the data contract parameter hasColumnNames.
    /// </param>
    /// <returns>
    /// Returns the current value of data contract parameter hasColumnNames.
    /// </returns>
    [DataMemberAttribute,
        SysOperationLabelAttribute("File has header column") ]
    public NoYes parmHasColumnNames(NoYes _hasColumnNames = hasColumnNames)
    {
        hasColumnNames = _hasColumnNames;
        return hasColumnNames;
    }

    /// <summary>
    /// Set or get Input file data stream
    /// </summary>
    /// <param name = "_value">current value of stream</param>
    /// <returns>file memory stream to process</returns>
    [Hookable(false)]
    public System.IO.Stream parmInputDataStream(System.IO.Stream _value = inputDataStream)
    {
        inputDataStream = _value;
        return inputDataStream;
    }

    /// <summary>
    /// Gets or sets the value of the data contract parameter fileLayout.
    /// </summary>
    /// <param name="_layout">
    /// The new value of the data contract parameter fileLayout.
    /// </param>
    /// <returns>
    /// Returns the current value of data contract parameter fileLayout.
    /// </returns>
    [DataMemberAttribute,
        SysOperationLabelAttribute("File layout") ]
    public Str1260 parmLayout(Str1260 _layout = layout)
    {
        layout =  '';
        layout =  'TXT/CSV File delimited as |' + '\n';

        layout += strfmt("%1 | %2 : %3\n", '1', 'A', 'Column1');
        layout += strfmt("%1 | %2 : %3\n", '2', 'B', 'Column2');
        layout += strfmt("%1 | %2 : %3\n", '3', 'C', 'Column3');
        layout += strfmt("%1 | %2 : %3\n", '4', 'D', 'Column4');
        layout += strfmt("%1 | %2 : %3\n", '5', 'E', 'Column5');


        return layout;
    }

}

UI Builder:
/// <summary>
/// Class is to upload through excel for PO inbound substitution journals to handle run time contract operations
/// </summary>
class SAN_POImportUIBuilder extends SysOperationAutomaticUIBuilder
{

    #define.commandButton('CommandButton')
    #define.fileUpload('FileUpload')
    #define.fileTypesAccepted('.txt,.csv')
    
    SAN_POImportContract   contract;

    /// <summary>
    /// Adds a button to the dialog to import a file.
    /// </summary>
    [Hookable(false)]
    public void build()
    {
        DialogGroup             dialogGroup;
        DialogTabPage           dialogTabPage;
        Dialog                  dlg;
        FormBuildControl        formBuildControl;
        FileUploadBuild         dialogFileUpload;
        DialogField             dialogLayout;
        FormBuildTabPageControl parametersTabPage;
        FormBuildTabPageControl layoutTabPage;

        dlg = this.dialog();

        contract = this.dataContractObject() as SAN_POImportContract;

        dialogTabPage = dlg.addTabPage("@SYS7764");
        dialogTabPage.columns(2);
        parametersTabPage = dlg.formBuildDesign().control(dialogTabPage.name());
        parametersTabPage.fastTabExpanded(FastTabExpanded::Yes);
        dialogGroup = dlg.addGroup('Upload file');
        formBuildControl = dlg.formBuildDesign().control(dialogGroup.name());
        dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), #fileUpload);
        dialogFileUpload.style(FileUploadStyle::MinimalWithFilename);
        dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
        dialogFileUpload.fileTypesAccepted(#fileTypesAccepted);
        dialogFileUpload.fileNameLabel("@SYS308842");

        dlg.addGroup("@SYS339526");
        this.addDialogField(methodStr(SAN_POImportContract, parmHasColumnNames), contract);

        dialogTabPage = dlg.addTabPage("@Polaris:FileLayout");
        layoutTabPage = dlg.formBuildDesign().control(dialogTabPage.name());
        layoutTabPage.fastTabExpanded(FastTabExpanded::Yes);
        dialogLayout = this.addDialogField(methodStr(SAN_POImportContract, parmLayout), contract);
        dialogLayout.showLabel(false);
        dialogLayout.enabled(false);
        dialogLayout.widthMode(1);
        dialogLayout.displayHeight(15);
    }

    /// <summary>
    /// Handles dialog closing events.
    /// </summary>
    /// <param name = "sender">
    /// xFormRun class.
    /// </param>
    /// <param name = "e">
    /// FormEventArgs class.
    /// </param>
    [SuppressBPWarningAttribute('BPParametersNotUsed', 'This event parameter is not used')]
    private void dialogClosing(xFormRun sender, FormEventArgs e)
    {
        FormEventArgs formEventArgs;

        formEventArgs = e;

        this.dialogEventsUnsubscribe(sender as FormRun);
    }

    /// <summary>
    /// Handles dialog events.
    /// </summary>
    /// <param name = "_formRun">
    /// FormRun class type.
    /// </param>
    private void dialogEventsSubscribe(FormRun _formRun)
    {
        FileUpload fileUpload = _formRun.control(_formRun.controlId(#fileUpload));
        fileUpload.notifyUploadCompleted += eventhandler(this.uploadCompleted);
        fileUpload.notifyUploadAttemptStarted += eventhandler(this.uploadStarted);
        _formRun.onClosing += eventhandler(this.dialogClosing);
    }

    /// <summary>
    /// Handles dialog event.
    /// </summary>
    /// <param name = "_formRun">
    /// FormRun class type.
    /// </param>
    private void dialogEventsUnsubscribe(FormRun _formRun)
    {
        FileUpload fileUpload = _formRun.control(_formRun.controlId(#fileUpload));
        fileUpload.notifyUploadCompleted -= eventhandler(this.uploadCompleted);
        fileUpload.notifyUploadAttemptStarted -= eventhandler(this.uploadStarted);
        _formRun.onClosing -= eventhandler(this.dialogClosing);
    }

    /// <summary>
    /// Handles dialog event post run.
    /// </summary>
    [Hookable(false)]
    public void postRun()
    {
        super();
        FormRun formRun = this.dialog().dialogForm().formRun();
        this.dialogEventsSubscribe(formRun);
        this.setDialogOkButtonEnabled(formRun, false);
    }

    /// <summary>
    /// Enables or disables the dialog Ok button.
    /// </summary>
    /// <param name = "_formRun">
    /// The <c>FormRun</c> object.
    /// </param>
    /// <param name = "_isEnabled">
    /// Indicates to enable or disable the Ok button.
    /// </param>
    protected void setDialogOkButtonEnabled(FormRun _formRun, boolean _isEnabled)
    {
        FormControl okButtonControl = _formRun.control(_formRun.controlId(#commandButton));
        if (okButtonControl)
        {
            okButtonControl.enabled(_isEnabled);
        }
    }

    /// <summary>
    /// After the file has been uploaded, the Ok button is enabled.
    /// </summary>
    protected void uploadCompleted()
    {
        contract = this.dataContractObject() as SAN_POImportContract;
        var formRun = this.dialog().dialogForm().formRun();
        FileUpload fileUpload = formRun.control(formRun.controlId(#fileUpload));

        contract.parmFileName(fileUpload.fileName());
        using (System.IO.Stream stream = fileUpload.getUploadedFile(true))
        {
            if (stream)
            {
                System.IO.MemoryStream copiedStream = new System.IO.MemoryStream();
                stream.CopyTo(copiedStream);
                
                contract.parmInputDataStream(copiedStream);
            }
        }

        this.setDialogOkButtonEnabled(formRun, contract.parmInputDataStream() != null);
    }

    /// <summary>
    /// During file upload, the Ok button is disabled.
    /// </summary>
    private void uploadStarted()
    {
        var formRun = this.dialog().dialogForm().formRun();
        this.setDialogOkButtonEnabled(formRun, false);
    }

}


Controller:
/// <summary>
/// Class is to handle controller logic to upload  PO journals
/// </summary>
class SAN_POImportController extends SysOperationServiceController
{
    public ClassDescription caption()
    {
        return "Upload  Purchase Journals";
    }

    /// <summary>
    /// Provides entry point for the instance of <c>SAN_POImportController</c>.
    /// </summary>
    /// <param name = "_args">
    /// The arguments passed to the class <c>SAN_POImportController</c>.
    /// </param>
    public static void main(Args _args)
    {
        SAN_POImportController controller;

        controller = SAN_POImportController::construct();
        controller.showBatchTab(false);
        controller.parmArgs(_args);
        controller.startOperation();
    }

    /// <summary>
    /// Initializes new instance of <c>SAN_POImportController</c>.
    /// </summary>
    /// <returns>
    /// Return object of <c>SAN_POImportController</c>.
    /// </returns>
    public static SAN_POImportController construct()
    {
        SAN_POImportController   controller;
        
        controller = new SAN_POImportController(classStr(SAN_POImportService),
                                                        methodStr(SAN_POImportService, Run),
                                                        SysOperationExecutionMode::Synchronous);

        return controller;
    }

}

Service:
/// <summary>
/// Class is to upload through excel for PO upload journals to handle service operations
/// </summary>
class SAN_POImportService extends SysOperationServiceBase
{
    System.IO.Stream                        stream;
    int                                     totalLinesProcessed = 0;
    SAN_POImportContract        contract;
    str                             filename, journalProcessId;

    /// <summary>
    /// process file to upload WG purchase line item substitution journals
    /// </summary>
    /// <param name = "_contract">
    /// Contract class.
    /// </param>
    public void run(SAN_POImportContract _contract)
    {
        contract            = _contract;
        stream              = _contract.parmInputDataStream();
        filename            = _contract.parmFileName();
        this.processFile(_contract);
    }

    /// <summary>
    /// Processing excel file input
    /// </summary>
    /// <param name = "_contract">
    /// Contract class.
    /// </param>
    protected void processFile(SAN_POImportContract _contract)
    {
        #File
        TextStreamIo inFile = TextStreamIo::constructForRead(stream);
        inFile.inFieldDelimiter('|'); //TODO delimiter used
        inFile.inRecordDelimiter('\r\n'); 
        container recordContainer;
        str item;
        boolean     isFirstLine = true;
        recordContainer = inFile.read();
        if(_contract.parmHasColumnNames())
        {
            recordContainer = inFile.read();
        }
        
        ttsbegin;
        while (inFile.status() == IO_Status::OK)
        {
            if(isFirstLine)
            {
journalProcessId = '';
                //Header record creation logic
                isFirstLine= false;
            }

           //line record creation logic
            //Read the next line
            recordContainer = inFile.read();
        }
        ttscommit;

        info(strFmt("Journal - %2 Total record lines created %1",totalLinesProcessed, journalProcessId));
    }

}

Monday, January 6, 2025

Search hierarchy for a match (TableALLGroup) X++

  Table1 ppt;


 select firstonly ppt

 order ItemCode, ItemRelation, AccountCode, AccountRelation where

     (ppt.ItemCode == TableGroupAll::Table && ppt.ItemRelation == _itemId &&

         ppt.AccountCode == TableGroupAll::Table && ppt.AccountRelation == _accountNum) ||

     (ppt.ItemCode == TableGroupAll::Table && ppt.ItemRelation == _itemId &&

         ppt.AccountCode == TableGroupAll::GroupId && ppt.AccountRelation == _accountGroup) ||

     (ppt.ItemCode == TableGroupAll::Table && ppt.ItemRelation == _itemId &&

         ppt.AccountCode == TableGroupAll::All && ppt.AccountRelation == '') ||


     (ppt.ItemCode == TableGroupAll::GroupId && ppt.ItemRelation == _ItemGroup &&

         ppt.AccountCode == TableGroupAll::Table && ppt.AccountRelation == _accountNum) ||

     (ppt.ItemCode == TableGroupAll::GroupId && ppt.ItemRelation == _ItemGroup &&

         ppt.AccountCode == TableGroupAll::GroupId && ppt.AccountRelation == _accountGroup) ||

     (ppt.ItemCode == TableGroupAll::GroupId && ppt.ItemRelation == _ItemGroup &&

         ppt.AccountCode == TableGroupAll::All && ppt.AccountRelation == '') ||


     (ppt.ItemCode == TableGroupAll::All && ppt.ItemRelation == '' &&

         ppt.AccountCode == TableGroupAll::Table && ppt.AccountRelation == _accountNum) ||

     (ppt.ItemCode == TableGroupAll::All && ppt.ItemRelation == '' &&

         ppt.AccountCode == TableGroupAll::GroupId && ppt.AccountRelation == _accountGroup) ||

     (ppt.ItemCode == TableGroupAll::All && ppt.ItemRelation == '' &&

         ppt.AccountCode == TableGroupAll::All && ppt.AccountRelation == '');


 // Return table buffer if found, otherwise return 0 as the default

 if (ppt.RecId)

 {

     // return result

 }

Thursday, December 12, 2024

Convert Call stack to readable format in D365FO X++

//Input

--container _xppCallStack = xSession::xppCallStack(); 


Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFrames)

{

    str result = '';

    int startFrame = 1 + _skipFrames;


    // Each stack frame is four elements [Method, Line Number, Model Publisher, Model]

    for (int i = startFrame; i <= conLen(_xppCallStack); i += 4)

    {

        str methodName = conPeek(_xppCallStack, i);

        str lineNum = conPeek(_xppCallStack, i + 1);

        str publisher = conPeek(_xppCallStack, i + 2);

        str model = conPeek(_xppCallStack, i + 3);


        // Add a newline between stack frames

        if (i > 1)

        {

            result += '\n at';

        }

        

        // Model identifer

        if (publisher || model)

        {

            result += strFmt('[%1%2%3]', publisher, (publisher && model ? ':' : ''), model);

        }

        

        // Code

        result += strFmt('%1%2', methodName, (lineNum && lineNum != '0' ? ':' + lineNum : ''));

    }


    return result;

}

Monday, November 4, 2024

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++


Class:

Important: Code logic is just for Reference. 

New class => Duplicate of class MarkupCopy & Named as SAN_MarkupCopy

/// <summary>

/// Duplicate Copy class of MarkupCopy

/// Due to extension limited capabilities on internal and private implementation from STD OOB


Helper class: To call logic 

/// <summary>

/// Helper class to centralized logic to copy charges from and to table buffer for purchase

/// </summary>

class SAN_GeneratePurchaseMarkupChargesHelper

{

    public static void createPurchaseHeaderMarkupCharge(

                        Common          _fromTable, 

                        Common          _toTable,

                        PurchTable      _purchTable )

    {

        MarkupCopy                          markupCopy;

        MarkupCopyFromPurchOrderParameters  copyFromPurchOrderToSubTableParameters;


        markupCopy = MarkupCopy::construct();

        copyFromPurchOrderToSubTableParameters =

            MarkupCopyFromPurchOrderParameters::createCopyFromPurchOrderParameters(

                _fromTable,

                _toTable,

                '',

                _purchTable.CurrencyCode,

                SourceDocumentLineAccountingStatus::Draft,

                _purchTable,

                false);

        markupCopy.copyFromPurchOrder(copyFromPurchOrderToSubTableParameters);

    }


  public static void createPurchaseLinesMarkupCharge(

                        PurchLine          _purchLine,

                        VendInvoiceInfoLine          _vendInvoiceInfoLine,

                        PurchTable                  _purchTable,

                        VendInvoiceInfoTable    _vendInvoiceInfoTable)

    {

        ttsbegin;

        SAN_MarkupCopy markupCopy;


        markupCopy = SAN_MarkupCopy::construct();

        MarkupCopyFromPurchOrderParameters copyFromPurchOrderToLineParameters;

        

        copyFromPurchOrderToLineParameters =

                    MarkupCopyFromPurchOrderParameters::createCopyFromPurchOrderParameters(

                        _purchLine,

                        _vendInvoiceInfoLine,

                        '',

                        '',

                        SourceDocumentLineAccountingStatus::Draft,

                        null,

                        false);

        SysDaBinaryExpression       sysDaBinaryExpressionSource, sysDaBinaryExpressionDest;

        sysDaBinaryExpressionDest =  new SysDaEqualsExpression(

                new SysDaFieldExpression(_vendInvoiceInfoLine, fieldStr(VendInvoiceInfoLine, ParmId)), new SysDaValueExpression(_vendInvoiceInfoTable.ParmId))

            .and(new SysDaEqualsExpression(

                new SysDaFieldExpression(_vendInvoiceInfoLine, fieldStr(VendInvoiceInfoLine, TableRefId)), new SysDaValueExpression(_vendInvoiceInfoTable.TableRefId)));


        sysDaBinaryExpressionSource =  new SysDaEqualsExpression(

                new SysDaFieldExpression(_purchLine, fieldStr(PurchLine, RecId)), new SysDaFieldExpression(_vendInvoiceInfoLine, fieldStr(VendInvoiceInfoLine, PurchLineRecId)));


        copyFromPurchOrderToLineParameters.parmBufferToWhereClause(sysDaBinaryExpressionDest);

        copyFromPurchOrderToLineParameters.parmBufferFromWhereClause(sysDaBinaryExpressionSource);

        copyFromPurchOrderToLineParameters.parmDocumentStatusToExclude(DocumentStatus::Invoice);



        MarkupTransTmp markUpTransTmp = markupCopy.copyForAllDocumentLinesUsingTempMarkupTrans(copyFromPurchOrderToLineParameters);

        SAN_GeneratePurchaseMarkupChargesHelper::copyMarkupFromPurchOrderOptimizedCleanup(_vendInvoiceInfoTable, markUpTransTmp);


        ttscommit;

    }


    private static void copyMarkupFromPurchOrderOptimizedCleanup(VendInvoiceInfoTable _vendInvoiceInfoTable, MarkupTransTmp _markUpTransTmpCopy)

    {

        MarkupTrans markupTransOtherInvoices;

        VendInvoiceInfoLine vendInvoiceInfoLine;

        MarkupTransMapping markUpTransMapping;

        

        // Find if there is a MarkupTrans that is not marked Keep and it is already connected to another invoice

        // we will only call delete if there exists one

        select firstonly RecId from _markUpTransTmpCopy

        join vendInvoiceInfoLine

            where vendInvoiceInfoLine.ParmId == _vendInvoiceInfoTable.ParmId

                && vendInvoiceInfoLine.TableRefId == _vendInvoiceInfoTable.TableRefId

                && _markUpTransTmpCopy.TransTableId == vendInvoiceInfoLine.TableId

                && _markUpTransTmpCopy.TransRecId == vendInvoiceInfoLine.RecId

                && _markUpTransTmpCopy.SourceDocumentLine == 0

                && !_markUpTransTmpCopy.Keep

        join markupTransOtherInvoices

            where markupTransOtherInvoices.OrigTableId == _markUpTransTmpCopy.OrigTableId

                && markupTransOtherInvoices.OrigRecId == _markUpTransTmpCopy.OrigRecId

                && markupTransOtherInvoices.TransTableId == _markUpTransTmpCopy.TransTableId

                && markupTransOtherInvoices.TransRecId != _markUpTransTmpCopy.TransRecId;


        if (_markUpTransTmpCopy.RecId != 0)

        {

            vendInvoiceInfoLine.clear();

            markupTransOtherInvoices.clear();


            delete_from _markUpTransTmpCopy

            exists join vendInvoiceInfoLine

                where vendInvoiceInfoLine.ParmId == _vendInvoiceInfoTable.ParmId

                    && vendInvoiceInfoLine.TableRefId == _vendInvoiceInfoTable.TableRefId

                    && _markUpTransTmpCopy.TransTableId == vendInvoiceInfoLine.TableId

                    && _markUpTransTmpCopy.TransRecId == vendInvoiceInfoLine.RecId

                    && _markUpTransTmpCopy.SourceDocumentLine == 0

                    && !_markUpTransTmpCopy.Keep

            join markupTransOtherInvoices

                where markupTransOtherInvoices.OrigTableId == _markUpTransTmpCopy.OrigTableId

                    && markupTransOtherInvoices.OrigRecId == _markUpTransTmpCopy.OrigRecId

                    && markupTransOtherInvoices.TransTableId == _markUpTransTmpCopy.TransTableId

                    && markupTransOtherInvoices.TransRecId != _markUpTransTmpCopy.TransRecId;

        

            //Perform cascading delete action for <c>MarkupTransMapping</c> table

            markUpTransMapping.clear();


            markUpTransMapping.skipDataMethods(true);

            markUpTransMapping.skipDeleteActions(true);

            markUpTransMapping.skipEvents(true);


            delete_from markUpTransMapping

            notexists join _markUpTransTmpCopy

                where _markUpTransTmpCopy.TransRecId == markUpTransMapping.MarkupTransTransRecId &&

                    _markUpTransTmpCopy.TransTableId == markUpTransMapping.MarkupTransTransTableId &&

                    _markUpTransTmpCopy.LineNum == markUpTransMapping.MarkupTransLineNum;

        }


        // Create a SourceDocumentLine record for each new charge

        RecId sourceDocumentHeader = _vendInvoiceInfoTable.SourceDocumentHeader;

        int SourceRelationType = tableNum(MarkupTrans);

        EnumName TypeEnumName = enumStr(SourceDocumentLine_VendorInvoice);

        EnumValue TypeEnumValue = SourceDocumentLine_VendorInvoice::VendorInvoiceChargeLine;

        SourceDocumentLineAccountingStatus AccountingStatus = SourceDocumentLineAccountingStatus::Draft;

        AccountingDate ExchangeRateDate = _vendInvoiceInfoTable.updateDate();


        vendInvoiceInfoLine.clear();

        

        SourceDocumentLine sourceDocumentLine;

        

        sourceDocumentLine.skipDataMethods(true);

        sourceDocumentLine.skipEvents(true);

        sourceDocumentLine.skipTempTableForInsertRecordSet(true);


        insert_recordset sourceDocumentLine

        (

            ParentSourceDocumentLine,

            SourceDocumentHeader,

            AccountingStatus,

            ExchangeRateDate,

            SourceRelationType,

            TypeEnumName,

            TypeEnumValue,

            SourceImplementationRecId

        )

        select

            SourceDocumentLine,

            sourceDocumentHeader,

            AccountingStatus,

            ExchangeRateDate,

            SourceRelationType,

            TypeEnumName,

            TypeEnumValue

        from vendInvoiceInfoLine

            where vendInvoiceInfoLine.ParmId == _vendInvoiceInfoTable.ParmId

                && vendInvoiceInfoLine.TableRefId == _vendInvoiceInfoTable.TableRefId

        join RecId from _markUpTransTmpCopy

            where _markUpTransTmpCopy.TransTableId == vendInvoiceInfoLine.TableId

                && _markUpTransTmpCopy.TransRecId == vendInvoiceInfoLine.RecId

                && _markUpTransTmpCopy.SourceDocumentLine == 0;


        sourceDocumentLine.skipTempTableForInsertRecordSet(false);


        vendInvoiceInfoLine.clear();

        sourceDocumentLine.clear();


        update_recordset _markUpTransTmpCopy setting

            SourceDocumentLine = sourceDocumentLine.RecId

            where _markUpTransTmpCopy.SourceDocumentLine == 0

        join vendInvoiceInfoLine

            where vendInvoiceInfoLine.ParmId == _vendInvoiceInfoTable.ParmId

                && vendInvoiceInfoLine.TableRefId == _vendInvoiceInfoTable.TableRefId

                && vendInvoiceInfoLine.TableId == _markUpTransTmpCopy.TransTableId

                && vendInvoiceInfoLine.RecId == _markUpTransTmpCopy.TransRecId

        join sourceDocumentLine

            where sourceDocumentLine.SourceDocumentHeader == sourceDocumentHeader &&

                sourceDocumentLine.ParentSourceDocumentLine == vendInvoiceInfoLine.SourceDocumentLine &&

                sourceDocumentLine.SourceImplementationRecId == _markUpTransTmpCopy.RecId;


        SAN_GeneratePurchaseMarkupChargesHelper::insertMarkupTransRecordFromMarkupTransTmp(_markUpTransTmpCopy);


        //dispose buffers

        vendInvoiceInfoLine.dispose();

        _markUpTransTmpCopy.dispose();

        markupTransOtherInvoices.dispose();

        markUpTransMapping.dispose();

        sourceDocumentLine.dispose();

    }


    private static void insertMarkupTransRecordFromMarkupTransTmp(MarkupTransTmp _markUpTransTmpCopy)

    {

        SysDaInsertObject insertObj = SAN_GeneratePurchaseMarkupChargesHelper::buildMarkupTransInsertObject();

        SysDaQueryObject  queryObj  = SAN_GeneratePurchaseMarkupChargesHelper::buildMarkupTransTmpQueryObject(_markUpTransTmpCopy);

            

        SAN_GeneratePurchaseMarkupChargesHelper::insertRecords(queryObj, insertObj);

    }


    private static SysDaInsertObject buildMarkupTransInsertObject()

    {

        //insert_recordset markupTransDestination (

        //    BankLCImportChargeAllocation_SA, CalculatedAmount, CalculatedAmountMST_W, CurrencyCode, etc.)


        MarkupTrans markupTransDestination;


        markupTransDestination.skipEvents(true);

        markupTransDestination.skipDataMethods(true);

        markupTransDestination.skipTempTableForInsertRecordSet(true);


        SysDaInsertObject   markupTransInsertObject = new SysDaInsertObject(markupTransDestination);


        SAN_GeneratePurchaseMarkupChargesHelper::addMarkupTransFields(markupTransInsertObject.fields());


        return markupTransInsertObject;

    }


    private static SysDaQueryObject buildMarkupTransTmpQueryObject(MarkupTransTmp _markupTransTmpSource)

    {

        //select BankLCImportChargeAllocation_SA, CalculatedAmount, CalculatedAmountMST_W, CurrencyCode, etc. from markupTransTmpSource


        SysDaQueryObject markupTransTmpQueryObject = new SysDaQueryObject(_markupTransTmpSource);

        SAN_GeneratePurchaseMarkupChargesHelper::addMarkupTransFields(markupTransTmpQueryObject.projection());

        

        return markupTransTmpQueryObject;

    }


    private static void addMarkupTransFields(SysDaSelection _selectionObject)

    {

        _selectionObject

            .add(fieldStr(MarkupTrans, BankLCImportChargeAllocation_SA))

            .add(fieldStr(MarkupTrans, CalculatedAmount))

            .add(fieldStr(MarkupTrans, CalculatedAmountMST_W))

            .add(fieldStr(MarkupTrans, CurrencyCode))

            .add(fieldStr(MarkupTrans, CustomsAssessableValue_IN))

            .add(fieldStr(MarkupTrans, CustVendPosted_RU))

            .add(fieldStr(MarkupTrans, ExchRate_RU))

            .add(fieldStr(MarkupTrans, ExchRateSecond_RU))

            .add(fieldStr(MarkupTrans, FromAmount))

            .add(fieldStr(MarkupTrans, IsAutoCharge))

            .add(fieldStr(MarkupTrans, IsTieredCharge))

            .add(fieldStr(MarkupTrans, ItemPosted_RU))

            .add(fieldStr(MarkupTrans, Keep))

            .add(fieldStr(MarkupTrans, LineNum))

            .add(fieldStr(MarkupTrans, MarkupAllocateAfter_IN))

            .add(fieldStr(MarkupTrans, MarkupCategory))

            .add(fieldStr(MarkupTrans, MarkupClassification_BR))

            .add(fieldStr(MarkupTrans, MarkupCode))

            .add(fieldStr(MarkupTrans, MCRBrokerContractFee))

            .add(fieldStr(MarkupTrans, MCRCouponMarkup))

            .add(fieldStr(MarkupTrans, MCRInstallmentEligible))

            .add(fieldStr(MarkupTrans, MCRMarkupTransCreatedBy))

            .add(fieldStr(MarkupTrans, MCRMiscChargeOverride))

            .add(fieldStr(MarkupTrans, MCROriginalMiscChargeValue))

            .add(fieldStr(MarkupTrans, MCRReasonCode))

            .add(fieldStr(MarkupTrans, MCRRetailInfoCodeId))

            .add(fieldStr(MarkupTrans, MCRSavedRecId))

            .add(fieldStr(MarkupTrans, MCRSavedTableId))

            .add(fieldStr(MarkupTrans, ModuleCategory))

            .add(fieldStr(MarkupTrans, ModuleType))

            .add(fieldStr(MarkupTrans, NotionalCharges_IN))

            .add(fieldStr(MarkupTrans, NotionalPct_IN))

            .add(fieldStr(MarkupTrans, TaxAmount))

            .add(fieldStr(MarkupTrans, TaxAmountExcise_RU))

            .add(fieldStr(MarkupTrans, TaxAmountExciseMST_RU))

            .add(fieldStr(MarkupTrans, TaxAmountMst_W))

            .add(fieldStr(MarkupTrans, TaxAmountVAT_RU))

            .add(fieldStr(MarkupTrans, TaxAmountVATMST_RU))

            .add(fieldStr(MarkupTrans, TaxAutoGenerated))

            .add(fieldStr(MarkupTrans, TaxGroup))

            .add(fieldStr(MarkupTrans, TaxItemGroup))

            .add(fieldStr(MarkupTrans, TaxValueVAT_RU))

            .add(fieldStr(MarkupTrans, TaxVATType_RU))

            .add(fieldStr(MarkupTrans, TaxWriteCode))

            .add(fieldStr(MarkupTrans, ToAmount))

            .add(fieldStr(MarkupTrans, Txt))

            .add(fieldStr(MarkupTrans, Value))

            .add(fieldStr(MarkupTrans, VATDocumentType_RU))

            .add(fieldStr(MarkupTrans, SATProductCode_MX))

            .add(fieldStr(MarkupTrans, SATUnitCode_MX))

            .add(fieldStr(MarkupTrans, WithholdingTypeCode_MX))

            .add(fieldStr(MarkupTrans, MarkupAutoTableRecId))

            .add(fieldStr(MarkupTrans, RetailShippingPromotionDiscount))

            .add(fieldStr(MarkupTrans, IsAdvancedLineProrated))

            .add(fieldStr(MarkupTrans, IsOverriddenProratedLine))

            .add(fieldStr(MarkupTrans, MarkupAutoLineRecId))

            .add(fieldStr(MarkupTrans, IsOverriddenLine))

            .add(fieldStr(MarkupTrans, PreviousValue))

            .add(fieldStr(MarkupTrans, OverrideSalesTax))

            .add(fieldStr(MarkupTrans, TransTableId))

            .add(fieldStr(MarkupTrans, TransRecId))

            .add(fieldStr(MarkupTrans, OrigTableId))

            .add(fieldStr(MarkupTrans, OrigRecId))

            .add(fieldStr(MarkupTrans, SpecificUnitSymbol))

            .add(fieldStr(MarkupTrans, SourceDocumentLine));


        if (LedgerParameters::find().EnableWHTOnCharges == NoYes::Yes)

        {

            _selectionObject

                .add(fieldStr(MarkupTrans, TaxWithholdGroup))

                .add(fieldStr(MarkupTrans, TaxWithholdItemGroup));

        }

    }


    private static void insertRecords(SysDaQueryObject _queryObject, SysDaInsertObject _insertObject)

    {

        _insertObject.query(_queryObject);

        SysDaInsertStatement insertStatement = new SysDaInsertStatement();


        insertStatement.executeQuery(_insertObject);

    }


}

Skip Inventory reservation on Sales order lines in D365FO

[ExtensionOf(classStr(InventUpd_Reservation))] final class InventUpd_ReservationCls_SAN_Extension {     void updateNow()     {         if(mo...