locked
Update Field with results of LINQ Query RRS feed

  • Question

  • I have a LINQ query where I get a result back.

    I want to write my result into a field of a form within an entity.

    Anyone know how to do this?

    Wednesday, September 30, 2015 11:42 AM

Answers

  • Hi JMcCon,

    Try below code to update the record:

            var _LinqResult = from data in dataSourse
                              select data.singleValue;
    
            using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
            {
                _service = (IOrganizationService)_serviceProxy;
    
                Entity account = new Entity("account"); // Suppose you want to update the account entity
                account["id"] = new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // set the guid of the target account record
    
                account["name"] = _LinqResult;
    
                _service.Update(account);
            }

    Make sure that _LinqResult datatype match to the target crm field datatype.

    • Proposed as answer by Piyush Parate Wednesday, September 30, 2015 5:56 PM
    • Edited by Piyush Parate Wednesday, September 30, 2015 5:59 PM
    • Marked as answer by JMcCon Thursday, October 1, 2015 8:08 AM
    Wednesday, September 30, 2015 5:56 PM

All replies

  • Hi JMcCon,

    Try below code to update the record:

            var _LinqResult = from data in dataSourse
                              select data.singleValue;
    
            using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
            {
                _service = (IOrganizationService)_serviceProxy;
    
                Entity account = new Entity("account"); // Suppose you want to update the account entity
                account["id"] = new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // set the guid of the target account record
    
                account["name"] = _LinqResult;
    
                _service.Update(account);
            }

    Make sure that _LinqResult datatype match to the target crm field datatype.

    • Proposed as answer by Piyush Parate Wednesday, September 30, 2015 5:56 PM
    • Edited by Piyush Parate Wednesday, September 30, 2015 5:59 PM
    • Marked as answer by JMcCon Thursday, October 1, 2015 8:08 AM
    Wednesday, September 30, 2015 5:56 PM
  • Thanks for the reply ChangeFrenzoId
    Thursday, October 1, 2015 8:08 AM