Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin triggered when adding a sharepoint document

(0) ShareShare
ReportReport
Posted on by

Hello Folks,

I'm trying to develop a plugin that fires when a sharepoint document is added to a CRM entity.
So for that I developed a plugin that is supposed to be triggered on a post operation creation on the entity SharePoint document that is described in this link: <<here>> https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/entities/sharepointdocument

Unfortunately, the plugin does not seem to trigger when I add a document.

Here is the way I have registed the step of the plugin:

step-registration.jpg

And here is the code of the plugin:

namespace CEP.Crm.Plugins
{
    using System;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    using CEP.Crm.Plugins.Manager;

 

    /// <summary>
    /// PostSharePointDocumentCreate Plugin.
    /// Fires when the record is created
    /// All Attributes
    /// </summary>    
    public class PostSharePointDocumentCreate : Plugin
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PostAccountUpdate"/> class.
        /// </summary>
        public PostSharePointDocumentCreate()
            : base(typeof(PostSharePointDocumentCreate))
        {
            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "create", "sharepointdocument", new Action<LocalPluginContext>(ExecutePostSharePointDocumentCreate)));

          
        }

                protected void ExecutePostSharePointDocumentCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            try
            {

                IPluginExecutionContext context = localContext.PluginExecutionContext;
                IOrganizationService orgService = localContext.OrganizationService;
                Entity inputEntity = (context.InputParameters != null && context.InputParameters.Contains("Target")) ? (Entity)context.InputParameters["Target"] : null;
                if (inputEntity == null)
                    return;
                throw new Exception("I'am in the plugin");
            }
            catch (InvalidPluginExecutionException iex)
            {
                throw iex;
            }
        }
    }
}

Does anybody could see why this plugin is not triggered when I had a sharepoint document from the ocument area of a CRM entity (account for example) ?

Is the plugin attached to a wrong entity ?

I use the server based sharepoint integration and the version of Dynamics 365 is Version 1612 (9.0.1.621) (DB 9.0.1.425) online.

Thanks in advance for your help,

Emmanuel Barache

*This post is locked for comments

  • Suggested answer
    Santosh bhagat Profile Picture
    464 on at
    RE: Plugin triggered when adding a sharepoint document

    Check below link

    dotnetdeveloper2012.blogspot.com/.../dynamics-crm-sharepoint-upload-event.html

  • Emmanuel Barache Profile Picture
    on at
    RE: Plugin triggered when adding a sharepoint document

    Hi Martijn,

    We have been able to address this need using MS Flows.

    We set a WF that capture the document attachment and the ID of the CRM record from the folder in order to set the link with the CRM entity.

    Best regards,

    Emmanuel

  • Suggested answer
    JohnAnonymous Profile Picture
    5,241 on at
    RE: Plugin triggered when adding a sharepoint document

    I can't answer the questions regarding the documentation.

    I don't think there's any option to fire any event from within CRM using a plugin if the document is stored in SharePoint. No matter what de documentations says. If you need to have this functionality, look at webhooks / flow / remote vent receivers for SharePoint and build your logic there. That path is very feasable in my opinion, but you need to have extensive SharePoint knowledge.

    My logic would be:

    - When a document is added / deleted / updated, fire an event (webhook or logic app would be my preferred choice)

    - Based on the location of the document, query to find the corresponding document location based on the relative path

    - Find the regarding object id of the document location and make any changes to the record you desire.

  • Emmanuel Barache Profile Picture
    on at
    RE: Plugin triggered when adding a sharepoint document

    Any ideas guys ? Really in deep trouble with that subject. We proposed to a customer some custom developments based on what is said on the MS Documention. The entity SharePointDocument is supposed to represent a Sharepoint document in the CRM. It appears on the list of available entities for plugins but that does not work !!!

    I had feedback on this thread that tells that this entity id dedicated to internal uses but my questions are :

    What internal uses ?

    Why expose it in the documention if not intended to be used ?

    Any clue to help in in my need (described upper in this thread)  ?

    Any help will be very appreciated !

    Thanks in advance dear experts ;)

    Emmanuel

  • Emmanuel Barache Profile Picture
    on at
    RE: Plugin triggered when adding a sharepoint document

    The subsidiary question would be: what is the entity displayed in the associated documents view of an entity and can a plugin be associated?

  • Emmanuel Barache Profile Picture
    on at
    RE: Plugin triggered when adding a sharepoint document

    Hi Jason,

    Thank you for your answer.

    Is there a way with a Dynamics plugin to cover the following need ? :

    When somebody from the document associated view within a CRM entity (like account for example), add a document, to fire a plugin where I can manage to check the regardingobjectID, check if the entity type of the regarding object is an account, and update the account with a flag if my condition is verified.

    What would be the best way to do that ?

    I really thought that this entity was containing the list of sharepoint documents assoicated to the CRM, and if not, I don't see the purpose of it. Internal use ok, but what ??? Mystery.

    Thanks in advance,

    Emmanuel

  • Verified answer
    jlattimer Profile Picture
    24,560 on at
    RE: Plugin triggered when adding a sharepoint document

    Matjin is correct there isn't a way to do this if the document originates in SharePoint or the SharePoint documents view in CRM.

    The SharePoint Document entity isn't used to track documents - it's just something for internal system use.

  • Emmanuel Barache Profile Picture
    on at
    RE: Plugin triggered when adding a sharepoint document

    Hi Martijn,

    When you are in CRM, for example on account entity, and you go to Document Associeted Grid, it displays a list of documents and I assume that this entity is SharepointDocument or many to many relation from SharepointDocument and account.

    What would be the use of the following entity : docs.microsoft.com/.../sharepointdocument ?

    Thanks for your message

    Emmanuel

  • Verified answer
    JohnAnonymous Profile Picture
    5,241 on at
    RE: Plugin triggered when adding a sharepoint document

    As far as I know this is not possible. CRM has know knowledge on what's happing in SharePoint. It just queries SharePoint on demand when you open the document Grid. I don't think the SharePoint document entity is used at all.

    I don't know what your logic is, but you should trigger the process from SharePoint, not from CRM.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans