locked
Object Expected error RRS feed

  • Question

  • Hello,

    I'm getting object expected error when i run the below code. Below is the html web resource called in iframe. Please let me know why i'm getting this error and help me to solve this.

    <HTML><HEAD><TITLE>CRM 2011 HTML Web Resource</TITLE>
    <SCRIPT src="ClientGlobalContext.js.aspx"></SCRIPT>
    <SCRIPT type=text/javascript src="new_json2"></SCRIPT>
    <SCRIPT type=text/javascript src="new_jquery1.4.1.min"></SCRIPT>
    <SCRIPT language=javascript>
    function searchprofile()
    {
     var serverUrl = Xrm.Page.context.getServerUrl();
     var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
     var retrieveUserReq = new XMLHttpRequest();
    alert(serverUrl);
     retrieveUserReq.open("GET", ODataPath + "/new_ResourcesSet", false);
     retrieveUserReq.setRequestHeader("Accept", "application/json");
     retrieveUserReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
     retrieveUserReq.onreadystatechange = function () {
      retrieveUserReqCallBack(this);
     };
     retrieveUserReq.send();
    }
    function retrieveUserReqCallBack(retrieveUserReq)
    {
     if (retrieveUserReq.readyState == 4 /* complete */) {
       if (retrieveUserReq.status == 200) {
         var retrievedUser = JSON.parse(retrieveUserReq.responseText).d;
         var userFullName = retrievedUser.new_name;
    alert(userFullName);
      }
     }
    }
    </SCRIPT>
    <META charset=utf-8></HEAD>
    <BODY contentEditable=true>
    <P>Enter Key Word:&nbsp; <INPUT style="WIDTH: 386px; HEIGHT: 22px" id=Text1 size=49>&nbsp;&nbsp;&nbsp;&nbsp;<INPUT style="WIDTH: 87px; HEIGHT: 24px" id=Search onclick=searchprofile() value=Search size=116 type=button text="Search"></P>
    <P>&nbsp;</P>
    <P>&nbsp; </P>
    <P>&nbsp;</P>
    <P>&nbsp;</P></BODY></HTML>


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, January 17, 2013 9:53 AM

Answers

  • Hi,
       You are doing a retrieve multiple call. So, the result will be a list. Following will work correctly.

    var userFullName = retrievedUser.results[0].new_name;


    Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"

    • Proposed as answer by Vikranth Pandiri Thursday, January 17, 2013 10:09 AM
    • Marked as answer by Madhu-CRM Thursday, January 17, 2013 10:31 AM
    Thursday, January 17, 2013 10:09 AM

All replies

  • Hello,

    I think you are getting error in "JSON.parse", make sure you have added json library in your entity or try to use like this.



    Contact Me
    Follow me on Twitter
    My Facebook Page
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, January 17, 2013 10:06 AM
    Moderator
  • Hi,
       You are doing a retrieve multiple call. So, the result will be a list. Following will work correctly.

    var userFullName = retrievedUser.results[0].new_name;


    Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"

    • Proposed as answer by Vikranth Pandiri Thursday, January 17, 2013 10:09 AM
    • Marked as answer by Madhu-CRM Thursday, January 17, 2013 10:31 AM
    Thursday, January 17, 2013 10:09 AM
  • hi this might be the problem,

     var serverUrl = parent.Xrm.Page.context.getServerUrl();

    are you able to get server url first ?try above code.

    If yes check for responseText and

    var retrievedUsers = JSON.parse(retrieveUserReq.responseText).d;

    it is collection you need to check

    if(retrievedUsers.length>0)

    {

    var userFullName = retrievedUser.results[0].new_name;

    }



    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    • Edited by san Sanz Thursday, January 17, 2013 10:18 AM
    Thursday, January 17, 2013 10:17 AM