Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Invoice Contract plugin stop work in CRM 2016.

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
    Community Member Profile Picture
    Community Member Microsoft Employee 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans