Thursday, July 6, 2023

Add Range In Default Dimension , D365 , X++

 I am going to show you How You can add range in any default dimension .

If it it standard form where you want to add range then you have to create COC of that form's dataSource which contains DefaultDimension Field. 

In my example I am adding range in Default Dimension "Project" in  Revenue Recognition Schedule(RevRecDefferredLine) Form  . I want to show just that particular record whose projectId matches the string control named "ProjIdFilter" whice I added in my form through form extension


Create the COC of RecRecDefferredLine form's datasource "NetDefferredLine" beacase my default dimension field is in NetDefferredLine datasource and paste below code


[ExtensionOf(formDataSourceStr(RevRecDeferredLine , NetDeferredLine))]
final class MZNKARevRecDeferredLineDS_Extension
{
    public void executeQuery()
    {

        FormRun                 fr = this.formRun();
        FormStringControl       projectIdFilter = fr.design(0).controlName(formControlStr(RevRecDeferredLine , ProjIdFilter));
        DimensionProvider       dimensionProvider = new DimensionProvider();
		
        dimensionProvider.clearDimensionRangesFromQuery(
				this.query());


        dimensionProvider.addAttributeRangeToQuery(
				this.query(),
				this.name(),
				fieldStr(RevRecDeferredLine, DefaultDimension),
				DimensionComponent::DimensionAttribute,
				ProjectIdFilter.valueStr(),
				"D05_ActivityName");
 
 
        next executeQuery();
    }
}


Explanation:
What this code does is to set the range of default dimension named "Project" with the filter string which I added in form

DimensionProvider dimensionProvider = new DimensionProvider();

It will call the constructor of class DimensionProvider


 dimensionProvider.clearDimensionRangesFromQuery(
				this.query());
This line will clear the already applied ranges

 dimensionProvider.addAttributeRangeToQuery(
				this.query(),
				this.name(),
				fieldStr(RevRecDeferredLine, DefaultDimension),
				DimensionComponent::DimensionAttribute,
				ProjectIdFilter.valueStr(),
				"Project");
This code does the actual work 
First argument is the Query name 
Second argument is the datasource name of which you are adding range
3rd argument is the default dimension field 
4th argument is to specify that it is default dimension
5th argument is the string which you want to filter 
6th argument is the that specific default dimension name I my case I am applying range in "Project" dimension

No comments:

Post a Comment

Change SSRS Report Design Based On Condition , D365 ,X++

 To change Sales Invoice control document's design based on condition use following code. Here I have created COC of salesInvoiceControl...