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)

Ajax Call Error

(0) ShareShare
ReportReport
Posted on by 1,549

When creating an incident, I'm trying to check the value of a field on the Account (customerid).

I am using odata and jquery which are both pre-loaded on the form.

I am getting an Ajax Call Error when the function gets to the red part below. I have no other detail about the error.

Anyone has an idea? I can't find the error in my code.

AlerteCompteSupportDesactive = function () {

var compte = window.Xrm.Page.getAttribute('customerid').getValue();

if (compte === null || compte[0] === null) {
return;
}

var compteid = compte[0].id;

if (compteid !== null) {

var url = "/AccoutSet(guid'" + compteid + "')/new_Supportdesactive";

var entity = $.odata.getOne(url);

if (typeof entity !== 'undefined' && entity !== null && typeof entity.new_Supportdesactive !== 'undefined' && entity.new_Supportdesactive == 1)
{
Xrm.Page.ui.setFormNotification("Attention. Le support est désactivé pour ce compte! ", "WARNING", "alertecompte")
}

}
};

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Yvan,

    Where did you get this example? Can you send a link that will demonstrate that odata extension?

  • yleclerc Profile Picture
    1,549 on at

    I got the code from another CRM Organization we have. It was first written for CRM 2011, but it still works after migrating to CRM 2016. Back then, the guy used odata a lot.

    Here is a link to how the form is configured: https://youtu.be/zgOcqJf2g8w. Sorry, our CRM base language is French...

    Maybe my approach is wrong...

    Here is my goal:

    In an inciden,t upon choosing Account, I need to check the value of a field in the Account (2 option field). If the field value is yes (1), I need to display a notification.

  • yleclerc Profile Picture
    1,549 on at

    odata is a library we uploaded in CRM...

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Looks like your library is not get loaded.

    You have 2 ways - find a way to load that library or avoid using it and switch to something other. For example you can use rough JavaScript. Install CRMRest Builder and use it - it can provide you code to start.

  • yleclerc Profile Picture
    1,549 on at

    Thanks Andrew!

    I will check with Jason Lattimer because when loading CRMRest Builder, it stall at "Please wait" forever...

  • yleclerc Profile Picture
    1,549 on at

    Thanks Again! I am getting there... slowly! Here is the code I built with Rest Builder. I added alerts to figure out what is going on.

    alert (result); -> Returns [object Object]
    alert (new_supportdesactive); -> Returns undefined

    AlerteCompteSupportDesactive = function () {

    if (typeof ($) === 'undefined') {
    $ = parent.$;
    jQuery = parent.jQuery;
    }

    $.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts()?$select=new_supportdesactive",
    beforeSend: function(XMLHttpRequest) {
    XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
    XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
    XMLHttpRequest.setRequestHeader("Accept", "application/json");
    XMLHttpRequest.setRequestHeader("If-None-Match", "W\/\"000000\""); //Change 000000 to your value
    },
    async: false,
    success: function(data, textStatus, xhr) {
    if (xhr.status === 304) { //Handle data not changed
    } else {
    var result = data;
    var new_supportdesactive = result["new_supportdesactive"];
    }

    alert (result);
    alert (new_supportdesactive);

    if (new_supportdesactive == 1)
    {
    Xrm.Page.ui.setFormNotification("Attention. Le support est désactivé pour ce compte! ", "WARNING", "alertecompte")
    }
    },
    error: function(xhr, textStatus, errorThrown) {
    Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
    }
    });
    };

    When I execute the code with Rest builder, it seemd to be working

    2017_2D00_11_2D00_21_5F00_13_2D00_58_2D00_58.jpg

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Yvan,

    Where do you pass id of account to query?

  • yleclerc Profile Picture
    1,549 on at

    I guess I am not! It there any way to this directly in Rest Builder or it has to be added manually to the code?

    2017_2D00_11_2D00_21_5F00_14_2D00_17_2D00_09.jpg

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    You will have to add it to code.

    Should be something like following based on your code:

    var compte = window.Xrm.Page.getAttribute('customerid').getValue();

    var compteid = compte[0].id.replace("{","").replace("}", "");

    url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + compteid + ")?$select=new_supportdesactive",

  • Community Member Profile Picture
    on at

    Hi YLeclerc,

    as i can see:

    var result = data; <-- is an array
    var new_supportdesactive = result[0]["new_supportdesactive"]; <-- you need to use index

    Please let me know.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

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