Enter the key words to find the related topics

Showing posts with label Ax7. Show all posts
Showing posts with label Ax7. Show all posts

Listpage Filter in D365FO

 [ExtensionOf(classStr(SalesTableListPageInteraction))]

final class SalesTableListPageInteraction_Extension

{

    public void initializeQuery(Query _query)

    {

       

        next initializeQuery(_query);

        var qbds = _query.dataSourceTable(tableNum(SalesTable));

        qbds.addRange(fieldNum(SalesTable,SalesStatus)).value(queryValue(SalesStatus::None));

    }


}

AX7 Model import, export, delete using command

 ModelUtil.exe

Usage: ModelUtil.exe -export -metadatastorepath=[path to metadata store] -modelname=[name of the model to export] -outputpath=[path to the folder where the model should be saved]


Usage: ModelUtil.exe -import -metadatastorepath=[path to metadata store where model should be imported] -file=[full path to the file to be imported]


Usage: ModelUtil.exe -replace -metadatastorepath=[path to metadata store where model should be imported] -file=[full path to the file to be imported]


Usage: ModelUtil.exe -delete -metadatastorepath=[path to metadata store] -modelname=[name of the model to delete]


Usage: ModelUtil.exe -importxref -file=[path of xref file to import] -server=[sql server] -database=[database name]

D365 Table Event handler

DataEventType::Inserting 

[DataEventHandler(tableStr(PurchLine), DataEventType::Inserting)]
    public static void PurchLine_onInserting(Common sender, DataEventArgs e)
    {
        PurchLine purchLine = sender as PurchLine;

        if (InventTable::find(purchLine.ItemId).TrackingNum)
        {
            purchLine.TrackNumber =  purchLine.VendAccount + purchLine.PurchId;
        }
    }

DataEventType::Updating

 [DataEventHandler(tableStr(PurchLine), DataEventType::Updating)]
    public static void PurchLine_onUpdating(Common sender, DataEventArgs e)
    {
        PurchLine purchLine = sender as PurchLine;
        if (InventTable::find(purchLine.ItemId).TrackingNum)
        {
            purchLine.TrackNumber =  purchLine.VendAccount + purchLine.PurchId;
        }
        else
        {
            purchLine.TrackNumber =  #EmptyString;
        }
    }

DataEventType::Inserted

 [DataEventHandler(tableStr(RetailCustAffiliation), DataEventType::Inserted)]
    public static void RetailCustAffiliation_onInserted(Common sender, DataEventArgs e)
    {
        RetailCustAffiliation retailCustAffiliation = sender;
        if (retailCustAffiliation.CustAccountNum)
}



D365 Form Event Handler

FormControlEventType::Clicked

[FormControlEventHandler(formControlStr(CustOpenTrans, MarkOrderTotal), FormControlEventType::Clicked),

 public static void MarkOrderTotal_OnClicked(FormControl sender, FormControlEventArgs e)
{
        FormRun                     formRun = sender.formRun() as FormRun;
        FormRun                     formRunParent = formRun.args().caller();
        Common                      originator = formRun.args().record();
        FormDataSource         custTransOpen_ds = formRun.dataSource('CustTransOpen');
       CustTransOpen            custTransOpen = custTransOpen_ds.cursor();

}

FormControlEventType::Lookup

    [FormControlEventHandler(formControlStr(SalesTable, SalesLine_TruckShipmentId), FormControlEventType::Lookup),
    SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]
    public static void SalesLine_TruckShipmentId_OnLookup(FormControl sender, FormControlEventArgs e)
{
      SalesLine               salesLine = sender.dataSourceObject().cursor();
}

FormDataSourceEventType::Activated 

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated),
    SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]
    public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
           SalesLine                   salesLine;


           salesLine = sender.cursor();

}

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated) ]
    public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormRun formRun  = sender.formRun();
        SalesTable saleTable;
   
        FormDataSource salesTableDS    = formRun.dataSource(formDataSourceStr(SalesTable, SalesTable)) as FormDataSource;
        saleTable = salesTableDS.cursor();
}

FormDataFieldEventType::Modified

 [FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, DlvMode), FormDataFieldEventType::Modified)]
    public static void DlvMode_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
        SalesLine                   salesLine;

        salesLine = sender.datasource().cursor();
}

Form field mandatory

 [FormDataFieldEventHandler(formDataFieldStr(SalesTable, FreightThirdPartyBilling, FreightBillAccount), FormDataFieldEventType::Modified) ]
    public static void FreightBillAccount_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
        FormDataSource                  thirdPartyBillingDS;
        FreightThirdPartyBilling     thirdPartyBilling;
        boolean                                 allowEdit;
        FormStringControl               cityCtrl;         
     
        thirdPartyBillingDS = sender.datasource();
        thirdPartyBilling = sender.datasource().cursor();
     
        cityCtrl = thirdPartyBillingDS.formRun().design().controlName(formControlStr(SalesTable,FreightThirdPartyBilling_City));
        cityCtrl.mandatory(allowEdit);
     
}


Form field modified and inserting into fields based on record.

 [FormDataFieldEventHandler(formDataFieldStr(PurchTable, PurchTable, VendFactoryAddress), FormDataFieldEventType::Modified)]
    public static void VendFactoryAddress_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        LogisticsPostalAddress    logisticsPostalAddress;
        int64                               factoryAdress;

        factoryAdress      = sender.getValue();
   
        select firstonly logisticsPostalAddress where logisticsPostalAddress.RecId == factoryAdress;
        sender.datasource().object(fieldNum(PurchTable, CountryRegId)).setValue(logisticsPostalAddress.CountryRegionId);
        sender.datasource().object(fieldNum(PurchTable, TransactionCode)).setValue(logisticsPostalAddress.TransactionCode);
        sender.datasource().object(fieldNum(PurchTable, Port)).setValue(logisticsPostalAddress.PortId);
        sender.datasource().object(fieldNum(PurchTable, IntermediaryCode)).setValue(logisticsPostalAddress.IntermediaryCode);

     
    }

Form method Post event Handler

[PostHandlerFor(formStr(SalesTable), formMethodStr(SalesTable, enableTMSFields))]
    public static void SalesTable_Post_enableTMSFields(XppPrePostArgs args)
 {
        FormRun salesTableForm  = args.getThis();
        Common common = salesTableForm.args().record();
       SalesTable  salesTab;
 FormStringControl   carrierCode  = salesTableForm.design(0).controlName(formControlStr(SalesTable, TMSSalesTable_CarrierCode));

        FormDataSource tmsSalesTableDatasource    = salesTableForm.dataSource(formDataSourceStr(SalesTable, TMSSalesTable)) as FormDataSource;
salesTab = salesTableDS.cursor();
}

FormDataSourceEventType::SelectionChanged

[FormDataSourceEventHandler(formDataSourceStr(LogisticsPostalAddressGrid, DirPartyPostalAddressView), FormDataSourceEventType::SelectionChanged)]
    public static void DirPartyPostalAddressView_OnSelectionChanged(FormDataSource sender, FormDataSourceEventArgs e)
    {
        var formRun = sender.formRun() as FormRun;
        str callerFormName = formRun.args().caller().Name();

        if(callerFormName == formStr(Decorator)) 
        {
            var dirPartyPostalAddDatasource = formRun.dataSource(formDataSourceStr(LogisticsPostalAddressGrid, DirPartyPostalAddressView)) as FormDataSource;
            if( dirPartyPostalAddDatasource.numberOfRowsLoaded() > 0 )
            {
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, NewAddress))).enabled(false);
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, MoreOptions))).enabled(false);
            }
            else
            {
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, NewAddress))).enabled(true);
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, MoreOptions))).enabled(true);
            }
        }
    }



D365 Best practice warring

If we get BP warring regarding parameter "e" is not used in coding part we can set below attribute in the method.

SuppressBPWarning('BPParameterNotUsed', 'Parametr e not used')

Example:
 [DataEventHandler(tableStr(PurchLine), DataEventType::Updating),
     SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]
    public static void PurchLine_onUpdating(Common sender, DataEventArgs e)
    {
}

D365 Table browser from URL(Work Space)

Add "sysTableBrowser&tableName=SalesLine" after mi= as shown below.

https://edev-waazd365.sandbox.operations.dynamics.com/?cmp=SMC&mi=sysTableBrowser&tableName=SalesLine

Customization Analysis Report D365 F & O

Customization analysis report provides the details about Customizations, Overlayered code, extenstions, Errors , warnings etc.


 Syntax:

The syntax is as follows

xppbp.exe -metadata="LocalPackagesFolder" -all -model="ModelName" -xmlLog="LogLocation" -module="PackageName" -car="ReportLocation"



Example:
xppbp.exe -metadata=C:\AosService\PackagesLocalDirectory -all -model="Foundation" -xmlLog=C:\Temp\BPCheckLogcd.xml -module="ApplicationSuite" -car=C:\Temp\CustomizationAnalysisReport_Foundation.xlsx

D365/AX7 Form Event Handlers



FormControl LookUp:



[FormControlEventHandler(formControlStr(SalesTable, DiplItemProductType), FormControlEventType::Lookup)]

public static void DiplItemProductType_OnLookup(FormControl sender, FormControlEventArgs e)
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), sender);

QueryBuildDataSource            qbdsProduct,qbdsInvent;
Query                                        query;
FormRun                                   formRun;
FormControl                              formCtrl;
           formRun = sender.formRun();
           formCtrl = formRun.design().controlName(formControlStr(SalesTable, DiplItemProductType));

           query           = new Query();qbdsInvent = query.addDataSource(tableNum(InventTable));
           qbdsProduct = qbdsInvent.addDataSource(tableNum(EcoResProduct));
           qbdsProduct.addLink( fieldNum(InventTable, Product), fieldNum(EcoResProduct, RecId));
          qbdsProduct.addRange(fieldNum(EcoResProduct, ProductType)).value(SysQuery::value  (EcoResProductType::Service));

          sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId), true);
          sysTableLookup.addLookupfield(fieldNum(InventTable, ItemType), true);
          sysTableLookup.parmQuery(query);
          sysTableLookup.performFormLookup();

 }  

FormControl Modified:



[FormControlEventHandler(formControlStr(SalesTable, SalesLine_ItemId), FormControlEventType::Modified)]
public static void SalesLine_ItemId_OnModified(FormControl sender, FormControlEventArgs e)

{
FormRun              element = sender.formRun();
FormControl        itemidctrl = element.design(0).controlName("SalesLine_ItemId");
FormDataSource SalesLine_ds = element.dataSource(formDataSourceStr(SalesTable, SalesLine)) as FormDataSource;
SalesLine           salesLine = SalesLine_ds.cursor();
salesLine.DiplItemId = itemidctrl.valueStr();
}

Modified method for unbound controls of a form

Grid field appear/disappear based on  field status


My scenario : Based on unbound enum field in form, grid field should be apper/disapper.

Solution: I have copied onmodified event for filed and created and pasted in new class as shown below.

class DIPLCustomerEH
{

 [FormControlEventHandler(formControlStr(DIPLCustomer, DIPLCustomer_AccountType), FormControlEventType::Modified)]

public static void DIPLCustomer_AccountType_OnModified(FormControl sender, FormControlEventArgs e)
{
 
FormRun element = sender.formRun();
FormComboBoxControl schemactrl = element.design(0).controlName("DIPLCustomer_AccountType");
FormDataSource DIPLCustomer_ds = element.datasource(FormDataSourcestr(DIPLCustomer,DIPLCustomer)) as FormDataSource;
 
FormDataObject schema = DIPLCustomer_ds.object(fieldNum(DIPLCustomer, Sechema));
 
if(schemactrl.selection() == DIPLAccountType::Debit)
{

schema.visible(false);
}
else
 
{
schema.visible(true);
}
  }

}








  

Composite Entity in D365


Create new project from Visual Studios.

Navigate to File->New->Project.

Name it as CR_CustomEntity.

Navigate to Solution Explorer, right click on Project, select New Item under Add.

Select Table under Data Model (Operations Artifacts).

Name it as DICustTable.

Add two fields
  • ID(string)
  • Name(string)
Create Index name it as IDX, add ID field in that.

Change Primarykey property to IDX .



Now create second table name it as DICustInfo.

Add two fields.
  •  ID
  • Address
Create Index name it as IDX, add ID field in that.

Change Primarykey property to IDX .

Create Normal relation name it as DICustTable, as shown below.


Set the properties as shown below.






Now right on DICustTable, select Create data entity under Add-ins, as show below.



After clicking , staging table, security privileges, entity are created.

Table
  • DICustTableStaging
Security privileges
  • DICustTableEntityMaintain
  • DICustTableEntityView
Data Entities
  • DICustTableEntity

Now Similarly, do for DICustInfo same as DICustTable.

After completion  staging table, security privileges, entity are created.

Table
  • DICustInfoStaging
Security privileges
  • DICustInfoEntityMaintain
  • DICustInfoEntityView
Data Entities
  • DICustInfoEntity

See below picture for clear image.



Now create below two fields in two Staging tables(DICustTable, DICustInfo)

  • RowId(Integer)
  • ParentRowId(Integer)
Now create new foreignKeyRelation on DICustInfoStaging table, add field relations as shown below.




 Set below properties




Now navigate to solution explorer, right click select new item under Add.

Select Composite Data Entity under Data Model (Operations Artifacts).

Name it as DICompositeEntity.

Now right click on DICompositeEntity, select New Root  Data Entity Reference



Set the below properties.


Now again right click on DICustTableEntity, select New Embedded Data Entity Reference, set the below properties.




Now you can Import and Export from User Interface .