Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Unable to update invoice product using plugin

(0) ShareShare
ReportReport
Posted on by 3,614

I've following plugin that run when an Invoice Product is being created from Invoice Product sub-grid or form. But it seems it don't updated the Policy Date field. I debugged the code and it run successfully but the field is not updated. Any suggestion?

try
            {
                IPluginExecutionContext context = (IPluginExecutionContext)isp.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)isp.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);

                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    Entity invoiceProduct = (Entity)context.InputParameters["Target"];
                    if (invoiceProduct.Attributes.Contains("invoiceid"))
                    {
                        Entity invoice = new Entity("invoice");
                        invoice = service.Retrieve("invoice", invoiceProduct.GetAttributeValue<EntityReference>("invoiceid").Id, new ColumnSet("new_policydate"));
                        invoiceProduct.Attributes["new_policydate"] = Convert.ToDateTime(invoice.Attributes["new_policydate"]);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException("Error: " + ex.Message);
            }


*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to update invoice product using plugin

    change this line:

    invoiceProduct.Attributes["new_policydate"] = ((DateTime)invoice["new_policydate"]).Date;

    Refer this:

    crmprof.wordpress.com/.../ms-crm-2011-retrieve-ms-crm-fields-using-late-bound

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: Unable to update invoice product using plugin

    Switched to Pre-Operaiton, not working.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to update invoice product using plugin

    Hi,

    Can you change the "Event Pipeline Stage of Execution" for Pre- Operation ?

    Best Regards,

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: Unable to update invoice product using plugin

    still not working, when I turn on the Profiling it works, when I stop profiling don't work.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Unable to update invoice product using plugin

    This is the answer. Update Pipeline Stage of Execution to "Pre-Operation".

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: Unable to update invoice product using plugin

    Here is what I've in the plugin configuration.

    IPfields.JPG

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Unable to update invoice product using plugin

    Can you please confirm that your plugin is registered in "Pre" mode?

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans