locked
CRM 2011 : IOrganizationService Create RRS feed

  • Question

  • Hi! We have a import job(written in c#) loading new entities. I want to inactivate some of these entities and i have been told this has to be done after its loaded(using SetStateRequest) . I'm wondering if the entity is present after an IOrganizationService Create, in that way i could read the entity and do an update(with SetStateRequest) right after the Create?

    BR

    knutmyre

    Tuesday, March 19, 2013 1:09 PM

Answers

  • Yes, you can do this. The return value of IOrganizationService Create is the Guid of the new record, and you can assign this to the SetStateRequest.EntityMoniker.Id property

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by knutmyre Wednesday, March 20, 2013 11:40 AM
    Tuesday, March 19, 2013 1:23 PM
    Moderator
  • Hi,

    Define a logic which newly created record you want to deactivate.

    Create a workflow. Check the condition in workflow, add an step to deactivate the record. 

    If you have a very complex logic to identify the records you want to deactivate then use plugin. Within your plugin check the conditions and use below code to deactivate the record. 

    SetStateRequest setStateReq = new SetStateRequest();
    setStateReq.EntityMoniker = new EntityReference(<entityschemaName>, <recordGUId>);
    setStateReq.State = new OptionSetValue(1);
    setStateReq.Status = new OptionSetValue(-1);
     
    SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);



    Chandan - http://mscrm-chandan.blogspot.in/ I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful !!!


    Tuesday, March 19, 2013 1:30 PM

All replies

  • Yes, you can do this. The return value of IOrganizationService Create is the Guid of the new record, and you can assign this to the SetStateRequest.EntityMoniker.Id property

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by knutmyre Wednesday, March 20, 2013 11:40 AM
    Tuesday, March 19, 2013 1:23 PM
    Moderator
  • Hi,

    Define a logic which newly created record you want to deactivate.

    Create a workflow. Check the condition in workflow, add an step to deactivate the record. 

    If you have a very complex logic to identify the records you want to deactivate then use plugin. Within your plugin check the conditions and use below code to deactivate the record. 

    SetStateRequest setStateReq = new SetStateRequest();
    setStateReq.EntityMoniker = new EntityReference(<entityschemaName>, <recordGUId>);
    setStateReq.State = new OptionSetValue(1);
    setStateReq.Status = new OptionSetValue(-1);
     
    SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);



    Chandan - http://mscrm-chandan.blogspot.in/ I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful !!!


    Tuesday, March 19, 2013 1:30 PM