locked
deactivate contract line item in plugin RRS feed

  • Question

  • hi I have custom entity and have two lookups 

    lookup1 contract 

    lookup1 contractdetail 

    When I close the custom entity, I would like to deactivate the contractdetail record and create a new one. Is this possible. Is there any message that I can use similar to 'convertquotetoorder' or should I use the setstatus method?  

    Thursday, September 1, 2011 10:22 PM

Answers

  • Hi,
    I was in a favor of plugin but the solution was already explained so proposed a workflow solution (which is definitely easier not suitable for all entities). For a plugin based solution, register a plugin on SetStateDynamicEntity Message for custom entity in Pre-Operation/Post-Operation stage, the plugin code should check if custom entity is deativated then you can i.e.
    if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference &&
        ((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "my_custom_entity") {
        switch (context.MessageName)
        {
        // Check if entity status is changed
        case "SetStateDynamicEntity":
       
        if (context.InputParameters.Contains("Status"))
        {
         // Check if the record status is completed, change 1 with the relevant value
         if (((OptionSetValue)context.InputParameters["Status"]).Value == 1)
            {
                 // 1. Write code here to retrieve the Contract details entity and use SDK SetStateRequest to change the entity status to deactivate
        // 2. Create new record using Service.Create Method
                 
         
            }
         }
    }
    

    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Jehanzeb.Javeed Friday, September 2, 2011 12:08 PM
    • Marked as answer by CRM elite Friday, September 2, 2011 12:21 PM
    Friday, September 2, 2011 12:08 PM

All replies

  • Hi

    it is possible.

    1. Create a plugin on setstate/setdynamicstate of your custom entity.
    2. use the id of the entity to retrieve the contractdetail
    3. use setstaterequest to set the state of the contractdetail to deactivate.
    4. Create a new contractdetail (you can get contractid from the contractdetail

     

    You can shuffle the step 3 and 4. Perform 4 before three.

     

    I hope this help.

     

     


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Friday, September 2, 2011 12:07 AM
    Friday, September 2, 2011 12:06 AM
  • Hi,

    To make the solution implementation more easier even you can create a new workflow that will run on custom entity status change to close or close (checkbox: two optionset) and will execute the following steps:

    1. Add step Change Status, select contract details entity and choose deactivate status

    2. Create new record and set all fields form the previous record or with new values as per required


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, September 2, 2011 12:16 AM
  • Hi,

    To make the solution implementation more easier even you can create a new workflow that will run on custom entity status change to close or close (checkbox: two optionset) and will execute the following steps:

    1. Add step Change Status, select contract details entity and choose deactivate status

    2. Create new record and set all fields form the previous record or with new values as per required

    3. Save and Activate workflow


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, September 2, 2011 12:16 AM
  • I tried to use the workflow approach but for reason, I could only see the Contract but not the contract detail entity.  I created a workflow for the custom entity and select 'trigger for the field change' in the add setp, I try to select the entity but contract detail is not available. Only contract, even though I have look up for Contract and Contract detail in the Custom Entity. 

     

    Friday, September 2, 2011 11:29 AM
  • Hi Thanks Amreek,  Can you help me with " setstate/setdynamicstate"  is it pre o post event of Create Operation? 

    Friday, September 2, 2011 11:30 AM
  • Hi,
    I was in a favor of plugin but the solution was already explained so proposed a workflow solution (which is definitely easier not suitable for all entities). For a plugin based solution, register a plugin on SetStateDynamicEntity Message for custom entity in Pre-Operation/Post-Operation stage, the plugin code should check if custom entity is deativated then you can i.e.
    if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference &&
        ((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "my_custom_entity") {
        switch (context.MessageName)
        {
        // Check if entity status is changed
        case "SetStateDynamicEntity":
       
        if (context.InputParameters.Contains("Status"))
        {
         // Check if the record status is completed, change 1 with the relevant value
         if (((OptionSetValue)context.InputParameters["Status"]).Value == 1)
            {
                 // 1. Write code here to retrieve the Contract details entity and use SDK SetStateRequest to change the entity status to deactivate
        // 2. Create new record using Service.Create Method
                 
         
            }
         }
    }
    

    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Jehanzeb.Javeed Friday, September 2, 2011 12:08 PM
    • Marked as answer by CRM elite Friday, September 2, 2011 12:21 PM
    Friday, September 2, 2011 12:08 PM
  • Thank you Javeed. 
    Friday, September 2, 2011 12:21 PM