Как обновить значения текстовых полей в определенной форме на Crm 4.0? - PullRequest
0 голосов
/ 08 июля 2011

Я хочу обновить данные своей учетной записи. Как я могу получить к ней доступ и обновить ее?

Я могу создать новую учетную запись, используя этот код, но также хочу обновить:

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();

                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);

            }

1 Ответ

0 голосов
/ 09 июля 2011

Обновления работают очень похоже на Creates. Просто убедитесь, что у DynamicEntity есть GUID и имя объекта записи, которую вы хотите обновить и заменить

MyService.Create(leadEntity);

с

MyService.Update(LeadEntity);
...