Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin not working Post Operation Update

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

  • Nour Profile Picture
    Nour on at
    RE: Plugin not working Post Operation Update

    Thank you. I used images and preimages mainly because I had a more complicated code and not just the one posted above ( I was in need of all the attributes not just the updated ones).

    We solved the problem using another way of logic by implementing linq queries.

    Thank you a lot for your effort.

  • Verified answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Plugin not working Post Operation Update

    Ok another thing. You said that you want to do something when edm_createpurchaseorder flag is changed to "yes". Right now you are checking preImage (so pre-operation image). You should check post Image. Also for such scenario you don't need images - you should just check if Target contains "edm_createpurchaseorder" and if this flag is set to "yes".

  • Nour Profile Picture
    Nour on at
    RE: Plugin not working Post Operation Update

    I checked! They are the same. I really have no idea what is the issue!

  • Suggested answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Plugin not working Post Operation Update

    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

  • ACECORP Profile Picture
    ACECORP 1,579 on at
    RE: Plugin not working Post Operation Update

    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);

  • ACECORP Profile Picture
    ACECORP 1,579 on at
    RE: Plugin not working Post Operation Update

    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?

  • Nour Profile Picture
    Nour on at
    RE: Plugin not working Post Operation Update

    Hello,

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

  • Nour Profile Picture
    Nour on at
    RE: Plugin not working Post Operation Update

    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
    Nour on at
    RE: Plugin not working Post Operation Update

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

    I debugged so many times before.

  • Suggested answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,265 on at
    RE: Plugin not working Post Operation Update

    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.

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