Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Step by Step What I need to start to send insert and update data into contacts in CRM 2011

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all,

I'm completely new in Dynamics CRM, so I would like to have your valuable help.

I want to know the libraries or packages that I need to start a C# project to insert and update data over Contacts in CRM 2011

Thanks,

Cristóbal Gómez

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Hi guys

    Finally, I found the solution. I coded this:

    WinOpportunityRequest winOpportunityRequest = new WinOpportunityRequest();
    Entity opportunityClose = new Entity("opportunityclose");
    opportunityClose.Attributes.Add("opportunityid", new EntityReference("opportunity", _opportunityId));
    opportunityClose.Attributes.Add("subject", "Win the Opportunity!");
    
    winOpportunityRequest.OpportunityClose = opportunityClose;
    winOpportunityRequest.Status = new OptionSetValue(3);
    
    var response = _service.Execute(winOpportunityRequest);


    Greetings 

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Hi Aric,

    I've added namespace "Microsoft.Crm.Sdk.Messages", so I can access WinOpportunityRequest, but I can't determinate what is "OpportunityClose" or which is the correct namespace for this class.

    So, I've tried the following way but I have errors:

    var winOppRequest = new WinOpportunityRequest
    {
        OpportunityClose = new Entity("opportunity")
        {
            Id = _opportunityId
        },
        Status = new OptionSetValue(1),
    };
    
    var response = _service.Execute(winOppRequest);

    System.ArgumentException: Object of type 'Microsoft.Crm.Entities.Opportunity' cannot be converted to type 'Microsoft.Crm.Entities.OpportunityClose'.

     

    At this point, I have a Question,  why I can't update the "StateCode" and "StatusCode" like other fields ?? For Example:

    opportunityEntity.Attributes["statecode"] = new OptionSetValue(1);
    opportunityEntity.Attributes["statuscode"] = new OptionSetValue(3);


    Thanks for your reply

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    See below link as far as state codes:

    technet.microsoft.com/.../dn531157.aspx

    You need to use the following code:

    var winOppRequest = new WinOpportunityRequest

    {

       OpportunityClose = new OpportunityClose

       {

           OpportunityId = new EntityReference

               (Opportunity.EntityLogicalName, _opportunityId)

       },

       Status = new OptionSetValue((int)opportunity_statuscode.Won)

    };

    _serviceProxy.Execute(winOppRequest);

    Console.WriteLine("Opportunity closed as Won.");

    Make sure that you add a reference to Microsoft.Crm.Sdk.Messages namespace in the using area of your class/plugin, so that you can use the WinOpportunityRequest class.

    Let me know if this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Hi Aric,

    Thanks for your advices, now I know how to use the forum and the rulers. But to avoid lost the focus on my actual problem, and if you have'n a problem, I would like to ask about your reply,

    Also, I' tried to update statuscode, just like you recommend me:

    opportunityEntity.Attributes["statecode"] = new OptionSetValue(1);

    opportunityEntity.Attributes["statuscode"] = new OptionSetValue(3);

    But in this case there is the following exception:

    "System.ArgumentException: 3 is not a valid status code for state code OpportunityState.Open on opportunity.\r\nParameter name: statusCode"

    Is like StateCode is never update to win state, so it still has 0 (open) value.

    as I said, if you preffer don't reply this question and I will open a new Post..

    Thanks in advance

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Cristobal,

    One more thing.

    Once you get an answer on a particular question that you have you should close the particular forum question and mark the answer as verified.

    This will help in various ways. First the subject of the question will be relevant to the actual question. In this case, the subject is already different than the question that you have in place.

    Second, verifying an answer will help additional users see a solution to a similar problem that they are having when searching the forums.

    Lastly, the people that help you out can get credit for the answers that they gave you.

    Overall, this helps out everyone is the end.

    Gracias :)

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Hi Cristobal,

    You should be updating both State Code and Status Code.

    Won is both a State Code and a Status Code.

    Your logic should be:

    Entity opportunityEntity = new Entity("opportunity");

    opportunityEntity.Id = _opportunityId;

    opportunityEntity.Attributes["statecode"] = new OptionSetValue(1);

    opportunityEntity.Attributes["statuscode"] = new OptionSetValue(3);

    _service.Update(opportunityEntity);

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Hi guys,

    I need your appreciated help, I'm trying to update StateCode to Win using the following code:

    Uri organizationUri = new Uri(operationContext.ServiceSettings.OrganizationUri);
    Uri homeRealmUri = null;
    ClientCredentials credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = NetworkCredential)CredentialCache.DefaultCredentials;
    OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
    IOrganizationService _service = (IOrganizationService)orgProxy;
    
    Entity opportunityEntity = new Entity("opportunity");
    opportunityEntity.Id = _opportunityId;
    opportunityEntity.Attributes["statecode"] = new OptionSetValue(1);
    _service.Update(opportunityEntity);

    The problem is "statecode" field never is updated and I don't know what's wrong.

    In CRM, there are a workflow to update "statuscode" if "statecode" is updated. If I change statecode through CRM screen, it works fine. So the Idea is updated "statecode" using XRM and automatically update "statuscode".

    Any Idea??

    Thanks for your help

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Thanks a lot,

    I was deploying with 4.6.2 .net framework, I changed to 4.5.2 and it works !!

    Greetings

  • Verified answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Hi Cristobal,

    Maybe this blog helps : www.develop1.net/.../Method-not-found-!!0-SystemArrayEmpty().aspx

    Hope this helps.

    Radu

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Step by Step What I need to start to send insert and update data into contacts in CRM 2011

    Hi friends,

    I was developing a Windows service to update some information from one system to CRM Dynamics. Now I wanna install my service un CRM's server but I get the following error:

    System.MissingMethodException: Method not found: '!!0[] System.Array.Empty()'.

    Any suggestions will be appreciate :)  

    Thanks

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans