Показаны сообщения с ярлыком Ax7. Показать все сообщения
Показаны сообщения с ярлыком Ax7. Показать все сообщения

вторник, 30 июля 2019 г.

How to filter record by dimension values in D365


Hi all,

It's been a long time I wrote the post in my blog. But today I will fresh it by writing the new one.

I got a task - to filter the query on worker's default dimension fields. This was quite challenging for me.
First I did it via DimensionAttributeValueSetStorage class.  It didn't feet the requirement because the functionality has to have a possibility to filter records via any of the dimensions (Division, Location, CostCenter, Department, etc).
Next, I found an article about DimensionsProvider class which has some sort of abilities that I was needed. And I used it.

It worked as expected and as required!

So, below I provided a piece of code which you can interpret for your requirements, but I believe the general concept will be clear:

private void filterResourcesByDimensions(Query _q)
    {
        Counter                             i;
        DimensionAttribute                  dimensionAttribute;
        str                                 dimValue;
        container                           workerDefaultDimension, workerDefaultDimensionVal;
        QueryBuildDataSource                qbdsResource;
        
        DimensionProvider                   dimProvider = new DimensionProvider();

        workerDefaultDimension = ['Division', 'Location', 'Region', 'ServiceLine', 'SubService'];

        workerDefaultDimensionVal = [_context.division(),
                                    _context.location(),
                                    _context.region(),
                                    _context.serviceLine(),
                                    _context.subService()
                                    ]; //Dimensions values (any)

        qbdsResource = _q.dataSourceTable(tableNum(ResCompanyResourceView));
   
        for (i = 1; i <= conLen(workerDefaultDimension); i++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(workerDefaultDimension,i));
       
            if (dimensionAttribute.RecId == 0 && conpeek(workerDefaultDimensionVal, i) == '')
            {
                continue;
            }
       
            dimValue = conPeek(workerDefaultDimensionVal,i);
       
            if (dimValue != "")
            {
                dimProvider.addAttributeRangeToQuery(_q, qbdsResource.name(), identifierStr(DefaultDimension), DimensionComponent::DimensionAttribute, dimValue, dimensionAttribute.Name);
            }
        }
    }

Feel free to contact if you still have any questions! I'm

воскресенье, 26 февраля 2017 г.

Event handler for form datasource ax7

Hi, dear readers!
Recently I've had new task for Ax7, namely, I had to change behavior of one control on form. For this I must not customize current form, but extend it and create event handler to handle it. This was I done.
And below I just wanted to share with you some thoughts about  how we could do it faster and easier:

[FormDataSourceEventHandler(formDataSourceStr(WHSShipmentDetails, WHSShipmentTable), FormDataSourceEventType::Activated)]
    public static void WHSShipmentTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        WHSShipmentTable    shipmentTable = sender.cursor();  // our Args.record()
        //FormDataSource      shipmentDs = sender.formRun().dataSource(tableNum(WHSShipmentTable));      // in that way we could get DataSource to manipulate ds fields for example.
        FormControl         printConfirmControl = sender.formRun().design(0).controlName("ConfirmAndPrintShipmentRun"); //get control to change behavior
                printConfirmControl.enabled(WHSShipConfirm::isShipConfirmEnabledForShipment(shipmentTable));
    }

After creating new class, build the project and verify whether your event handler works or not.

Hope it'd be helpful!

Looking forward to seeing with you in new posts!