In the vendor payment journal lines > Marked settlement transaction tab, I have t add a form part that will list the attachments for the invoice linked to the TmpCustVendTrans record selected in the grid.
I extended VendShowSpecifikation form to call a refresh of my form part on-selectionchanged. My form part's datasource is DocuRef with DocuValue inner-joined.
As long as there is only one attachment linked to the invoice (TmpCustVendTrans.InvoiceId > VendInvoiceJour), then it updates the container correctly on each selection changed of the grid onVendShowSpecifikation (datasource TMpcustVendTrans).
However the moment there ate more than one attachment to the invoice, then I have to add tot he formpart the docuRef.Name and then the user has to click in the formpart on this column for it to refresh the container.
If there is more than one TmpCustVendTrans in the grid and some has 2 attachments and other one, then the record with the 1 attachment will show correctly.
However if there are 2 rows with each 2 attachments, then if it's the 1st row, it shows the names of both attachments but only the first one will have the container populated.
I have to click on the name of the 2nd attachment for it to populate the container.
Then when I go to the next row in VendShowSpecifikation grid which also have 2 attachments, then the first attachment will populate its container with the correct attachment. However the 2nd attachment name will still show the previous selection's 2nd attachment even though the name will be that of the current selected row. I have to click on the name for it to populate the container correctly.
The properties of the container in my form part is the same as what is in standard DocuView form.
So how can I have the form part automatically populate the container with the name of the DocuRef records in the form part? IF this is not possible, how can I at least clear the container bofre the next TmpCustVendTrans docuRef records are listed?
Below is my extension code of VendShowSpecifikation:
[ExtensionOf(formStr(VendShowspecifikation))]
public final class TMC_VendShowspecifikation_Extension
{
private Map formPartReferenceControlsMap;
private boolean factBoxEnabled;
internal FormRun baseformRun;
private TmpcustVendTrans recordSelected;
public void init()
{
// CoC
next init();
formPartReferenceControlsMap = new Map(Types::String, Types::Class);
factBoxEnabled = SysClientPerf::find().FactBoxesEnabled;
baseformRun = this as FormRun;
}
[FormDataSourceEventHandler(formDataSourceStr(VendShowspecifikation, TmpcustVendTrans), FormDataSourceEventType::SelectionChanged)]
public void TmpcustVendTrans_OnSelectionChanged(FormDataSource sender, FormDataSourceEventArgs e)
{
TmpCustVendTrans vendTransLocal = sender.cursor() as TmpcustVendTrans;
this.TMC_parmVentTransSelected(vendTransLocal);
if(factBoxEnabled)
{
this.refreshFormPart(formStr(TMC_APInvoiceViewFP), vendTransLocal);
}
}
private void refreshFormPart(str _formPartName, TmpCustVendTrans _vendTrans)
{
FormPartReferenceControl fpCtrl;
if (formPartReferenceControlsMap.exists(_formPartName))
{
fpCtrl = formPartReferenceControlsMap.lookup(_formPartName);
}
else
{
fpCtrl = baseformRun.getPartControlByName(_formPartName);
if(!fpCtrl)
{
fpCtrl = this.TMC_GetCustomPartControlByName(_formPartName);
}
//if the part does not exist we get null back, we still insert that in the cache to avoid determining it on each call
formPartReferenceControlsMap.insert(_formPartName, fpCtrl);
}
if (fpCtrl
&& fpCtrl.visible()
&& fpCtrl.expanded())
{
fpCtrl.refresh();
}
}
public FormPartReferenceControl TMC_GetCustomPartControlByName(str _name)
{
FormPartReferenceControl partReferenceControl, tmpPartReferenceControl;
MapEnumerator partControlEnumerator = factboxIdToControl.getEnumerator();
//Factboxes are not modeled as controls under the Form Design. Instead, they are generated controls
//The Compiler generates a new for each of these controls which has the __Generated_FormPart_ prefix for all such controls
// **** NOTE: the above is not true for custom controls added with extensions ****
str controlName = _name;
while (partControlEnumerator.moveNext())
{
tmpPartReferenceControl = partControlEnumerator.currentValue() as FormPartReferenceControl;
if (tmpPartReferenceControl && tmpPartReferenceControl.name() == controlName)
{
partReferenceControl = tmpPartReferenceControl;
break;
}
}
return partReferenceControl;
}
public TmpCustVendTrans TMC_parmVentTransSelected(TmpCustVendTrans _vendtrans = recordSelected)
{
recordSelected = _vendtrans;
return recordSelected;
}
}
Any help is much appreciated.