Skip to main content

Notifications

Announcements

No record found.

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,439
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.
 
 
  • Retha Profile Picture
    1,439 on at
    How to refresh document viewer container in form part automatically
    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.
  • Anton Venter Profile Picture
    19,542 Super User 2025 Season 1 on at
    How to refresh document viewer container in form part automatically
    Hello,
     
    Try calling the executeQuery method of the form part datasource instead calling the refresh method of the form part.
     
     

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

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,748 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans