web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to get property undefined or null reference

(0) ShareShare
ReportReport
Posted on by 1,821

Hi,

I have created new customized entity namely account technology details, it store technical information of account.  for this the primary field is new_accounttechnologydetailsId and new_accounttechnologydetails is the entity.  I want to check whether record exists in this entity or not before creating record.  Please find below script for this.   I do not know it executes until alert("2") and the retrieveResult.status is always 200 even the record not exists in this entity.  It displays unable to get property for any fields when I try to display.  I verified the filed name but it is correct.  and retrieved.results.length is always 0 even there is record or not.  Please help to find solution to check the account id before change account id.

j1.png

var accountID= Xrm.Page.getAttribute("new_accountid").getValue()[0].id;
            var context = Xrm.Page.context;
            var serverUrl = context.getServerUrl(); 
            var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
            var retrieveResult = new XMLHttpRequest();
            retrieveResult.open("GET", ODataPath + "/new_accounttechnologydetailsSet?$select=OwnerId&$filter=new_accounttechnologydetailsId eq guid'" +  accountID + "'", false);
            retrieveResult.setRequestHeader("Accept", "application/json");
            retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            retrieveResult.send();
            if (retrieveResult.readyState == 4 )
               {
                             
              if (retrieveResult.status == 200)
                   {
                   alert("2");
                   var retrieved = JSON.parse(retrieveResult.responseText).d;
                   alert(retrieved.results.length);
  
  var tact = retrieved.results[0].OwnerId;
                alert(tact);
    
                
                }
            }

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Unable to get property undefined or null reference

    It looks like your URL is not getting any data. Check if filter is correct. I don't think custom entityid should be equivalent to account id.

    $select=OwnerId&$filter=new_accounttechnologydetailsId eq guid'" +  accountID + "'"

  • P NOUSHAD Profile Picture
    1,821 on at
    RE: Unable to get property undefined or null reference

    Hi,

    Can I check manually including filter option, I mean out of CRM whether URL is correct or not. like this test-crm/.../OrganizationData.svc

    Custom entity id and account id is same.  I tried this from SQL it give same value.

    But my query is how it accept  retrieveResult.readyState == 4 and retrieveResult.status == 200 even if there is no record or filter is not mathing

    if (retrieveResult.readyState == 4 )  accept no issue

                  {

                 if (retrieveResult.status == 200) accept no issue

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Unable to get property undefined or null reference

    Refer this :

    msdn.microsoft.com/.../ms753800(v=vs.85).aspx

    developer.mozilla.org/.../Status

    It will fetch null data. You need to put a check for null data for all results

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Unable to get property undefined or null reference

    Hi Noushad,

    Please debug the Javascript by putting a debugger on the function start and check all the values after each step.

  • P NOUSHAD Profile Picture
    1,821 on at
    RE: Unable to get property undefined or null reference

    Hi,

    You mean by pressing F2,  I tried that but I do now know how to get this java scripts. Please help me in brief how to debug java scripts.

    It is working if I gave filter on new_name, but I do not know what is reason.

    retrieveResult.open("GET", ODataPath + "/new_accounttechnologydetailsSet?$select=new_name&$filter=new_name  eq '" +  accountID + "'", false);

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Unable to get property undefined or null reference

    As I have mentioned before your issue is in the URL. Please debug your code:

    1. Open the record which needs to be debugged.

    2. Press F12.

    3. In Find Search box search for new_accounttechnologydetailsSet .

    4. Place a debugger point and refresh your page.

    You can use Odata Query Designer tool to build your query.

    https://crm2011odatatool.codeplex.com/

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Unable to get property undefined or null reference

    Hi Noushad,

    As I am assuming that you want to check record before creating in entity that is it already exists or not. See, on the basis of GUID "new_accounttechnologydetailsId" you will not get that you want. It is possible only using Name of "new_accounttechnologydetails" entity or we can check is there any record of this entity exist for new_accountid.

    If you are considering, first approach then you have to apply filter on Name field not on  "new_accounttechnologydetailsId" field and the value will be, Name field`s data.

    Or if you are going for second approach, you have to apply filter on "new_accounid" field not on "new_accounttechnologydetailsId" and value for this field will be, "new_accountid" field`s data.

    Let me know, if there is any doubt with this.

    See, result from JSON can have Status=200 and ReadyState=4, although data is not there. Our checks are more important.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Unable to get property undefined or null reference

    Hi Noushad,

    Please follow the steps below for debugging.

    1. Put a debugger keyword in the start of the function as shown below.

    function Name() {
        debugger;
        var accountID = Xrm.Page.getAttribute("new_accountid").getValue()[0].id;
        var context = Xrm.Page.context;
        var serverUrl = context.getServerUrl();
        var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
        var retrieveResult = new XMLHttpRequest();
        retrieveResult.open("GET", ODataPath + "/new_accounttechnologydetailsSet?$select=OwnerId&$filter=new_accounttechnologydetailsId eq guid'" + accountID + "'", false);
        retrieveResult.setRequestHeader("Accept", "application/json");
        retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieveResult.send();
        if (retrieveResult.readyState == 4) {
    
            if (retrieveResult.status == 200) {
                alert("2");
                var retrieved = JSON.parse(retrieveResult.responseText).d;
                alert(retrieved.results.length);
    
                var tact = retrieved.results[0].OwnerId;
                alert(tact);
    
    
            }
        }
    } 

    2.  Register this Javascript library in the form.

    3. Press F12 to open Developer Tools and Open the form where you registered the library.

    4. Go to Developer Tools and see that Javascript execution has stopped at the point where debugger was put.

    5. Press F10 to pass by each step and see the values at the end after each step as shown in the screenshot below.

       4670.10.PNG

    Hope this helps.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans