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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to pass execution context to JavaScript function on click of New button from Entity Home Page?

(0) ShareShare
ReportReport
Posted on by 5

Hi,

I have a scenario where I want to show a specific form based on the user's choice while creating a record.

I have created an HTML web resource which asks user to select an option and depending on the selection I want to navigate to the specific form from the available forms for the entity. PFB the code that I have come up with:

askUserToSelect: function (executionContext) {
        var formContext = executionContext.getFormContext();
        var alertButton = new Alert.Button();
        alertButton.label = "Continue";
        alertButton.callback = function () { askUserToSelectSuccessCallback(executionContext); };
        //alertButton.callback = askUserToSelectSuccessCallback;
        var array = new Array();
        array.push(alertButton);
        Alert.showWebResource("askUserForSelection.html", 700, 380, "User Choice", array, null, false, 30);
    },

askUserToSelectSuccessCallback: function (executionContext) {
        
        var formContext = executionContext.getFormContext();
        
        var iFrameParameters = Alert.getIFrameWindow();
        var userChoice = iFrameParameters.userChoice;
        
        if (userChoice == "Form1") {
            
            formContext.ui.formSelector.items.get(Form1_GUID).navigate();
        }
        else {
            formContext.ui.formSelector.items.get(Form2_GUID).navigate();
        }
    },

Using the Ribbon Workbench tool, I have customized the command for New button on Entity Home Page to pass PrimaryControl as a parameter to askUserToSelect function. However I am getting null value in the executionContext.

Similarly, I have customized the command for New button on Entity Form page to pass PrimaryControl as a parameter to askUserToSelect functionIn this scenario, the executionContext is available to use, however, it gets lost on successCallback event.

I have the same question (0)
  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,
    "executionContext" is only supported in forms. So if you add it to ribbons which in homepage, it will not work for us.

    According to your description, looks like you want to open forms directly from the homepage, so you could use "Xrm.Navigation.openForm". "Xrm" platform is available on the homepage.

    function askUserToSelect() {
        var entityFormOptions = {};
        entityFormOptions["entityName"= "new_bpptest";
        entityFormOptions["entityId"= "52CA6EA4-BFF0-E911-A812-000D3A339A58";
        Xrm.Navigation.openForm(entityFormOptions).then(
            function (success) {
                console.log(success);
            },
            function (error) {
                console.log(error);
            });
    }

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openform

    I've test in my instance and it worked well.

    BTW, if you need to open a record, you need to pass the record id in your function.

    Hope it helps.

    Best Regards,

    Leo

  • Mahesh Padekar Profile Picture
    5 on at

    Hello Leo,

    Thanks for the response.

    I wanted to create a new record with a specific form out of available forms of the Entity instead of opening the form for an existing record. During more research I found that we can pass Form ID as a parameter to  "Xrm.Navigation.openForm".

    PFB the code that I used to solve the issue (open specific Create Form from entity home page):

        askUserToSelectSuccessCallback: function (executionContext) {
            
            var formContext = executionContext.getFormContext();
            
            var iFrameParameters = Alert.getIFrameWindow();
            var userChoice = iFrameParameters.userChoice;
            
            var entityFormOptions = {};
            entityFormOptions["entityName"] = EntityName;
            
            
            if (userChoice == "Form1") {
                var parameters = { formid: Form1_GUID };                        
                Xrm.Navigation.openForm(entityFormOptions, parameters);
            }
            else {
                var parameters = { formid: Form2_GUID };                        
                Xrm.Navigation.openForm(entityFormOptions, parameters);
            }
        }

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Thanks so much for your sharing and reply.

    Yes this function could pass form id to choose different forms.

    Sorry for my omission.

    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

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans