Wednesday 15 November 2023

Insert/Update or remove the default dimension value in D365 FSCM via x++

Use below method to insert/update the dimension values, just pass the parameter values to the method and it will return the updated value:

public static DimensionDefault setDefaultDimension(Name             _dimensionName,

                                                          DimensionValue   _dimensionValue,

                                                          DimensionDefault _defaultDimension)

    {

        DimensionAttributeValueSetStorage   dimStorage = new DimensionAttributeValueSetStorage();

        DimensionAttribute                  dimAttribute;

        DimensionAttributeValue             dimAttributeValue;

        DimensionValue                      dimensionValue;

        DimensionDefault                    defaultDimension = _defaultDimension;

           

        if (_dimensionValue) //If dimension value is there then insert or update it. 

        {

            ttsBegin;

            dimStorage          = DimensionAttributeValueSetStorage::find(defaultDimension);

            dimAttribute        = DimensionAttribute::findByName(_dimensionName);

            dimAttributeValue   = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute, _dimensionValue, true, true);

            dimStorage.addItem(dimAttributeValue);

            defaultDimension = dimStorage.save();

            ttsCommit;

        }

        else if (!_dimensionValue) //If dimension value is not there then remove it.

        {

            ttsBegin;

            dimStorage          = DimensionAttributeValueSetStorage::find(defaultDimension);

            dimAttribute        = DimensionAttribute::findByName(_dimensionName);

            dimensionValue      = ProjProjectV2Entity::FindDefaultDimensionVal(_dimensionName, _defaultDimension);// This method is defined below

            dimAttributeValue   = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute, dimensionValue, true, true);

            dimStorage.removeDimensionAttributeValue(dimAttributeValue.RecId);

            defaultDimension = dimStorage.save();

            ttsCommit;

        }

        return defaultDimension;

    }

    /// <summary>

    /// Find the dimension value

    /// </summary>

    /// <param name = "_dimensionName">

    /// Dimension name

    /// </param>

    /// <param name = "_defaultDimension">

    /// Default dimension value

    /// </param>

    /// <returns>

    /// Dimension value

    /// </returns>


    public static DimensionValue findDefaultDimensionVal(Name             _dimensionName,

                                                            DimensionDefault _defaultDimension)

    {

        DimensionAttributeValueSetStorage   dimStorage;

        DimensionValue                      dimensionValue;

        Counter                             i;

        dimStorage = DimensionAttributeValueSetStorage::find(_defaultDimension);

        for (i= 1 ; i<= dimStorage.elements() ; i++)

        {

            if (DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == _dimensionName)

            {

                dimensionValue = dimStorage.getDisplayValueByIndex(i);

            }

        }

        return dimensionValue;

    }

Tuesday 8 August 2023

Create Multi User Printer Setup to print multiple reports at a same time

 Hi all, in this post I'm going to talk about how we create a setup where different user can select different printers according to their requirements which then prints reports for multiple records.

I have created a setup where user can print all the work orders for a production wave and these reports will be routed to the printer selected by the user in the setup below:


Step 1: Create a table with 2 fields (Printer Name and UserId) and create relations as in below screenshot:




Step 2: Now create form menu item and privileges for this table, once form is created, then user can select their favorite printer against their user Id, so next time they print specific reports then it will go to the selected printer only:





Step 3: Now create a controller class to apply the logic to your specific reports, as in below screenshot:




Insert/Update or remove the default dimension value in D365 FSCM via x++

Use below method to insert/update the dimension values, just pass the parameter values to the method and it will return the updated value: p...