Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to make Ajax Synchronous call in Dynamics 365 Portal.

Posted on by 115

Hi All,

I have to get the records from an entity in synchronous mode and based on the output I have to do some set of operations in Portal entity form.

 Ásyn = false' is deprecated so the below code is not getting the result in synchronous mode. 

function getODataResponse(oDataUrl) {
var response = null;
$.ajax({
type: "GET",
url: oDataUrl,
async: false,
dataType: "json"
}).done(function (json) {
response = json.value;
});
return response;
}

Any suggestion please to read the data in sync mode from an entity in Dynamic 365 Portal.

Thanks & Regards,

Nandhini M

*This post is locked for comments

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: How to make Ajax Synchronous call in Dynamics 365 Portal.

    Hi,

    You should be able to make it run by changing false to true ?? have you already resolved if yes, you share share your steps so that it will help others as well. And make sure to close this thread.

  • Suggested answer
    Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: How to make Ajax Synchronous call in Dynamics 365 Portal.

    Hi Nandhini,

    You can handle it using promises.

    var   serverRequest=function (url, httpVerb, data, isAsync, headers) {

                       var res = $.Deferred();

                       $.ajax({

                           type: httpVerb,

                           contentType: "application/json; charset=utf-8",

                           datatype: "json",

                           data: data !== null ? JSON.stringify(data) : data,

                           async: isAsync,

                           url: url,

                           beforeSend: function (XMLHttpRequest) {

                               XMLHttpRequest.setRequestHeader("Accept", "application/json");

                               if (headers) {

                                   $(headers).each(function (ind, elem) {

                                       XMLHttpRequest.setRequestHeader(elem.header, elem.value);

                                   });

                               }

                           },

                           complete: function (XmlHttpRequest) { },

                           success: function (data, textStatus, XmlHttpRequest) {

                               res.resolve(data);

                           },

                           error: function (data) {

                               res.reject(data);

                           }

                       });

                       return res.promise();

                   }

    then call this function like below:

    $.when(serverRequest('url','GET',null,true,null)).then((success)=>{

    //You will get your success response  here and write the code that you want to run after response here

    },(error)=>{

    //Error Handler

    })

    -Shaminder

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans