locked
Microsoft CRM SDK Update incorrectly causing workflow to fire RRS feed

  • Question

  • I've create a workflow that fires when a specific attribute is changed.  I have some code that updates an attribute when a user logs into our website, but not the attribute that triggers the workflow.  It appears as though the SDK update incorrectly triggers this workflow. The workflow doesn't trigger when I update the field the SDK updates through CRM. Has anyone else had this problem or does anyone know how to fix it?

    Dim

     

    token As New CrmWebService.CrmAuthenticationToken

    token.AuthenticationType = 0

    token.OrganizationName =

    "DISI"

     

    Dim service As New CrmWebService.CrmService

    service.Credentials = System.Net.CredentialCache.DefaultCredentials

    service.CrmAuthenticationTokenValue = token

     

     

    Dim query As New CrmWebService.QueryByAttribute

    query.ColumnSet =

    New CrmWebService.AllColumns

    query.EntityName = CrmWebService.EntityName.contact.ToString

    query.Attributes =

    New String() {"emailaddress1"}

    query.Values =

    New String() {LCase(txtUsername.Text)}

     

    Dim retrieved As CrmWebService.BusinessEntityCollection

    retrieved = service.RetrieveMultiple(query)

     

    If retrieved.BusinessEntities.Length > 0 Then

     

    Dim contact As New CrmWebService.contact

    contact = retrieved.BusinessEntities(0)

     

    Dim dt As New CrmWebService.CrmDateTime

    dt.Value = Now()

    contact.new_lastlogin = dt

    service.Update(contact)

    End If

    Monday, August 16, 2010 6:23 PM

Answers

  • The CRM platform assumes it is the responsibility of the calling code to determine which fields to change in an update. Hence, any properties that are set in any BusinessEntity that is passed to the Update method are assumed to have changed. In the code above, you used AllColumns when retrieving the entity, so all non-null properties will be considered to be updated. You shoudl replace AllColumns with a ColumnSet that contains only the primary key (in the case the contactid) attribute

     


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Monday, August 16, 2010 8:25 PM
    Moderator

All replies

  • The CRM platform assumes it is the responsibility of the calling code to determine which fields to change in an update. Hence, any properties that are set in any BusinessEntity that is passed to the Update method are assumed to have changed. In the code above, you used AllColumns when retrieving the entity, so all non-null properties will be considered to be updated. You shoudl replace AllColumns with a ColumnSet that contains only the primary key (in the case the contactid) attribute

     


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Monday, August 16, 2010 8:25 PM
    Moderator
  • Hi,

    Please retrieve those columns which you want to update. Do not retrieve AllColumns.
    If you retrieve AllColumns() and just modified one column value and update, CRM will update all NOT NULL column values back to MS CRM and any Plug-in / Workflow configured on Update on the above UPDATE LIST OF Columns will cause the Execution on Plugin / Wrokflows.

    Insted of below line
    // query.ColumnSet = New CrmWebService.AllColumns

    You need to change your code as below:

    ColumnSet Cols = new ColumnSet();
    Cols.AddColumn("new_lastlogin");
    query.ColumnSet = Cols;

    Hope this helps.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    • Proposed as answer by Ranjitsingh R Tuesday, August 17, 2010 2:30 AM
    Tuesday, August 17, 2010 2:30 AM
  • Thanks, that worked!
    Tuesday, August 17, 2010 4:45 PM