locked
Unable to get property undefined or null reference RRS feed

  • Question

  • 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.

    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);
        
                    
                    }
                }


    pnoushu@hotmail.com



    • Edited by P Noushad Monday, February 6, 2017 11:26 AM
    Monday, February 6, 2017 10:44 AM

All replies

  • var serverUrl = context.getServerUrl(); 
    
    Change it to
    
    var serverUrl = context.getClientUrl(); 


    Regards Faisal

    Monday, February 6, 2017 11:13 AM
  • Hi,

    it is working var serverUrl = context.getServerUrl();  since I my CRM version is 2011

    Let me know any other solution.


    pnoushu@hotmail.com

    Monday, February 6, 2017 11:28 AM
  • Ok Use this filter:-

    filter=new_accounttechnologydetailsId/Id eq (guid'" + accountID + "')


    Regards Faisal

    Monday, February 6, 2017 11:58 AM
  • Can you debug the JS and check what is content of retrieveResult.responseText and retrieveResult.responseXML.xml?

    MaKeer

    Monday, February 6, 2017 5:59 PM
  • Your accountID is having { and } characters in the front and in the end.
    remove them before you use it in the query.
    You can use somthing like this:

    var accountGUID= Xrm.Page.getAttribute("new_accountid").getValue()[0].id; 

    var accountID=  accountGUID.replace("{", '').replace("}", '');

    Then use accountID in your query; should work!

    Sachith Chandrasiri

    Tuesday, February 7, 2017 2:37 AM
  • Hi,

    Do you mean by using alert.  let me know is there any way I can check directly through browser.

    Regards,

    Noushad


    pnoushu@hotmail.com

    Tuesday, February 7, 2017 5:27 AM
  • you basically replace following line

    var accountID= Xrm.Page.getAttribute("new_accountid").getValue()[0].id;

    with below code and try:

    var accountGUID= Xrm.Page.getAttribute("new_accountid").getValue()[0].id; 

    var accountID=  accountGUID.replace("{", '').replace("}", '');


    Sachith Chandrasiri

    Tuesday, February 7, 2017 5:34 AM
  • Hi,

    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);


    pnoushu@hotmail.com

    Wednesday, February 8, 2017 6:44 AM
  • Yes, you can use JS Alerts

    like alert(retrieveResult.responseText);

    alert(retrieveResult.responseXML.xml);


    MaKeer

    Wednesday, February 8, 2017 7:09 PM