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)

Invoice Contract plugin stop work in CRM 2016.

(0) ShareShare
ReportReport
Posted on by 70

In plugin when  i will invoice contract, contractLine is set some fields. 

My source. 

                        var res = from ser in ServiceContext.CreateQuery("contractdetail")
                                  where (ser["contractid"].Equals(strContractId))
                                  select ser;

                        foreach (Entity cdi in res)
                        {

                            Money valor = new Money(20);

                            if (cdi.Attributes.Contains("price"))
                                cdi["price"] = valor;
                            else
                                cdi.Attributes.Add("price", valor);

                            if (cdi.Attributes.Contains("net"))
                                cdi["net"] = valor;
                            else
                                cdi.Attributes.Add("net", valor);

                            ServiceContext.UpdateObject(cdi);

                        }
                        //Here happen the error.
                        ServiceContext.SaveChanges();



Remarks:

context.ParentContext.MessageName "SetStateDynamicEntity"

draft to invoice or active. 

It's work in CRM plugin 2015!!!

Error: 

The target state is invalid.  The target state may not exist or the system does not allow changing to the target state from the current state.

*This post is locked for comments

I have the same question (0)
  • Anderson_0l1v31ra Profile Picture
    70 on at
    RE: Invoice Contract plugin stop work in CRM 2016.

    it's working. Thank you for help

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Invoice Contract plugin stop work in CRM 2016.

    Try this. Getting only the changeable columns.

    var res = from ser in ServiceContext.CreateQuery<ContractDetail>()

                                     where (ser["contractid"].Equals(strContractId))

                                     select new { ser.ContractDetailId };

                           foreach (var cdid in res)

                           {

                               ColumnSet cols = new ColumnSet(new String[] {"contractdetailid", "price", "net" });

                               ContractDetail cdi = (ContractDetail)service.Retrieve(ContractDetail.EntityLogicalName, cdid.ContractDetailId.Value, cols);

                               Money valor = new Money(20);

       if (cdi.Attributes.Contains("price"))

                                   cdi["price"] = valor;

                               else

                                   cdi.Attributes.Add("price", valor);

                               if (cdi.Attributes.Contains("net"))

                                   cdi["net"] = valor;

                               else

                                   cdi.Attributes.Add("net", valor);

                               service.Update(cdi);

    }

                           ServiceContext.SaveChanges();

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans