开发者

How to update textboxes' values in a specific form on Crm 4.0?

开发者 https://www.devze.com 2023-03-19 06:17 出处:网络
I want to update my account\'s datas.How can I access and update it ? I can create a new account using this code but also i want to update :

I want to update my account's datas.How can I access and update it ?

I can create a new account using this code but also i want to update :

private static CrmService ConnectToCrm() 
    {
        CrmService service = new CrmService();
        CrmAuthenticationToken token = new CrmAuthenticationToken();
        token.AuthenticationType = 0;
        token.OrganizationName = "crm";

        service.Url = "http://192.168.1.23:5555/mscrmservices/2007/crmservice.asmx";
        service.CrmAuthenticationTokenValue = token;

        service.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

        return service;
    }
    protected void btnUpdateAccount_Click(object sender, EventArgs e)
    {

      try
          {
              CrmService MyService = ConnectToCrm();

              开发者_StackOverflow  DynamicEntity leadEntity = new DynamicEntity();
                leadEntity.Name = EntityName.lead.ToString();
                ArrayList arrProps = new ArrayList();

                if (txtName.Text != string.Empty)
                {
                    StringProperty firstname = new StringProperty();
                    firstname.Name = "firstname";
                    firstname.Value = txtName.Text;
                    arrProps.Add(firstname);
                }
                if (txtSurname.Text != string.Empty)
                {
                    StringProperty lastname = new StringProperty();
                    lastname.Name = "lastname";
                    lastname.Value = txtSurname.Text;
                    arrProps.Add(lastname);
                }
                if (txtMail.Text != string.Empty)
                {
                    StringProperty mail = new StringProperty();
                    mail.Name = "emailaddress1";
                    mail.Value = txtMail.Text;
                    arrProps.Add(mail);
                }
                if (txtState.Text != string.Empty)
                {
                    StringProperty state = new StringProperty();
                    state.Name = "address1_stateorprovince";
                    state.Value = txtState.Text;
                    arrProps.Add(state);
                }

                leadEntity.Properties = (Property[])arrProps.ToArray(typeof(Property));

                MyService.Create(leadEntity);

            }


Updates work very similar to Creates. Just make sure that the DynamicEntity has the GUID and entity name of the record you want to update and replace

MyService.Create(leadEntity);

with

MyService.Update(LeadEntity);
0

精彩评论

暂无评论...
验证码 换一张
取 消