Hi Everyone,
This will be the last post for tonight :)
Ok, when we need to change default behavior for a control (a field), for instance in AR Invoice and Memo screen I would like a Subaccount and a Task to get defaulted from a Project, entered in the header area. Illustrated below:
To achieve it, I will use FieldDefaulting event for Subaccount and Project Task fields in the grid area.
So what I did is added an event for both fields, it had created me a code then I added necessary lines to it.
For the Subaccount:
protected override void ARTran_SubID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
base.ARTran_SubID_FieldDefaulting(sender, e);
var row = (ARTran)e.Row;
var SubID = row.SubID;
PMProject pm = PXSelect<PMProject,
Where<PMProject.baseType, Equal<PMProject.ProjectBaseType>, And<PMProject.nonProject, Equal<False>, And<PMProject.contractID, Equal<Current<ARInvoice.projectID>>, And<PMProject.isTemplate, NotEqual<True>>>>>>.SelectSingleBound(this, new object [] { e.Row });
if (pm != null)
{
//row.SubID = pm.DefaultSubID;
e.NewValue = pm.DefaultSubID;
}
}
For the Task:
protected void ARTran_TaskID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
var row = (ARTran)e.Row;
var TaskID = row.TaskID;
string DefTask = "00";
PMProject pm = PXSelect<PMProject,
Where<PMProject.baseType, Equal<PMProject.ProjectBaseType>, And<PMProject.nonProject, Equal<False>, And<PMProject.contractID, Equal<Current<ARInvoice.projectID>>, And<PMProject.isTemplate, NotEqual<True>>>>>>.SelectSingleBound(this, new object [] { e.Row });
if (pm != null)
{
e.NewValue = DefTask;
}
}
Please take note, I am updating task with 00 value, which is default task in my case.
e.NewValue structure is the correct way of settling new Default value for the control.
As a result:
It is defaulted to what I want on a New Line click :)
All the best,
Sergey.
No comments:
Post a Comment