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)

XrmServiceToolkit Issue

(0) ShareShare
ReportReport
Posted on by

Hi,

We're currently moving from CRM4 to CRM2011/13. When I run the following code...

    var queryOptions = {
        entityName: "new_employment",
        attributes: ["new_clientnameid"],
        values: oCGuid,
        columnSet: ["new_employerid", "new_startdate", "new_datefinished", "statuscode"],
        orderby: ["new_employerid"]
    };

    var fetchedJobs = XrmServiceToolkit.Soap.QueryByAttribute(queryOptions);

    if (fetchedJobs[0] != null) {
        for (var i = 0; i < fetchedJobs.length; i++) {
            
            // Get Employer GUID
            var oEGuid = fetchedJobs[i].attributes["new_employerid"].value;
        }
     }


 ...the line

     var oEGuid = fetchedJobs[i].attributes["new_employerid"].value

returns "undefined" and so results in an error later in the code.

The fetchedJobs.length returns 5 -this is correct (for the record I am accessing).

If I replace "new_employerid" with any other values from the columnSet then there is no problem at all, so the query appears to be working alright.

When the corresponding code is run in CRM4 on the same data, it works fine.

The field "new_employerid" is a lookup field on a form and stores the Employer GUID - though I understand that this is an array and wonder if that is why I am having this problem - though perhaps not.

Really am puzzled by this one and would appreciate it if anyone can shed any light on the issue.

Thanks in advance.

Doug.

*This post is locked for comments

I have the same question (0)
  • Bruno Lucas Profile Picture
    5,421 on at

    is new_employerid compulsory?

    do you have 1 out many "new_employment" that could have no value for "new_employerid"?

    try to add this:

    var employerid = retrievedContact.attributes['new_employerid'];

    if(employerid != null) {

     oEGuid = fetchedJobs[i].attributes["new_employerid"].value;

    }

     

  • Community Member Profile Picture
    on at

    Thanks for your reply, Bruno.

    Yes, new_employerid is "business required" and it points back to the organisation that is the 'employer' for the job record that I am trying to access.

    Tried the code modification that you suggested but it still returned 'undefined' and then when the code runs on to use the value that should have been returned to interrogate the organisation (accounts) entity - to get the name of the employer I get this error message...

    Basically the links are:-  Casenote  -->  Client  -->  Job(s)  -->  Employer (organisation/account).

    When doing a casenote for a client the user needs to identify who the employer of that client is so the code looks at the job record(s) of the client, finds the employerID and then uses that to retrieve the organisation name. It's the step of getting the employerID from the job record that is tripping up.

    The logic worked fine in CRM4 (using the CrmServiceToolkit) but now using the XrmServiceToolkit it hits this brick wall each time.

  • Bruno Lucas Profile Picture
    5,421 on at

    I've used it recently for the same reason, upgrading from 4 to 11. it worked fine except for the SOAP call.

    do you have all the dependencies added on the correct order?

    "Dependency JSON2, jQuery 1.7.2 or above"

    do you also have the latest version of "XrmServiceToolkit"?

    it seems more like something like the JSON is not there because the error is not on the "var fetchedJobs = XrmServiceToolkit.Soap.QueryByAttribute(queryOptions);"

  • Verified answer
    Matt Knight Profile Picture
    on at

    If "new_employerid" is a lookup, that means it stores an Entity Reference. Given that, "value" has no meaning in that context. Try replacing it with "Id". That member should reference the GUID of the EntityReference class.

    msdn.microsoft.com/.../microsoft.xrm.sdk.entityreference_members.aspx

  • Verified answer
    Mithilesh Kumar Profile Picture
    10,047 on at

    Hi Doug,

    Since "new_employerid" is a Lookup Field, it will store the Reference to the Record which will be a GUID.

    To get the GUID Value from the Lookup Field, you will have to use

    oEGuid = fetchedJobs[i].attributes["new_employerid"].id;

    Hope that helps

    Thanks

  • Verified answer
    Bruno Lucas Profile Picture
    5,421 on at

    Good point Matt

    this is actually on the documentation but a bit hidden:

  • Community Member Profile Picture
    on at

    Thanks Matthew, Mithilesh & Bruno,
    ...that did the trick - all working now (until I hit the next hurdle).

    Doug.

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