Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

How to call a function after another function completed

Posted on by

Good day,

In Javascript, how to call 2 functions but in turn. the 2nd function must be executed after 1st function completed.

So I have a function to insert a new record, then 2nd function is to retrieve the record. Guess by just calling it in 2 lines not working 

Regards,

  • Verified answer
    Inogic Profile Picture
    Inogic 24,094 on at
    RE: How to call a function after another function completed

    You can see below example of CRM XRM functions for creating and retrieving data using JavaScript.

    Xrm.WebApi.createRecord("entityName", Your Query").then(
    function success(result)
    {
    Xrm.WebApi.retrieveRecord("entityName ", "Your Query").then(
    function success(result)
    {
    console.log("deleted");
    // perform operations on record deletion
    },
    function (error) {
    console.log(error.message);
    // handle error conditions
    }
    );
    },
    function (error) {
    console.log(error.message);
    // handle error conditions
    }
    );

    Hope this helps.

    Thanks!

  • Suggested answer
    Flydancer Profile Picture
    Flydancer 1,332 on at
    RE: How to call a function after another function completed

    If you have a promise, use the then function:

    insertRecord().then(

       (onResolved) => {

           // retrieve record..

       },

       (onRejected) => {

           // Some task on failure

       }

    )

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: How to call a function after another function completed

    Hi,

    please share your code

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans