Home

Monday, June 10, 2019

Filter records using unbound Enum combo box values

1- Form Class declaration-
public class FormRun extends ObjectRun
{
   
    QueryBuildRange   qbr;
    AllOpenPosted     status;
}

2-Form's init method--

public void init()
{
    super();

    AllOpenPostedField.selection(AllOpenPosted::Open);
    status   = AllOpenPostedField.selection();

}

3- form Data Source execute query-
public void executeQuery()
{
   QueryBuildDataSource qbds;
    ;
    if(status == AllOpenPosted::Open)
    {
        qbr.value(QueryValue(NoYes::No));
    }
     else if(status == AllOpenPosted::Posted)
    {
        qbr.value(QueryValue(NoYes::Yes));
    }
    else
    {
        qbr.value(SysQuery::valueNot(AllOpenPosted::All));
    }
    super();
}
4-form data source init method

public void init()
{
    QueryBuildDataSource qbds;
    super();

    qbds =  this.query().dataSourceTable(tablenum(STG_SalaryDisbursement));
    if (element.args().dataset() != tablenum(STG_SalaryDisbursement))
    {
        qbds  =  this.query().dataSourceTable(tablenum(STG_SalaryDisbursement));
        qbr   =  qbds.addRange(fieldnum(STG_SalaryDisbursement,JVPosted));
    }
}

5- Unbound enum control's modified method:
public boolean modified()
{
    boolean ret;
   ;
   ret = super();

   status   = this.selection();

   STG_SalaryDisbursement_ds.executeQuery();

   return ret;
}


Thursday, July 20, 2017

Find party Email phone and fax based on type ax 365

class TestRunnableClass
{      
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {    
        /*LogisticsElectronicAddress      logisticsElectronicAddress;
        int64                           party;
        party                        = VendTable::find(PurchTable::find("P000000052").OrderAccount).Party;
        Phone ph=    LogisticsElectronicAddress::findPrimary( VendTable::find(PurchTable::find("P000000052").OrderAccount).Party, LogisticsElectronicAddressMethodType::Phone).Locator;
        info(strFmt("primary is --%1",ph));*/

     
        LogisticsElectronicAddress      logisticsElectronicAddress;
        VendTable vendtable;
        vendTable = VendTable::find("V000000020");
        select Location, Type, Locator,Description from logisticsElectronicAddress
        where logisticsElectronicAddress.Location == DirPartyLocation::findOrCreate(vendTable.Party, 0).Location
        && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email
        && logisticsElectronicAddress.IsPrimary == NoYes::Yes;
        info(strFmt("Email is-%1 .. Contact is-%2",logisticsElectronicAddress.Locator,logisticsElectronicAddress.Description));
           
       
    }

}

Ax 365 ssrs report handler class

class ABC_purchPurchaseOrderHandler
{
    
    
        /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(PurchPurchaseOrderHeader), DataEventType::Inserting)]
    public static void PurchPurchaseOrderHeader_onInserting(Common sender, DataEventArgs e)
    {
        PurchPurchaseOrderHeader    tmpTable = sender;
        VendTable                   vendTable;

        vendTable                        = VendTable::find(PurchTable::find(tmpTable.PurchId).OrderAccount);
        tmpTable.ABC_vendPhone           = PurchTable::find(tmpTable.PurchId).vendorPhone();
        tmpTable.ABC_vendTeleFax         = PurchTable::find(tmpTable.PurchId).vendTable_InvoiceAccount().telefax();
        tmpTable.ABC_DlvMode             = PurchTable::find(tmpTable.PurchId).DlvMode;
        tmpTable.ABC_PayTerms            = PurchTable::find(tmpTable.PurchId).Payment;
        tmpTable.ABC_SupplierDescription = PurchTable::find(tmpTable.PurchId).vendorName();
        tmpTable.ABC_Buyer               = HcmWorker::find(PurchTable::find(tmpTable.PurchId).WorkerPurchPlacer).name();
        tmpTable.ABC_InvoiceDescription  = dirParty::findPostalAddressByRole(vendTable.Party, LogisticsLocationRoleType::Invoice).displayLocationDescription();
        tmpTable.ABC_BillingAddress      = dirParty::findPostalAddressByRole(vendTable.Party, LogisticsLocationRoleType::Invoice).Address;
        tmpTable.ABC_Contact             = ABC_purchPurchaseOrderHandler::getContactDeatils(vendTable.Party, LogisticsElectronicAddressMethodType::Email).Description;
        tmpTable.ABC_vendPhone           = ABC_purchPurchaseOrderHandler::getContactDeatils(vendTable.Party, LogisticsElectronicAddressMethodType::Phone).Locator;
       
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(PurchPurchaseOrderTmp), DataEventType::Inserting)]
    public static void PurchPurchaseOrderTmp_onInserting(Common sender, DataEventArgs e)
    {
        PurchPurchaseOrderTmp           tempTable = sender;
        VendPurchOrderJour              vendPurchOrderJour = VendPurchOrderJour::findRecId(tempTable.JournalRecId);
        CustVendExternalItem            custVendExternalItem;


        select ExternalItemTxt from custVendExternalItem
            where custVendExternalItem.ItemId == tempTable.ItemId &&
            custVendExternalItem.ExternalItemId == tempTable.ExternalItemNum &&
                custVendExternalItem.CustVendRelation == vendPurchOrderJour.purchTable().InvoiceAccount;

        tempTable.ABC_ExternalItemName  = custVendExternalItem.ExternalItemTxt;
    }

    /// <summary>
    /// Get the party contact details
    /// </summary>
    /// <param name = "_party"></param>
    /// <param name = "_type"></param>
    /// <returns></returns>
    public static LogisticsElectronicAddress getContactDeatils(RefRecId _party, LogisticsElectronicAddressMethodType _type)
    {
        LogisticsElectronicAddress      logisticsElectronicAddress;

        select * from logisticsElectronicAddress
            where logisticsElectronicAddress.Location == DirPartyLocation::findOrCreate(_party, 0).Location
                && logisticsElectronicAddress.Type == _type
                && logisticsElectronicAddress.IsPrimary == NoYes::Yes;

        return logisticsElectronicAddress;
    }

}

Friday, March 31, 2017

D365 | Recurring Integration - Application ID

When you create a recurring data job in Dynamics 365 (AX7) you will be asked for an application id in the "Setup authorization policy" tab.


If you don't have already created your application id within the azure active directory you need to follow these steps to get it done. This relates to the new azure portal: https://portal.azure.com


1- Login to the azure portal and click on azure active directory.

             

2- Manage -> App registration and click ADD

             

3- In the Create dialog enter a name, select Application type Native and provide a uri. For example the address of your onebox development environment: https://usnconeboxax1aos.cloud.onebox.dynamics.com
Click Create - and wait a second

       
4- Navigate to the newly created app - now you should already see the application id that you're looking for

 

5- Before you continue in D365 click on required permissions - Add

6- Select: Microsoft Dynamics ERP (Microsoft.ERP) as the API and select permissions as needed and click select and done

7- Now your required permissions should look like this


Copy the application id and enter it in Dynamics 365. Now you can go on with the recurring integration.



Sunday, June 26, 2016

Add Range in query ax 2012

static void AddRangeToQuery3Job(Args _args)
{
    Query q = new Query();  // Create a new query.
    QueryRun qr;
    CustTable ct;
    QueryBuildDataSource qbr1;
    str strTemp;
    ;

    // Add a single datasource.
    qbr1 = q.addDataSource(tablenum(CustTable));
    // Name the datasource 'Customer'.
    qbr1.name("Customer");

    // Create a range value that designates an "OR" query like:
    // customer.AccountNum == "4000" || Customer.CreditMax > 2500.

    // Add the range to the query data source.
    qbr1.addRange(fieldNum(CustTable, AccountNum)).value(
    strFmt('((%1.%2 == "US-012") || (%1.%3 > 100))',
        qbr1.name(),
        fieldStr(CustTable, AccountNum),
        fieldStr(CustTable, CreditMax)));

    // Print the data source.
    print qbr1.toString();
    info(qbr1.toString());

    // Run the query and print the results.
    qr = new QueryRun(q);

    while (qr.next())
    {
        if (qr.changedNo(1))
        {
            ct = qr.getNo(1);
            strTemp = strFmt("%1 , %2", ct.AccountNum, ct.CreditMax);
            //print strTemp;
            info(strTemp);
        }
    }
    pause;
}
================================================================
static void Job34(Args _args)
{

    Query q = new Query();  // Create a new query.
    QueryRun qr;
    InventTrans inventTrans;
    QueryBuildDataSource qbr1;
    str strTemp;
    ;

    // Add a single datasource.
    qbr1 = q.addDataSource(tablenum(InventTrans));
    // Name the datasource 'Customer'.
    qbr1.name("InventTrans");

    // Create a range value that designates an "OR" query like:
    // customer.AccountNum == "4000" || Customer.CreditMax > 2500.

    // Add the range to the query data source.
    qbr1.addRange(fieldNum(InventTrans, StatusReceipt)).value(
    strFmt('((%1 == %2 ") || (%1 == %3) ||  (%4 == %5)))',
        fieldStr(InventTrans, StatusReceipt),
        any2int(StatusReceipt::Purchased),
        any2int(StatusReceipt::Received),
        fieldStr(InventTrans, StatusIssue),
        any2int(StatusIssue::sold)));

    // Print the data source.
    print qbr1.toString();
    info(qbr1.toString());

    // Run the query and print the results.
    qr = new QueryRun(q);

    while (qr.next())
    {
        if (qr.changedNo(1))
        {
            inventTrans = qr.getNo(1);
            strTemp = strFmt("%1 , %2", inventTrans.ItemId, inventTrans.itemName());
            //print strTemp;
            info(strTemp);
        }
    }
    pause;
}
======================================================================
static void queryEmpDept(Args _args)

{
Query query;
QueryBuildDataSource queryBuildDataSource1,queryBuildDataSource2;
QueryBuildRange queryBuildRange;
QueryBuildLink queryBuildLink;
QueryRun queryRun;
CustTable deptTrainingTable;
CustTrans empTrainingTable;
;
// Create a new query object
query = new Query();
// Add the first data source to the query
queryBuildDataSource1 = query.addDataSource(tablenum(CustTable));
// Add the range to this first data source
queryBuildRange = queryBuildDataSource1.addRange(fieldnum(CustTable, AccountNum));
// Set the range
queryBuildRange.value("US-021");
// Add the second datasource to the first data source
queryBuildDataSource2 =queryBuildDataSource1.addDataSource(tablenum(CustTrans));
// Add the link from the child data source to the parent data
//source
queryBuildLink = queryBuildDataSource2.addLink(fieldnum(CustTable,AccountNum),fieldnum(CustTrans, OrderAccount));
// Create a new QueryRun object based on the query definition
queryRun = new QueryRun(query);
// Loop through all the records returned by the query
while (queryRun.next())
{
// Get the table data by using the get() method
deptTrainingTable = queryRun.get(tablenum(CustTable));
empTrainingTable = queryRun.get(tablenum(CustTrans));
info (strfmt("AccountNum %1,  Name %2, voucher Id %3, order Account %4 ", deptTrainingTable.AccountNum,deptTrainingTable.name(),empTrainingTable.voucher,empTrainingTable.AmountCur));
}
}