web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

changing the status of a contract in Dynamics CRM 2011

(0) ShareShare
ReportReport
Posted on by 55

Hi,

We are using the contracts entity within CRM to manage our contracts.  We do not use the invoiceing functionality etc. and are quite happy for them all to stay in the draft status.  We also have not contract lines on the contract.

However we are finding that if the contract end date expires then the contract status moves to expired and we can't seem to find a way to move the status back to "in draft" to allow us to alter the date.  I have tried to use workflow to change the status but this does not seem to have any effect.

Our end goal is to be able to edit the end date to a new one in the future.

(If we choose the renew option then it alows us to edit the fields but on save it tells us that the contract is expired and it does not allow us to progress.)

Has anyone got a solution - we are using the online version


Regards

Dave

*This post is locked for comments

I have the same question (0)
  • ITBizOwner Profile Picture
    35 on at
    RE: changing the status of a contract in Dynamics CRM 2011

    I don't have an answer, but we are in the exact same situation.  Very odd that it locks up like that.  We open a contract when we "Close as Won" an Opportunity. BY default the contract end date is the same day as the Contract start date and it expires within 24 hours.  We have not been able to renew it.  Any help is appreciated.  We are using the Cloud version of Dynamics CRM.

  • AFTAB HUSSAIN Profile Picture
    on at
    RE: changing the status of a contract in Dynamics CRM 2011

    Hello Dave,

    Please check the link below.

    www.magnetismsolutions.com/.../Renewing_Contracts_in_Microsoft_Dynamics_CRM_2011.aspx

    rc.crm.dynamics.com/.../ug_cs_contracts.htm

    Or there way, we can create a workflow that can be used to notify before the contracts expires so that required modifications can be made.

    community.dynamics.com/.../105149.aspx

    Thank You !

  • Suggested answer
    Sanjaya Prakash Pradhan Profile Picture
    2,745 User Group Leader on at
    RE: changing the status of a contract in Dynamics CRM 2011

    Hi Dave,

    Just relax. I have the solution for it.

    As per your requirement you are not using the full implementation of the contract. I mean you are just using contracts without contract line. Its OK.

    As we know, there is a system job running everyday and expires contracts whose end date is passed. Once the status is getting expired you can not change anything on this.

    So for your case you have to restrict the status change from draft to Expire.

     For this you need to write a plugin for it which will run to restrict the status change.

    the below code will be required for the plugin.

    Important NOTE : Change the code accordingly.

    Lets Say Plugin Name : RestrictAutoExpireContracts.cs

     

    /// The class begins

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Metadata;
    using System.Xml;
    using System.ServiceModel;
    using System.Web.Services.Protocols;

        public class RestrictAutoExpireContracts : IPlugin
        {
            //Restrict OOB Auto Expire of contract and Contract 

            //Pre Operation
            public void Execute(IServiceProvider serviceProvider)
            {
                try
                {
                    // Obtain the execution context from the service provider.
                    IPluginExecutionContext context =
                        (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                    // Get a reference to the organization service.
                    IOrganizationServiceFactory factory =
                        (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = factory.CreateOrganizationService(context.UserId);

                    // Check the InputParameters for an EntityMoniker instance to work with; validate type
                    if (context.InputParameters.Contains("EntityMoniker") &&
                            context.InputParameters["EntityMoniker"] is EntityReference)
                    {
                        EntityReference contractInfo = (EntityReference)context.InputParameters["EntityMoniker"];

                        // Verify entity is a Contract instance
                        if (contractInfo.LogicalName != "contract")
                            throw new InvalidPluginExecutionException("Failure in ContractSetStateHandler: Not a Contract instance.");

                        if (!context.PreEntityImages.Contains("PreSetStateContract"))
                            throw new InvalidPluginExecutionException("Failure in ContractSetStateHandler: Missing PreSetStateContract image.");


                        if (!context.PreEntityImages["PreSetStateContract"].Attributes.Contains("statecode"))
                            throw new InvalidPluginExecutionException("Failure in ContractSetStateHandler: Missing state in context.");

                        Entity preSetStateContract = (Entity)context.PreEntityImages["PreSetStateContract"];

                        if (!preSetStateContract.Attributes.Contains("statecode"))
                            throw new InvalidPluginExecutionException("Failure in ContractSetStateHandler: Missing statecode in image.");


                        int oldStateCode = ((OptionSetValue)preSetStateContract.Attributes["statecode"]).Value;
                        int newStateCode = ((OptionSetValue)context.InputParameters["State"]).Value;

                        // Make sure we only care about a transition from Draft to Expired
                        if ((newStateCode != 0) && oldStateCode == 0)
                            throw new InvalidPluginExecutionException("Draft Contracts are not allowed to automatically change OOB state.");
                    }
                    else
                        throw new InvalidPluginExecutionException("Failure in ContractSetStateHandler: Expected EntityMoniker unavailable.");
                }
                catch (SoapException ex)
                {
                    throw new Exception("Error from CRM service : " + ex.Message);
                }

                catch (Exception ex)
                {
                    throw new Exception("Error from CRM service : " + ex.Message);
                }
            }

        }

     

    NOTE: After writing the plugin register the plugin with below option:

    1. register the assembly in post operation of setstate message

    1385.2.png

    2. add preimage for the setstate step with name : PreSetStateContract

     

    3. add step for setstatedynamicEntity & Add preimage PreSetStateContract.

    1385.2.png

     

    Now Your Work is Done. Now the contracts of your system will never be expired and at anytime you can edit the dates. Cheers. :)

  • yleclerc Profile Picture
    1,549 on at
    RE: changing the status of a contract in Dynamics CRM 2011

    @Dave, did you ever found a solution to your issue? We are stuck with the same problem.

    We need to update contracts that expired on December 31, but they are now in read-only mode...

    P.S. We also use Contract Lines.

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans