Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Syntax for updating record from custom entity

Posted on by

Hi,

I'm using C# presently to retrieve records from Microsoft CRM Online using the SDK, however I can't seem to get my head around the retrieve and update the record syntax.

I currently have the following which works perfectly for creating a new record and relating it to its parent.

var CRMService = CRMHelper.GetCRMService();

//instantiate the object

new_additionalphoto p = new new_additionalphoto();

p.new_Photo = new EntityReference("new_additionalphoto", new Guid(Request.QueryString["id"]));

p.new_Description = txtDescription.Text;

var Id = CRMService.Create(p);


But what I'm want to do now without creating the record is to retrieve a record based on the querystring (GUID) passed to the page and then update some fields and then re-save it. 

I can't seem to understand the syntax of how I retrieve the record and associating the querystring to get the right record.

Any ideas would be greatly appreciated. 

*This post is locked for comments

  • Chris Vine Profile Picture
    Chris Vine on at
    RE: Syntax for updating record from custom entity

    You are a legend. Thank you Guido. Appreciate your help. Worked perfectly.

  • Chris Vine Profile Picture
    Chris Vine on at
    RE: Syntax for updating record from custom entity

    [quote user="Guido Preite"]

    assuming that your querystring contains the ID of the record, this is a late bound example:

    1. var CRMService = CRMHelper.GetCRMService();
    2. Entity myRecord = CRMService.Retrieve("new_additionalphoto", new Guid(Request.QueryString["id"]), new ColumnSet(true));
    3. myRecord["new_description"] = "My new Description";
    4. CRMService.Update(myRecord);

    [/quote]Thanks for the quick reply Guido.

    I've just tried your syntax (note I have put in the column field name into the myRecord[""] and when it does the update it tells me that the attribute doesn't exist.

    + $exception {"'new_inspections' entity doesn't contain attribute with Name = 'new_CoverPhoto'."} System.Exception {System.ServiceModel.FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>}

    Any ideas? The field definitely exists as I could submit with my code at the top.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans