Skip to main content

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


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 await operators in JavaScript to solve this scenario.
First thing let’s try to define async and 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 = await QuickCreate();
    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 

Comments

  1. I have to comment on my own post just to say the above code want work on IE 11 for the simple reason that IE 11 does not support ECMAScript 6.
    In case of IE 11 you have to use callback.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Close/Resolve Case in Power Automate Flow

 How to Close/Resolve case from Power automate flow from your DataVerse Connector Add a New Row Table Name: Case Resolutions Subject: Add your subject here Case (Cases): incidents({Case Id Guid})

Azure DevOps Fork Repos between two Organization

  Azure DevOps Fork Repos between two Organization This weekend I embarked on a topic a bit foreign to myself, on the surface seemed a bit simple. The idea is to fork my Azure DevOps Repo to a different organization and push changes between them. Bad news DevOps doesn’t allow to fork Repos to a different organization, you have only the capability to fork to a different Projects within the same Organization. I’m pretty much sure there are so many other ways to solve this issue, but this is the one that I found to be easy to implement. Import Repo to the new Organization Remember here you have to generate a personal token to be able to import the Repo you have to be a member of the new organization as well This might take a few minutes depending on the size of your project, once its complete you will receive a confirmation email, or just refresh it after few minutes So far all looks good, you can clone the solution in your new Organizati...

Using Adaptive Cards on Power Virtual Agent

  Adaptive Card for Power Virtual Agent its on preview, this feature will enable you to enhance your bot with a better visual responses. Here is a demo of a Power Virtual Agent I have embedded on Teams Its quite easy to implement you can use Adaptive Card Designer to generate JSON for your Adaptive Card. You can start by selecting "Ask with Adaptive Card" Here will be able to configure You can Use Adaptive Card Designer for designing your Card, its quite easy to work with. If you are skilled developer you can take advantage of the JSON. This is your JSON template: {     "type" : "AdaptiveCard" ,     "$schema" : "http://adaptivecards.io/schemas/adaptive-card.json" ,     "version" : "1.5" ,     "body" : [] } T