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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin not working Post Operation Update

(0) ShareShare
ReportReport
Posted on by
Dear all, 

I have registered post and preimages and wrote the following code on update of my edm_materialrequisitionform entity. 
I want my code to create a purchase order when it is updated such that edm_createpurchaseorder field is yes. 

When I am debugging the code, I am not getting anything in my visual studio. (The arrow is not appearing eventhough i attached it to the plugin registration tool ofcourse).

 protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new InvalidPluginExecutionException("localContext");
            }

            Entity entity = null;
            Entity preentity = null;
            Entity postentity = null;
            if (localContext.PluginExecutionContext.InputParameters.Contains("Target") && localContext.PluginExecutionContext.InputParameters["Target"] is Entity)
            {
                entity = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];
            }
            else
            {
                return;
            }
            if (localContext.PluginExecutionContext.PreEntityImages.Contains("preimage"))
            {
                preentity = (Entity)localContext.PluginExecutionContext.PreEntityImages["preimage"];
            }

            else
            {
                return;
            }
            if (localContext.PluginExecutionContext.PostEntityImages.Contains("postimage"))
            {
                postentity = (Entity)localContext.PluginExecutionContext.PostEntityImages["postimage"];
            }

            else
            {
                return;
            }

edm_materialrequisitionform prematerialrequisitionform = preentity.ToEntity<edm_materialrequisitionform>(); edm_materialrequisitionform postmaterialrequisitionform = postentity.ToEntity<edm_materialrequisitionform>(); bool createPurchaseOrder= prematerialrequisitionform.GetAttributeValue<bool>("edm_createpurchaseorder"); if (createPurchaseOrder== true) { Entity purchaseorder = new Entity("edm_purchaseorder"); purchaseorder["edm_name"] = postmaterialrequisitionform.edm_name; purchaseorder["edm_date"] = postmaterialrequisitionform.edm_DateOfRequest; // purchaseorder["edm_customer"] = preentitymaterialrequisitionform.new_ localContext.OrganizationService.Create(purchaseorder); } } } }

*This post is locked for comments

I have the same question (0)
  • tw0sh3ds Profile Picture
    5,600 on at

    Hi,

    Do you get any error, or just nothing happens?

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    As described here you cannot debug a plugin in CRM Online, you need to use tracing:

    msdn.microsoft.com/.../gg328574.aspx

  • tw0sh3ds Profile Picture
    5,600 on at

    Andres, he is using PRt to debug his plugins, so your answer is irrelevant

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    Sorry, overlooked it.

    Please check this blog how to correctly debug with profiler:

    www.inogic.com/.../how-to-debug-plugins-using-profiler

    make sure the plugin dll deployed in CRM online equals the locally referenced dll file.

  • Nour Profile Picture
    on at

    My problem is not in how to debug. My problem is I am missing something in the logic.

    I debugged so many times before.

  • Nour Profile Picture
    on at

    Hello Pawel,

    I think It is in the logic itself. Something which has to do with images.

    No I do not get any error when I debug. The debugger runs and gives nthing, not even the arrow to debug.

  • Nour Profile Picture
    on at

    Hello,

    Paweel what is entity alias in the plugin registration tool when registering an image?

  • ACECORP Profile Picture
    1,589 on at

    What type of field is "edm_createpurchaseorder"?

    Is it possible that the check to see if that field is set to "yes" could be incorrect?

  • ACECORP Profile Picture
    1,589 on at

    The code related to the creation looks correct.

    Maybe put the creation code higher up and outside of the "create PO" check just to see if you can get it to execute.

    // Instantiate an account object.
    Entity myPO = new Entity("edm_purchaseorder");

    // Set the required attributes.
    myPO["edm_name"] = "The Name Here";

    myPO["edm_date"]= DateTime.Today();

    // Create an account record named Fourth Coffee.
    _myPOId = _orgService.Create(myPO);

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi,

    Maybe you misspelled your images names? Make sure that in PRT when registering preimage,you put "preimage" (case sensitive) in name and alias and also the same for postimage. Based on your code I would assume that in InputParameters you are lacking "preimage" or "postimage" and the plugin just ends it's running before it even hits the part with record creation

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans