Skip to main content

Notifications

Announcements

No record found.

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

  • RE: Invoice Contract plugin stop work in CRM 2016.

    it's working. Thank you for help

  • Verified answer
    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,575 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans