Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Released product form readonly in unit test

(0) ShareShare
ReportReport
Posted on by 27

Good day everyone,

I've got a question regarding the use of the test framework for forms. I have some custom code that sets some fields to not editable in the EcoResProductDetailsExtended form if some criteria are met. The code itself works fine. However, I also wanted to write some unit tests for this, to easily test my code in future upgrades etc.

So what I did:

- Recorded a task in F&O via the task recorder

- Downloaded the recorded task and imported it as unit test in Visual Studio via Extensions -> Dynamics 365 -> Addins -> Imported task recording

- Modified the generated code to write 2 test methods. One test to verify that the fields are editable in scenario 1, and another test to verify that the fields are readonly in scenario 2.

To my suprise however, the fields are readonly in both cases. Just to be sure, I disabled all my custom code for these fields, but still the fields are readonly.

This is my test case (slightly simplified to show only relevant parts):

class MyFormTest extends SysTestCase
{
    protected EcoResProductDetailsExtendedFormAdaptor EcoResProductDetailsExtendedForm;

    public void testFieldEditable()
    {
        changecompany('XXXX')
        {
            using (var c = ClientContext::create())
            {
                //Go to Product information management > Products > Released products.
                using (var c1 = c.navigate(menuItemDisplayStr(ecoresproductdetailsextendedgrid),formStr(EcoResProductDetailsExtended),Microsoft.Dynamics.TestTools.Dispatcher.MenuItemType::Display))
                {
                    EcoResProductDetailsExtendedForm = c1.form();

                    //In the list, click the link in the selected row.
                    EcoResProductDetailsExtendedForm.HeaderGrid().selectRecord();
                    EcoResProductDetailsExtendedForm.systemDefinedViewEditButton().click();

                    this.assertTrue(EcoResProductDetailsExtendedForm.EcoResProduct_SearchName().editable());
                }
            }
        }
    }
}

In my test setup (not included in the snippet) I made sure company XXXX is created, and has 1 released product. I checked that the grid contains 1 product by adding the following debug line to the test.

Info(int2Str(EcoResProductDetailsExtendedForm.HeaderGrid().count()));

Anyone got an idea why this test fails? Am I missing some setup to be able to edit a product via the form in my unit test? I have been writing more unit tests in Dynamics, but this is my first test involving forms like this.

  • FV@E Profile Picture
    FV@E 27 on at
    RE: Released product form readonly in unit test

    When I open the UI the field can be edited normally:

    pastedimage1681389858670v1.png

    Only during my unit test the editable() seems to return false.

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: Released product form readonly in unit test

    As far I know the released products form is non editable from UI. It is same at list page level and at item level also. Only may be custom fields would be editable. Are you asking this only?

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans