Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Plugin is duplication action

$
0
0

Hello,

Problem: We have a plugin that is causing the 'success action' to fire twice. I will note that when I make a new login for our portal and apply for our application I get the duplication, but when I apply for the same application a second time I only get one.  If I switch the a different application same results, first time duplicates, 2nd does not.

Process: We have an external portal, that creates an invoice in CRM.  When the invoice 'status reason' changes we fire a plugin.  Per our audit in CRM the status reason IS changing three times and the plugin fires 3 times, however, we have some checks in place to only fire if the target status = paid AND the preimage status was not PAID (code below).

Once we get past these filters, the next steps are:

1. Gather child data from invoice (line items and payment information).

2. At the end, conditionally, update the related Contact, Application (may be multiple), and Same Invoice that started the plugin.

3. Once this is complete I have a series of workflows that trigger (based on the Bool fields below) an email, to which I am getting two of the same.

Workflows: on change of Bool field, check for True, check invoice = PAID, then send email.

Other note: our status reason on invoice audit looks like this:

Old   New

NULL  New

New   Overpaid

Overpaid  Paid

Paid  Paid (this one gets me, since I dont update this field in my code, but maybe Im doing this incorrectly).

-- Ive commented out the contact update and still get duplicates, and now in my latest version, commented out the invoice update.  As I am writing this I feel the application may be the portion causing the duplicate, and will try it, and update my post.  As I am in a major time crunch I would very much appreciate any suggestions from the community and provide any further detail that may be require.

Thank you.

Plugin details: trigger: status reason

- Message Update

- Entity: invoice

- Post Op, Async, with a preimage of the 'status reason'

Code Sample

Entity target = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];
var PreResult = (preImage.Contains("statuscode")) ? preImage.GetAttributeValue<OptionSetValue>("statuscode").Value : 99999;
var PreSendInv = (preImage.Contains("BOOLEAN FIELD") == true) ? true : false;
if ((PreResult != 467670001 && PreResult != 467670000 && PreResult != 467670002) && PreSendInv != true)
{
return;
}

if (target.GetAttributeValue<OptionSetValue>("statuscode").Value == 467670001)

{ Fire update portion of plugin - target gets sent to next phase}

UPDATE STATEMENT IN PLUGIN

var Customer2update = new Entity("contact");
Customer2update[GUID] = CustomerRef.Id;
Customer2update["string field"] = TEXT;
Customer2update["string field"] = TEXT;
Customer2update["string field"] = TEXT;
Customer2update["string field"] = TEXT;
Customer2update["string field] = TEXT;
Customer2update["string field"] = TEXT;

Customer2update["lookup"] = InvoiceRef;
Customer2update["lookup"] = PaymentRef;
Customer2update["string field"] = Invdetaildata;

orgService.Update(Customer2update);


/*
var InvUpdate = new Entity("invoice");
InvUpdate["invoiceid"] = InvoiceID;
InvUpdate["bool"] = bool;
InvUpdate["bool"] = bool;
InvUpdate["bool"] = bool;
InvUpdate["bool"] = bool;
InvUpdate["bool"] = bool;
//ac stuff
InvUpdate["bool"] = true;
InvUpdate["bool"] = true;
InvUpdate["bool"] = BenchPrepbool;
InvUpdate["bool"] = OtherACprodsbool;

orgService.Update(InvUpdate); */


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images