Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

Updating The Primary Field via a C# Console App

$
0
0

Hi,

CRM 2011 On-Premise
Visual Studio Express 2013 for Windows Desktop

I'm very new to both C# and the CRM 2011 SDK.

I'm writing a simple console application which updates existing values on an Entity.

The field "new_name" is the Primary Field for the Entity in CRM. It's set to have No Constraints.
I'm able to update this field without any errors if I put it on a Form in CRM.

If I run the following code however, the field new_background gets updated, but new_name retains its old value:

How does CRM determine what fields can or cannot be updated when using the SDK? I'm probably missing something very obvious here.

Thanks for your help.

- Bob

private static bool updTest(IOrganizationService crmService)
        {
            try
            {        
                var lateBoundContext = new OrganizationServiceContext(crmService);

                var inspQuery = (from inspRec in lateBoundContext.CreateQuery("new_inspection")
                                 where ((String)inspRec["new_shop"]).Contains("5250")                                 
                                select inspRec); 
                var iCount = inspQuery.AsEnumerable();

                if (iCount.Any())
                {
                    Console.WriteLine("Got Record(s)");
                    foreach (var inspRec in inspQuery)
                    {
                        lateBoundContext.UpdateObject(inspRec); // Tell CRM we want to update the Entity.
                        inspRec.Attributes["new_background"] = "TEST DATA XYZ"; // Works fine.
                        inspRec.Attributes["new_name"] = "Bob_1234X"; // Fails, with no error

                        Console.WriteLine("new_name is... {0}", inspRec.Attributes["new_name"]);
                        crmService.Update(inspRec);                     
                    }
                }                                
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Updating in CRM.");
                Console.WriteLine("Exception: " + ex.Message);
                Console.ReadKey();
                return false;
            }       
        }


Viewing all articles
Browse latest Browse all 1000

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>