locked
how to stop only child transaction in plug in RRS feed

  • Question

  • I have a scenario like, during the quick campaign i have to check the members phone numbers, if it doesnot contain data i should not allow the system to create an activity. for this i have created an plugin, on post operation , async. I am checking the data required in the plugin context. if the particular contact is not having data i am throwing an "invalidpluginexception".

    Due to this it is stopping whole transaction. It is not executing the other records.  How to stop only the child transaction in the plugin execution.  any idea?

    Friday, October 12, 2012 6:07 AM

Answers

  • Hello Samuel,

    I was interested by your problem, so I tried to reproduce the error. I created a plugin and registered it to the Pre-Operation stage in Synchronous mode of the Fax entity on the Create message. In this Plugin I am using this code:

    public void Execute(IServiceProvider serviceProvider)
            {
                var pluginContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                var recipients = ((Entity)pluginContext.InputParameters["Target"]).GetAttributeValue<EntityCollection>("to").Entities;
    
                foreach (var rec in recipients)
                {
                    if (rec.GetAttributeValue<EntityReference>("partyid").Id == new Guid("266065E7-9413-E211-85A5-00155D64D92C"))
                    {
                        throw new InvalidPluginExecutionException("test");
                    }
                }
            }

    So I am allowing faxes to be created for everyone except for one specific contact.

    Then I started a quick campaign with fax for all my contacts. I got the desired results, all contacts have a fax activity, except the one I define above. 

    So I am wondering why it is not working for you...

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.

    • Marked as answer by samuel s Friday, October 12, 2012 10:40 AM
    Friday, October 12, 2012 10:06 AM

All replies

  • Hello Samuel,

    a plugin that runs on post operation in async mode does not run in a transaction. If you want your plugin to execute in a transaction you will have to register it in synchronous mode. In post async mode, the record has already been created. Which means that in your scenario you would have to go and delete the record manually, if you don't want to allow its creation.

    So the exception you are throwing does not actually stop the record from being created. It just marks the async operation as "failed".

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.

    Friday, October 12, 2012 6:40 AM
  • thanks for your valuable points.

    Please go through the scenario below.

    my goal is to stop creating an activity for a contact when there is a data missing on the contact record during quick campaign.

    -> to achieve this i created one plugin . which runs on the fax entity , pre-operation,sync.

    it checks for a contact mobile phone data. if it is not there it throws an invalid plugin exception (i hope this is the way we can stop processing the create fax job).

    -> but when this exception is thrown it is stopping  the whole bulk operation. it is not executing the further records. but my goal is to, it should stop creating the activities for only the contacts who are not having the data and it should create activities for other contacts.

    how can we achieve this.

    Friday, October 12, 2012 7:04 AM
  • Could you please elaborate on the bulk operation you are mentioning? Can you describe the use case?

    I'm under the impression that maybe your plugin should not be registered to the "create" message, but to the "associate" message instead.


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.

    Friday, October 12, 2012 7:13 AM
  • bulk opeation means quick campaign,

    i am creating a quick campaign on a marketing list (contacts).

    Friday, October 12, 2012 8:31 AM
  • hi solved this issue changing the plugin logic.

    I created a plugin which executes in async-post create. In the plugin logic i am deleting the activities which are not meating the criteria.

    But still i ddint find the logic to cancel the child transaction alone without affecting the parent transaction.

    Friday, October 12, 2012 8:48 AM
  • Hello Samuel,

    I was interested by your problem, so I tried to reproduce the error. I created a plugin and registered it to the Pre-Operation stage in Synchronous mode of the Fax entity on the Create message. In this Plugin I am using this code:

    public void Execute(IServiceProvider serviceProvider)
            {
                var pluginContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                var recipients = ((Entity)pluginContext.InputParameters["Target"]).GetAttributeValue<EntityCollection>("to").Entities;
    
                foreach (var rec in recipients)
                {
                    if (rec.GetAttributeValue<EntityReference>("partyid").Id == new Guid("266065E7-9413-E211-85A5-00155D64D92C"))
                    {
                        throw new InvalidPluginExecutionException("test");
                    }
                }
            }

    So I am allowing faxes to be created for everyone except for one specific contact.

    Then I started a quick campaign with fax for all my contacts. I got the desired results, all contacts have a fax activity, except the one I define above. 

    So I am wondering why it is not working for you...

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.

    • Marked as answer by samuel s Friday, October 12, 2012 10:40 AM
    Friday, October 12, 2012 10:06 AM
  • Hi Pavlos,

    Thanks for your efforts.

    Actullay it is the problem with my test data. it is working fine the way u mentioned it above.

    Friday, October 12, 2012 10:40 AM