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 CRM (Archived)

How to make Ajax Synchronous call in Dynamics 365 Portal.

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Shaminderpal Singh Profile Picture
    1,565 on at

    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

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    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.

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans