web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to refresh document viewer container in form part automatically

(2) ShareShare
ReportReport
Posted on by 1,457
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.
 
 
I have the same question (0)
  • Anton Venter Profile Picture
    20,385 Super User 2025 Season 2 on at
    Hello,
     
    Try calling the executeQuery method of the form part datasource instead calling the refresh method of the form part.
     
     
  • Retha Profile Picture
    1,457 on at
    I added breakpoints and the refresh of the form part does call the ExecuteQuery of the datasource of the form part.
    I found that piece of code in InventOnhandItemListPage. That is how Microsoft refreshed the form parts.
    The difference is that there isn't a direct link between TmpCustVendTrans and the form part datasource which is docuView. I have to find VendInvoiceJour in the form part to be able to find the docuRef records linked to it.
    But regardless of that, in my opinion the container should show the correct image linked to the associated docuRef record in the form part factbox grid, but it does it only for the first attachment.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 763 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 413 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 284 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans