locked
Workflow for sharing records RRS feed

  • Question

  • Hi,
    I need to create a workflow or a plug-in that should be triggered when a record is shared and where i will get some related recordss and share them to the same user or team and with the same permissions. How can i achieve this?
    Thanks in advance
    Friday, October 16, 2009 7:30 AM

Answers

  • Hi, Sabine.

    Base Code of such plugin:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Crm.Sdk;
    
    namespace TestPlugin
    {
    	public class SharingPlugin : IPlugin
    	{
    		#region IPlugin Members
    
    		public void Execute(IPluginExecutionContext context)
    		{
    			if (context.MessageName == MessageName.GrantAccess)
    			{
    				Guid entityId = ((Moniker)context.InputParameters["Target"]).Id;//identifier of shared record
    				string entityTypeName = ((Moniker)context.InputParameters["Target"]).Name;//entity type code of chared record - contact, account, e.t.c
    				AccessRights rights = (((PrincipalAccess)context.InputParameters["PrincipalAccess"])).AccessMask;//What rights are given to user or team
    				Guid accessingEntityId = (((PrincipalAccess)context.InputParameters["PrincipalAccess"])).Principal.PrincipalId;//identitifier of user or team who record is shared to
    				SecurityPrincipalType principalType = (((PrincipalAccess)context.InputParameters["PrincipalAccess"])).Principal.Type;//type of entity record is shared to - systemuser of team
    
    			}
    
    		}
    
    		#endregion IPlugin Members
    	}
    }
    
    I hope this will help you.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Friday, October 16, 2009 9:17 AM
    Moderator

All replies

  • Hi, Sabine.

    You can do it with plugin. Your plugin have to handle GrantAccess and ModifyAccess messages. Check full list of supported messages for plugins.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Proposed as answer by Laurentiu Dan Friday, October 16, 2009 8:01 AM
    Friday, October 16, 2009 7:33 AM
    Moderator
  • Hi,
    Can i have a sample code on which i can depend? And i also need to have a clear idea on how it's triggered and how parameters will be sent...
    I am dealing with custom entities.
    I'm new to plug-ins.
    Thanks
    • Edited by ms_crm Friday, October 16, 2009 8:57 AM details
    Friday, October 16, 2009 8:51 AM
  • Hi, Sabine.

    Base Code of such plugin:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Crm.Sdk;
    
    namespace TestPlugin
    {
    	public class SharingPlugin : IPlugin
    	{
    		#region IPlugin Members
    
    		public void Execute(IPluginExecutionContext context)
    		{
    			if (context.MessageName == MessageName.GrantAccess)
    			{
    				Guid entityId = ((Moniker)context.InputParameters["Target"]).Id;//identifier of shared record
    				string entityTypeName = ((Moniker)context.InputParameters["Target"]).Name;//entity type code of chared record - contact, account, e.t.c
    				AccessRights rights = (((PrincipalAccess)context.InputParameters["PrincipalAccess"])).AccessMask;//What rights are given to user or team
    				Guid accessingEntityId = (((PrincipalAccess)context.InputParameters["PrincipalAccess"])).Principal.PrincipalId;//identitifier of user or team who record is shared to
    				SecurityPrincipalType principalType = (((PrincipalAccess)context.InputParameters["PrincipalAccess"])).Principal.Type;//type of entity record is shared to - systemuser of team
    
    			}
    
    		}
    
    		#endregion IPlugin Members
    	}
    }
    
    I hope this will help you.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Friday, October 16, 2009 9:17 AM
    Moderator