Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:30:36+00:00 2026-05-24T16:30:36+00:00

What are my mistakes, why do I get the object expected error, and, eventually,

  • 0

What are my mistakes, why do I get the “object expected” error, and, eventually, how does one debug jScript ?

I am new to Dynamics CRM and I would like to do a small customisation, which seem to require jScript. The instance (version 2011) is used mostly to manage client support.

There are 2 custom entities with relationships: FundLegalEntity –> SubFund

The Case (Incident) form is linked to the FundLegalEntity and the SubFund.
When user enters a SubFund I would like to have the FundLegalEntity filled automatically (if empty).
My question was: how do I code that ?

With the help of this great tutorial, and the very usefull oData Tool, and great help (below) from user @dub, here is my latest code:

function recalcParent()
{ 
    var lookupValue = Xrm.Page.getAttribute("new_subfundid").getValue();   

    var subFundId= lookupValue[0].id;
    // alert(subFundId);

    var request =  Xrm.Page.context.getServerUrl() + 
        "/xrmServices/2011/OrganizationData.svc/new_subfundSet?" + 
        "$select=new_LegalEntityId&" + 
        "$filter=new_subfundId eq guid'"+ subFundId+ "'";
    // alert(request);

$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: request,
    async: false,
    beforeSend: 
        function (XMLHttpRequest) 
        { 
            XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
        },
    success: 
        function (data, textStatus, XmlHttpRequest) 
        {
            var result = data.d.results[0];
            alert(result);
            var parentFundLookup = [{ entityType : "new_fund", id : result.LegalEntityId, name : result.FundLegalEntity}];                  
            // Set the value of the parent fund lookup 
        },
    error: 
        function (XmlHttpRequest, textStatus, errorThrown) 
        { 
            alert('Failed'); 
        }
    });       

} 

I have no more errors, the first 2 alerts (commente out) are giving me correct results.
THe 3rd alert displays “object Object”, and the control I expect to update is not updated.
Any hint please ? I suppose the last problem is in the var parentFundLookup = line…
I am a bit confused by all these different names.
Thanks !


Edit:

It’s nearly working now: when I modify the sub-fund in the Incident, the Legal Entity gets updated with the correct legal entity name, but the text box has a strange aspect, and the icon at the left of the text box is strange as well. Here is the latest bit of code:

success: 
    function (data, textStatus, XmlHttpRequest) 
    {
        var result = data.d.results[0];
        //alert(result.new_LegalEntityId.Name);
        var parentFundLookup = [{ entityType : "new_LegalEntity", id : result.new_LegalEntityId.Id, name : result.new_LegalEntityId.Name}];    
        Xrm.Page.getAttribute("new_fundlegalentityid").setValue(parentFundLookup);
    },

I suspect that the problem lies in the entityType : "new_LegalEntity", but I don’t know what to put in there. Any clue on this ? What does that represent ?
Here is a screenshot of the Legal Entity after the Sub-Fund is updated and the script has run.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:30:37+00:00Added an answer on May 24, 2026 at 4:30 pm

    You can use the Rest endpoint from your script to retrieve data from the organization service. Here’s an example to get you started. You can also look at the SDK documentation there’s a lot of useful information there.

    var subfundid; // get the id from the lookup 
    
    var request = 
        Xrm.Page.context.getServerUrl() + 
        "/XRMServices/2011/OrganizationData.svc/new_subfundSet?" + 
            "$select=ParentId&" +
            "$top=1&" + 
            "$filter=new_subfundId eq guid'"+ subfundid + "'";
    
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: request,
        async: false,
        beforeSend: 
            function (XMLHttpRequest) 
            { 
                XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
            },
        success: 
            function (data, textStatus, XmlHttpRequest) 
            {
                var result = data.d.results[0];
                var parentFundLookup = [{ entityType : "new_fund", id : result.ParentId, name : result.FundName}];                  
                // Set the value of the parent fund lookup 
            },
        error: 
            function (XmlHttpRequest, textStatus, errorThrown) 
            { 
                alert('Failed'); 
            }
        });
    

    Since this code uses JQuery, you’ll need to add the JQuery library as a web resource and include it in your form. See CRM 2011 "$ is undefined"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get the updated DOM html string for the form elements
How to ensure that my singleton object doesn't get released by mistakes when multiple
I am storing object values in strings e.g., string[] values = new string[] {
I have created a SecretkeySpec object wich contains a 128 bit key. I would
If I have several levels of object containment (one object defines and instantiates another
First off i'm new here so if I made any mistakes please point them
So new to objective-c and iphone/ipad development. Trying to get my feet wet with
I'm new to VBA but I'm trying to get a DYMO LabelWriter to work
I seem to make this mistake every time I set up a new development
I'm playing with DLR to get a better understanding of it. I'm not completely

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.