locked
CRM 2011 - On-Premise (IFD) Write a plugin that shares an opportunity with another user RRS feed

  • Question

  • I need to write a plugin that share opportunities with new users. Let me elaborate:

    The plugin is triggered when a new connection is created as follows:

    User selects an opportunity and click Connect from the Ribbon and selects connect to Another -> add a user with a role and save. At that point the plugin is triggered (when a new connection is created).

    I would like the plugin code that give read access to that opportunity to the user that the opportunity was connected to.

    Your help is greatly appreciated.

    Wednesday, April 3, 2013 5:44 PM

Answers

  • Hi Homayoun,

    You'll need some code like:

    Entity entity = (Entity)context.InputParameters["Target"];
    
    EntityReference record1id = entity.GetAttributeValue<EntityReference>("record1id");
    if (record1id.LogicalName == "opportunity")
    {
    Guid opportunityid=record1id.Id;
    // Code to share goes here
    }

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, April 3, 2013 6:40 PM
    Answerer

All replies

  • Hi,

    I suggest you use the Developer Toolkit (http://msdn.microsoft.com/en-gb/library/hh372957.aspx ) to register a plugin on Create of a Connection, test the from/to attributes and use the 'GrantAccessRequest' SDK Request to share the record:

    http://msdn.microsoft.com/en-us/library/hh547423.aspx

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, April 3, 2013 6:00 PM
    Answerer
  • Thank you so much Scott for your quick reply.

    I have created the plugin using the Developer Toolkit already on the Create Connection and it is being triggered. I am just trying to get the code for the GrandAccess. How do I test the from/to attribute?

    Wednesday, April 3, 2013 6:07 PM
  • Hi,

    A Connection has two attributes that are set to EntityReferences - Record1Id  and Record2Id.

    You'll need to look at the Target Image for these attributes and look at the LogicalName and Id properties of the EntityReferences they contain.

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, April 3, 2013 6:16 PM
    Answerer
  • Hi,

    Why you don't use the workflow for this purpose? You could trigger a workflow on create of a connection. Then you could use the workflow utilities for sharing.


    If the answer helped you, remember to mark it as answer.

    Wednesday, April 3, 2013 6:16 PM
    Moderator
  • Hi Payman,

    I had the link to CodePlex (given to me by a colleague). I am just trying to improve my plugin skills a little bit :-)

    Hi Scott,

    I have got that far already (the Record1Id is the opportunity id in this case, and Record2Id the new user id if I am not mistaken). I tried to look at those values but somehow they won't display for me.

    How do I look at the target image for those attributes and then the LogicalName and Id properties. That is I think what I mostly need at this time.

    If you could send me a simple sample code that would be great, otherwise, I do more research. At least with your advice I know I am on the right track. I will mark your reply as an answer anyways.

    Thanks,

    Homayoun

    Wednesday, April 3, 2013 6:28 PM
  • Hi Homayoun,

    You'll need some code like:

    Entity entity = (Entity)context.InputParameters["Target"];
    
    EntityReference record1id = entity.GetAttributeValue<EntityReference>("record1id");
    if (record1id.LogicalName == "opportunity")
    {
    Guid opportunityid=record1id.Id;
    // Code to share goes here
    }

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, April 3, 2013 6:40 PM
    Answerer
  • This is what I needed. This will get me going. Can't thank you enough. Have a wonderful day, Scott.

    Wednesday, April 3, 2013 6:48 PM