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 :

Dynamics 365 Open Quick Create Form and Save/Refresh calling record

Michael Ghebremedin Profile Picture Michael Ghebremedin 107

If you are working in a scenario where you have to open Quick Create Form through JavaScript and save/refresh the calling record after the quick create form has been saved, you have few choices.

In this article I will show you how you can leverage the async and awaitoperators in JavaScript to solve this scenario.
First thing let’s try to define asyncand await
Async: - pretty much a function that returns a promise
Await: - makes JavaScript wait until the promise has been settled.
First thing let’s define the function that is going to Open Quick Create Form
function QuickCreate() {
    var entityFormOptions = {};
    entityFormOptions["entityName"] = "contact";
    entityFormOptions["useQuickCreateForm"] = true;

    // Set default values for the Contact form
    var formParameters = {};
    formParameters["firstname"] = "Sample";
    formParameters["lastname"] = "Contact";
    formParameters["fullname"] = "Sample Contact";
    formParameters["emailaddress1"] = "contact@adventure-works.com";
    formParameters["jobtitle"] = "Sr. Marketing Manager";
    formParameters["donotemail"] = "1";
    formParameters["description"] = "Default values for this record were set programmatically.";

    // Open the form.
    return Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
        function (success) {
            console.log(success);
            return success
        },
        function (error) {
            console.log(error);
            return null;
        });}

Next we are going to define the function that is going to consume the QuickCreate() and see how we can use the JavaScript operators

async function ConsumeQuickCreate (formContext) {
    //here you can define which fields you want to update after the quick create has saved
    formContext.getAttribute("statuscode").setValue("set your value here");
    var success = awaitQuickCreate();
    if (success) formContext.data.refresh(save);
}


As you have noticed in the code above formContext.data.refresh(save); is not going to be executed until the QuickCreate() function has return a value.

Thanks For reading 


This was originally posted here.

Comments

*This post is locked for comments