Dynamics AX Blog - Posts from 2015 - Page 1

These posts are machine-translated.
Currently, only posts from »2015« are displayed

Calling a SysOperation-based function through code

If you need to run a function - implemented by using the SysOperation-Framework - by code, the following job can show you how you can do this.

static void runSysOperationThroughCode(Args _args)
{
    TutorialSysOperationServiceController controller;
    TutorialSysOperationDataContract dataContract;
    SysOperationStartResult sysOperationStartResult;
    
    controller = TutorialSysOperationServiceController::newFromArgs(new Args()); 

    dataContract = controller.getDataContractObject('_dataContract'); 

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous); 

    dataContract.parmFilenameSave(@"c:	empmyFile.txt");
    dataContract.parmCustAccount('US-006');
       
    sysOperationStartResult =
    controller.startOperation();
}

 
 
 

Debugging SSRS-Dataprovider

In the past i often had the problem, that i had to debug a dataprovider of a SSRS-Report, which could not be debugged using the well known Dynamics AX Debugger (for example because the dataprovider is executed only on server).

Therefore i created the below job (DataProvider has to extend SRSReportDataProviderBase), which only puts the content of the created (temporary) table to an simple infolog.

In the example the report "Work note" of the service module is used.

static void testSSRSDatProvider(Args _args)
{
    SMAWorkNoteTmp      tempTable;
    SMAWorkNoteDP       dataProvider = new SMAWorkNoteDP();
    SMAWorkNoteContract contract = new SMAWorkNoteContract();
    Query               query = new Query(identifierStr(SMAWorkNote));

    try
    {
        SysQuery::findOrCreateRange(
            query.dataSourceTable(
                tableNum(SMAServiceOrderTable)),
                fieldNum(SMAServiceOrderTable, ServiceOrderId)).value("00018");

        contract.parmItemConsumption(true);
        contract.parmItemRequirement(true);
        contract.parmExpense(true);
        contract.parmFee(true);
        contract.parmAdditionalNotes(true);
        contract.parmLineText(true);

        if( !contract.validate())
        {
            throw error(error::missingParameter(contract));    
        }

        dataProvider.parmDataContract(contract);
        dataProvider.parmQuery(query);
        dataProvider.processReport();

        tempTable = dataProvider.getSMAWorkNoteTmp();

        while select tempTable
        {
            info(tempTable.otServiceOrderId);
        }
    }
    catch (Exception::Break)
    {
        info("Aborted");
    }
}

 
 
 

Add prefixes to infolog-messages

With setPrefix () you can easily create nested messages in the infolog.
What I not knew before is, that you can integrate those prefixes directly in the message, simply by expanding the actual message to the desired heading and the control character for a tabulator.

static void inlinePrefix(Args _args)
{
    setPrefix("Inhaltsverzeichnis");
    info("Kapitel 1	Seite 1");
    info("Kapitel 1	Seite 2");
    info("Kapitel 1	Seite 3");
    info("Kapitel 2	Seite 4");
    info("Kapitel 2	Seite 5	Abschnitt 1");
    info("Kapitel 2	Seite 5	Abschnitt 2");
    info("Kapitel 2	Seite 6");    
}

The created infolog will look like this:

Infolog


 
 
 

Block journal through code

A common requirement in project life is to create journals of various types per code.

I recently had a similar requirement, but the Journal should not be posted immediatily, but it should be ensured that these journals are not unintentionally changed by other users.

And precisely for this requirement, the following code is intended:

JournalTableData::updateBlockServer(
    prodJournalTable, 
    JournalBlockLevel::None, 
    JournalBlockLevel::InUse, 
    false);

 


 
 
 

How to create a non-primary address in global adressbook

Example of how you can create a non-primary address for an entry in the global address book via code.

static void createPartyAddressNonPrimary(Args _args)
{
    DirPartyTable dirPartyTable = DirPartyTable::findByNum("???100000??");
    DirParty dirParty;
    DirPartyPostalAddressView dirPartyPostalAddressView;

    // Create instance of dirParty
    dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), dirPartyTable.partyType());

    // Create primary address
    dirPartyPostalAddressView.LocationName      = "Delivery";
    dirPartyPostalAddressView.City              = "Vienna";
    dirPartyPostalAddressView.Street            = "Kärtnerring";
    dirPartyPostalAddressView.StreetNumber      = "21";
    dirPartyPostalAddressView.CountryRegionId   = "AUT";
    dirPartyPostalAddressView.IsPrimary         = NoYes::No;

    dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
}

 
 
 

Open query window when opening form

To open the query-windows when opening a form, you can use the following code for example:

public void run()
{
    super();
    if(dataSourceName_ds.queryRun().prompt())
    {
        dataSourceName_ds.research();
    }
}

 


 
 
 

Cancel salesline through code

The code is based on the logic in the form SalesUpdateRemain ("Deliver remainder" button in the sales order header).

static void cancelSalesLine(Args _args)
{
    boolean updated;
    SalesLine salesLine; 
    
    try
    {
        ttsBegin;        
        
        salesLine = SalesLine::findInventTransId('012411', true);
    
        updated = SalesUpdateRemain::updateDeliveryRemainder(salesLine, 0, 0);
    
        if(updated)
        {
            info("Salesline canceled");    
        }        
        
        ttsCommit;
    }
    catch
    {
        error("SalesLine could not be canceled");
    }
}

 
 
Pages 1 2 3 4 » 

 

 
 
 
Posts of the actual month
April 2015
MoTuWeThFrSaSu
 12345
6789101112
13141516171819
20212223242526
27282930 
 
© 2006-2025 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.