Sunday, 30 August 2020

CustTable and DirAddressBookParty relation in D365 and Sql

 CustTable and DirAddressBookParty  relation in D365 and Sql

DirAddressBookParty       dirAddressBookParty;

        DirAddressBook                   dirAddressBook;

        CustTable                              custTable;

   select RecId,Party from custTable

            where custTable.AccountNum==this.CustomerAccount;


     select RecId from dirAddressBook 

            where dirAddressBook.Name==this.CountryCode;


             select RecId from dirAddressBookParty

                    where  dirAddressBookParty.Party==custTable.Party && dirAddressBookParty.AddressBook==dirAddressBook.RecId;

SQL query

select DISTINCT DirPartyLocation.PARTY,DirAddressBook.RECID,5637144576 from LogisticsPostalAddress
join DirPartyLocation on DirPartyLocation.LOCATION=LogisticsPostalAddress.LOCATION
Join LOGISTICSLOCATION on LOGISTICSLOCATION.RECID=LogisticsPostalAddress.LOCATION
join DirAddressBook on DirAddressBook.NAME=LogisticsPostalAddress.COUNTRYREGIONID
where DirPartyLocation.ISPRIMARY=1 and party in (select party from CUSTTABLE)
and LOGISTICSLOCATION.ISPOSTALADDRESS=1 and DirPartyLocation.ISPOSTALADDRESS=1 and DirPartyLocation.POSTALADDRESSROLES='Business'
and not exists (select 1 from DirAddressBookParty where DirAddressBookParty.PARTY=DirPartyLocation.PARTY and DirAddressBookParty.ADDRESSBOOK=DirAddressBook.RECID)
 and LogisticsPostalAddress.VALIDTO >=GETDate()

Wednesday, 12 August 2020

DataEventType::MappedEntityToDataSource in D365

DataEventType::MappedEntityToDataSource in D365

[DataEventHandler(tableStr(MyTableEntity), DataEventType::MappedEntityToDataSource)]

public static void MyTableEntity_onMappedEntityToDataSource(Common _sender, DataEventArgs _eventArgs)

{

    DataEntityContextEventArgs eventArgs = _eventArgs;

    MyTableEntity entity = _sender;

    if (eventArgs.parmEntityDataSourceContext().name() == dataEntityDataSourceStr(MyTableEntity, MyTable))

    {

        MyTable myTable = eventArgs.parmEntityDataSourceContext().getBuffer();

        ... write your logic here

    }

}


Thanks,

Vikas  Mehta.

FormEventType::Closing in d365

 FormEventType::Closing


Example on formeventtype:closing

 [FormEventHandler(formStr(FormName), FormEventType::Closing)]
    public static void FormNamee_OnClosing(xFormRun sender, FormEventArgs e)
    {
        FormDataSource datasource_ds    = sender.dataSource(formDataSourceStr(FormName, DataSourceName));
        TableName      buffTable        = datasource_ds.cursor();
    }


Example 2. Form DataSource while closing the form (same will apply for OnInitialized,
[FormEventHandler(formStr(EcoResAttributeValue), FormEventType::Closing)]
public static void EcoResAttributeValue_OnClosing(xFormRun sender, FormEventArgs e)
{
     FormDataSource ecoResProduct_ds   =          sender.dataSource(formDataSourceStr(EcoResAttributeValue, EcoResProductAttributeValue));
      EcoResProductAttributeValue      ecoResAttributeValue = ecoResProduct_ds.cursor();
<YOUR CODE>
}   

example 3
class HRIHcmWorkerPositionsFormEvents
{
    [FormEventHandler(formStr(HcmWorkerPositions), FormEventType::Closing)]
    public static void HcmWorkerPositions_OnClosing(xFormRun sender, FormEventArgs e)
    {
        FormRun         element = sender;
        FormRun         formrun;
        FormDataSource  formDatasource;
        int             idx;
        str             name;

        formrun = element.args().caller();

        name = element.args().callerName();

        if(formrun && name == 'hcmWorker')
        {            
            for(idx=1;formrun.dataSourceCount();idx++)
            {
                if(formrun.dataSource(idx).cursor() is HcmEmploymentDetail)
                {
                    formDatasource = formrun.dataSource(idx);
                    formDatasource.research(true);
                    break;
                }
            }
        }
    }

}

Thanks,
Vikas Mehta


FormDataSourceEventType::Activated in d365

FormDataSourceEventType::Activated in d365

WRITE THE BELOW CODE IN NEW CLASS OR ANY OTHER CLASS.

MAKE SURE THAT YOU USE THE METHOD SIGNATURE PROPERLY.
EXAMPLE
class CustTableFormEventHandler
{
    [FormDataSourceEventHandler(formDataSourceStr(CustTable, CustTable), FormDataSourceEventType::Activated)]
    public static void CustTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        CustTable           custTable     = sender.cursor(); //selected record
        FormDataSource      custTable_ds  = sender.formRun().dataSource("CustTable"); //DataSource 
        FormRun             element       = sender.formRun(); //form element
        FormControl         myNewButton   = element.design(0).controlName("MyNewButton"); 
//button on the form
        myNewButton.enabled(false); // enabled or disabled the button
    }
}


another example
[FormDataSourceEventHandler(formDataSourceStr(HRMCompFixedEmpl, HRMCompFixedEmpl), FormDataSourceEventType::Activated)]
public static void HRMCompFixedEmpl_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
HRMCompFixedEmpl compFixedEmpl = sender.cursor();
FormDataSource hrmCompFixedEmpl_ds = sender.formRun().dataSource(“HRMCompFixedEmpl”);
FormRun element = sender.formRun();
FormControl control1= element.design(0).controlName(“HRMCompFixedEmpl_field”);

if(compFixedEmpl.Status == NoYes::Yes)
{
control1.enabled(true);
}
else
{
control1.enabled(false);
}

}

Thanks,
Vikas Mehta

FormDataSourceEventType::InitValue in D365

 FormDataSourceEventType::InitValue in D365

    [FormDataSourceEventHandler(formDataSourceStr(FormName, DataSourceName), FormDataSourceEventType::InitValue)]
    public static void DataSourceNames_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e
    {
        FormRun          formRun             = sender.formRun();
        FormDataSource   DataSourceName_ds   = formRun.dataSource(formDataSourceStr(FormName,DataSourceName)) as FormDataSource;
        TableName        buffTable           = DataSourceName_ds.cursor();

    }


Thanks,
Vikas Mehta.

FormDataSourceEventType::Written in d365

FormDataSourceEventType::Written in d365

[FormDataSourceEventHandler(formDataSourceStr(MyForm, MyRandomTableDS), FormDataSourceEventType::Written)]

public static void MyRandomTableDS_OnWritten(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun() as FormRun;
//intellisense might not work in some cases over here.
formRun.myCustomMethod();
}

Thanks,
Vikas Mehta.

FormDataFieldEventType::Validating in D365

FormDataFieldEventType::Validating in D365

/// <summary>
/// Prevent changing the start mileage field on the FMRental form to a value that is equal to 1
/// </summary>
[FormDataFieldEventHandler(formDataFieldStr(FMRental, FMRental, StartMileage), FormDataFieldEventType::Validating)]
public static void StartMileage_OnValidating(FormDataObject sender, FormDataFieldEventArgs e)
{
    var dataObject = sender as FormDataObject;
    var args = e as FormDataFieldCancelEventArgs;
    if (args != null && dataObject != null)
    {
        var datasource = dataObject.datasource() as FormDataSource;
        if (datasource != null)
        {
            FMRental record = datasource.cursor() as FMRental;
            if (record.RecId > 0)
            {
                if (record.StartMileage == 1 )
                {
                    boolean doCancel = !checkFailed("Start Mileage = 1 is not allowed");
                    args.cancel(doCancel);
                }
            }
        }
    }
}

Thanks,
Vikas Mehta.

FormDataSourceEventType::ValidatingWrite in d365

 FormDataSourceEventType::ValidatingWrite in d365

/// <summary>

/// When saving a new rental, prevent setting the start mileage on the FMRental 

/// </summary>

[FormDataSourceEventHandler(formDataSourceStr(FMRental, FMRental), FormDataSourceEventType::ValidatingWrite)]

public static void FMRental_OnValidatingWrite(FormDataSource sender, FormDataSourceEventArgs e)

{

    var datasource = sender as FormDataSource;

    var args = e as FormDataSourceCancelEventArgs;

    if (args != null && datasource != null)

    {

        FMRental record = datasource.cursor() as FMRental;

        if (record.recId == 0)

        {

            if(record.startmileage == 1)

            {

                boolean doCancel = !checkFailed("Start Mileage = 1 is not allowed");

                args.cancel(doCancel);

            }

        }

    }

}


thanks,

Vikas Mehta.

DataEventType::ValidatedField in d365

 DataEventType::ValidatedField in d365

[DataEventHandler(tableStr(FMVehicle), DataEventType::ValidatedWrite)] public static void FMVehicle_onValidatedWrite(Common sender, DataEventArgs e) { ValidateEventArgs validateArgs = e as ValidateEventArgs; FMVehicle vehicle = sender as FMVehicle; boolean result = validateArgs.parmValidateResult(); if (vehicle.NumberOfCylinders > 8) { result = checkFailed("Invalid number of cylinders."); validateArgs.parmValidateResult(result); } }


Thanks,

Vikas Mehta





Wednesday, 5 August 2020

The menu item with name table could not be opened

The menu item with name table could not be opened.


On running a menu item many times we get the error stating that the 
"The menu item with name XX could not be opened."
The menu item with name XXX could not be opened.menu item could not be opened,menu item not opened,D365 menu item error,AX 2012 menu item with name,

this can be resolved by doing a full build with synchronization.
However before trying for full build , I would suggest that you do the below steps.
1) refresh the menu items and forms involved
if this does not work then 

1) clean solution
2) rebuild solution with synchronization.
3) reset usage data 
give it a try if it does not work then do a full build with Sync + iisreset

Thanks,
Vikas 

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++  Introduction In our previous posts, we explored what Copilot can do o...