The requirement is to add the dimension controller to the AFZInventJournal web control that i have created.
To display the dimension control against an EP form we have to reuse a component already provided for the same. The name of the web control meant for this purpose is called DimensionDefaultingEPController. At this point it is important to note how a user control can be used within another user control. This involves two steps
in this example we are going to embed two user controls into the main control. These are detailed below. We also need to ensure is that permissions are provided to the embedded control in the main control. Select the main control and navigate to the Permissions - Delete node, and add the component to be reused as shown below
Next open AFZInventJournal web control in Visual Studio for edit. Find the component to be embedded (DimensionDefaultingEPController) in the AOT explorer and add it to the project. When this is done both the AFZInventJournal and DimensionDefaultingEPController will be available in the same project
It is also important at this stage that we add reference to the application proxy object. The application proxy is a wrapper class created in dot net and used to call a class function of any AX class.
A step by step process to create a proxy object is Create Proxies for EP User Control
The user control (parent control) that would host the DimensionControl should also extend AxBaseUserControl and the class declaration for the same should look as below
public partial class AFZInventJournal : AxBaseUserControl
{
Now switch to the layout mode of the user control and figure our a section where you wish to have the dimension control displayed please add the below as shown below
The layout of the screen at this stage would be as follows:
Add a reference to the EP Proxy object as that is used in the DimensionController user control.
We are now ready to start addressing the dimension related requirements on the EP form. The typical requirement would be to display and save the dimensions values. To display the dimension the RecId stored in the default dimension columns should be passed on to the user control.
At this stage it is important to understand that if a column is not bound with a control then by default the value of that column will not be fetched in the dataset. To ensure that all field values of a dataset are fetched (irrespective of being bound) the data set property OnlyFetchActive should be set to false. Screen shot below
We first create a function a relation between the child user control and parent. For this select the user control presentation on the form and define the creating controller function as follows
Double click the CreatingController event and write the below code
protected void DimensionAttributesControl_CreatingController(object sender, EventArgs e)
{
DimensionAttributesControl.Controller = DimensionDefaultingController;
}
Next we create two functions to display and save the dimension
///
/// Copy current dimension to CustTable
///
protected void SaveDimension()
{
// retrieve the ID of the DimensionAttributeValueSet record that is associated with default values
// currently displayed
long newDimensionAttributeValueSetId = DimensionAttributesControl.DimensionCombinationId;
DataSetViewRow row = this.CurrentRow;
if (row != null)
{
row.SetFieldValue("DefaultDimension", newDimensionAttributeValueSetId);
}
}
///
/// the below method is used to read the defautlDimension RecID and bind it with the DimensionDisplayEpController
///
protected void displayDimension()
{
long dimensionAttributeValueSetId = 0;
DataSetViewRow row = this.CurrentRow;
if (row != null)
{
// get the DimensionAttributeValueSet record ID associated with the current record
dimensionAttributeValueSetId = (long)row.GetFieldValue("DefaultDimension");
}
// specify the DimensionAttributeValueSet record from which to display the default values
if (dimensionAttributeValueSetId != 0)
{
DimensionAttributesControl.DimensionCombinationId = dimensionAttributeValueSetId;
}
}
///
/// Returns the current row
///
private DataSetViewRow CurrentRow
{
get
{
try
{
DataSetView dsv = this.AxDSInventJournalTrans.GetDataSet().DataSetViews["InventJournalTrans_1"];
return (dsv == null) ? null : dsv.GetCurrent();
}
// CurrentRow on the dataset throws exception in empty data scenarios
catch (System.Exception)
{
return null;
}
}
}
Once this is done we need to call the display and save functions at the right events and the process is complete !!
protected override void OnPreRender(EventArgs e)
{
if (!Page.IsPostBack)
{
displayDimension();
}
base.OnPreRender(e);
}
protected void GridInventJournalTrans_SelectedIndexChanged(object sender, EventArgs e)
{
displayDimension();
}
To display the dimension control against an EP form we have to reuse a component already provided for the same. The name of the web control meant for this purpose is called DimensionDefaultingEPController. At this point it is important to note how a user control can be used within another user control. This involves two steps
- Drag the user control to be embedded from the AOT browser to the project.
- Include a reference to the added user control in the parent web control markup using a tag as follows:
in this example we are going to embed two user controls into the main control. These are detailed below. We also need to ensure is that permissions are provided to the embedded control in the main control. Select the main control and navigate to the Permissions - Delete node, and add the component to be reused as shown below
Next open AFZInventJournal web control in Visual Studio for edit. Find the component to be embedded (DimensionDefaultingEPController) in the AOT explorer and add it to the project. When this is done both the AFZInventJournal and DimensionDefaultingEPController will be available in the same project
A step by step process to create a proxy object is Create Proxies for EP User Control
The user control (parent control) that would host the DimensionControl should also extend AxBaseUserControl and the class declaration for the same should look as below
public partial class AFZInventJournal : AxBaseUserControl
{
Now switch to the layout mode of the user control and figure our a section where you wish to have the dimension control displayed please add the below as shown below
The layout of the screen at this stage would be as follows:
Add a reference to the EP Proxy object as that is used in the DimensionController user control.
We are now ready to start addressing the dimension related requirements on the EP form. The typical requirement would be to display and save the dimensions values. To display the dimension the RecId stored in the default dimension columns should be passed on to the user control.
At this stage it is important to understand that if a column is not bound with a control then by default the value of that column will not be fetched in the dataset. To ensure that all field values of a dataset are fetched (irrespective of being bound) the data set property OnlyFetchActive should be set to false. Screen shot below
We first create a function a relation between the child user control and parent. For this select the user control presentation on the form and define the creating controller function as follows
Double click the CreatingController event and write the below code
protected void DimensionAttributesControl_CreatingController(object sender, EventArgs e)
{
DimensionAttributesControl.Controller = DimensionDefaultingController;
}
Next we create two functions to display and save the dimension
///
/// Copy current dimension to CustTable
///
protected void SaveDimension()
{
// retrieve the ID of the DimensionAttributeValueSet record that is associated with default values
// currently displayed
long newDimensionAttributeValueSetId = DimensionAttributesControl.DimensionCombinationId;
DataSetViewRow row = this.CurrentRow;
if (row != null)
{
row.SetFieldValue("DefaultDimension", newDimensionAttributeValueSetId);
}
}
///
/// the below method is used to read the defautlDimension RecID and bind it with the DimensionDisplayEpController
///
protected void displayDimension()
{
long dimensionAttributeValueSetId = 0;
DataSetViewRow row = this.CurrentRow;
if (row != null)
{
// get the DimensionAttributeValueSet record ID associated with the current record
dimensionAttributeValueSetId = (long)row.GetFieldValue("DefaultDimension");
}
// specify the DimensionAttributeValueSet record from which to display the default values
if (dimensionAttributeValueSetId != 0)
{
DimensionAttributesControl.DimensionCombinationId = dimensionAttributeValueSetId;
}
}
///
/// Returns the current row
///
private DataSetViewRow CurrentRow
{
get
{
try
{
DataSetView dsv = this.AxDSInventJournalTrans.GetDataSet().DataSetViews["InventJournalTrans_1"];
return (dsv == null) ? null : dsv.GetCurrent();
}
// CurrentRow on the dataset throws exception in empty data scenarios
catch (System.Exception)
{
return null;
}
}
}
Once this is done we need to call the display and save functions at the right events and the process is complete !!
protected override void OnPreRender(EventArgs e)
{
if (!Page.IsPostBack)
{
displayDimension();
}
base.OnPreRender(e);
}
protected void GridInventJournalTrans_SelectedIndexChanged(object sender, EventArgs e)
{
displayDimension();
}
No comments:
Post a Comment