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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

Form load function not working in Unified Client Interface (UCI)

(0) ShareShare
ReportReport
Posted on by 30

Scenario -

On the contact form there is a subgrid to add new courses (for example)

when I click on the 'New course button' on the subgrid, the default course form is launched.

The form is pulling up Contact information and updating the relevant fields on it.

But there is function on the load of the form which should clear some of the information being pulled. (mentor and verifier fields should get cleared - these are lookup fields to contact)

This works fine in the Legacy web client but not in UCI as the fields doesn't get cleared up on the load.

Unified Client Interface                                                                                                                         Legacy Web Client

pastedimage1582806465845v1.png                                    pastedimage1582806557447v3.png

The code I have used on the load is 

var formType = Xrm.Page.ui.getFormType();
if (formType == 1) //create mode
{
if (Xrm.Page.getAttribute("gap_mentor").getValue() != null) {
Xrm.Page.getAttribute("gap_mentor").setValue(null);
}
if (Xrm.Page.getAttribute("gap_verifier").getValue() != null) {
Xrm.Page.getAttribute("gap_verifier").setValue(null);
}
}

  • Verified answer
    LeoAlt Profile Picture
    16,341 Moderator on at

    Hi partner,

    Now UCI dose not support "Xrm.page" so I recommend you to use "formContext" to insead.

    I updated your code and it worked well in my instance.

    function onLoad(executionContext) {
        var formContext=executionContext.getFormContext();
        var formType = formContext.ui.getFormType();
        if (formType == 1) //create mode
        {
            if (formContext.getAttribute("new_option").getValue() != null) {
                formContext.getAttribute("new_option").setValue(null);
            }
            
        }
    }

    To use "formContext", we should select "pass execution context as first parameter" when we add the function in onload event.

    pastedimage1582857620657v1.png

    And when I loading the create form of my custom entity, the option field value has been cleared.

    pastedimage1582857673242v2.png

    When we using custom JS code in UCI(model-drievn app), using formContext is more welcome :-)

    https://docs.microsoft.com/en-gb/powerapps/developer/model-driven-apps/client-scripting

    Hope it helps.

    Best Regards,

    Leo

  • Snitika Luthra Profile Picture
    30 on at

    Thankyou Leo. It worked like a charm :)

  • LeoAlt Profile Picture
    16,341 Moderator on at

    Hi Luthra,

    I'm so happy to hear that:-)

    If my answer helped, please mark my answer as verified so that we could help other users with similar issues.

    Best Regards,

    Leo

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
11manish Profile Picture

11manish 50 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 45

#3
Ayesha Wajahat Profile Picture

Ayesha Wajahat 18

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans