Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

CRM Dynamics Plugin Share

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

HI Experts, 

 Hope all doing good and safe. I'm facing some issue and i'm new to CRM . Can you please help me how to solve this issue.

We have an entity name "X". Now, when I'm creating  a new record we have one field name "Internal Viewer Team" Its a lookup for all teams.

pastedimage1600746487551v1.png

1. If I keep blank on internal viewer team field and saved the record. In share button i must not see any team. - Passed. Its working fine.

pastedimage1600746487553v2.png 

2. Now, Scenario 2 : Selecting one team in  internal viewer team as test “team 191”. Now i am able to see that team in share with Read, Write , Append access - its working fine for me. Passed.

pastedimage1600746487554v3.pngpastedimage1600746487555v4.png  

3. Now Scenario 3 : Now, I'm Selecting other team in Internal viewer team as "XYZ". Now in share, I am able to see before one(i.e test team191) and this one as well. But my requirement is this "test team 191" must be removed automatically once i select other team. 

pastedimage1600746487555v5.png

Can any one help me out with plugin code on scenario 3 to actives the task. Will mark for qualified answer.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Dynamics Plugin Share

    Hi Kokulam, can you please suggest the below scenario

    I Have an "X" Entity in that i have a team lookup name as "Internal Team viewer". Now, when i create a new record,  the form consists of tabs called general, items, client.

    The 'X' entity has 1:n relationships for items, and client.

    Now, if i create a record, it will share to the team people who is in "Internal Team viewer". and now my task is that record must cascade to items, client as well.

    can you please tell me how to achieve? and approach?

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,050 on at
    RE: CRM Dynamics Plugin Share

    Is this a lookup field on that entity, "primary internal contact."?  If  so you do not need to retrieve all the records, you can just use the value from this lookup as that's the contact you want to send the email to.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Dynamics Plugin Share

    Hi,

    How can i retrieve all records in that lookup? because we dont know which contact they select

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,050 on at
    RE: CRM Dynamics Plugin Share

    Hi

    There are few different ways to approach this, the following sample code could be executed in the catch block when the sharing fails.

    pastedimage1600762625764v1.png

    The above code is just an example, feel free to change as per your needs

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,959 Super User 2024 Season 1 on at
    RE: CRM Dynamics Plugin Share

    Hi,

    You are sharing record through plugin code right?

    So you should add try and catch in your plugin code where you added the code to share your record.

    try

    {

    // Grant the team read/write access to the lead.

    var teamReference = new EntityReference(Team.EntityLogicalName, _teamId);

    var grantAccessRequest = new GrantAccessRequest

    {

       PrincipalAccess = new PrincipalAccess

       {

           AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess,

           Principal = teamReference

       },

       Target = leadReference

    };

    svc.Execute(grantAccessRequest);

    }

    catch(Exception ex)

    {

    //Here Add create Email Activity and Send Email code

    }

    Please mark my answer verified if i were helpful

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Dynamics Plugin Share

    when sharing fails, we will get an error in CRM Right? were we need to store that error?

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,959 Super User 2024 Season 1 on at
    RE: CRM Dynamics Plugin Share

    Hi,

    You should add try & catch in your share code. now in Catch you can use below code to create activity and send email from plugin.

    carldesouza.com/.../

    Make sure you register your plugin steps in Asynchronous mode because system does not allow you to catch exception in Synchronous plugin.

    Please mark my answer verified if i were helpful

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Dynamics Plugin Share

    Hi Kokulan,

    Apricated your response. I have one more scenario can u please help me out with the approach and plugin code .

    I have primary internal contact lookup and internal viewer team lookup on that form.

    If sharing fails -

    when there is a failure in synchronizing the Internal viewer team to record sharing an Internal comment activity must be created and email has to sent who the person is in primary internal contact.

    can u please help me out here. i will mark as verify

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,050 on at
    RE: CRM Dynamics Plugin Share

    Hi,

    It looks like your plugin code currently only doing the sharing, its not unsharing from the old team.

    You will have to update your code to unshare from previous team. For an update plugin, you can register both pre & post images.  You can get the previous team from the pre-image and do the unshare first and then share it with the new team. You can get the new team from the PostImage.

    If you would like to see the sample code for sharing and unsharing, please follow the link below

    saikrishnayadav.blogspot.com/.../Sharing and Unsharing the record using Plugin

    Please refer to the following link to see an example for pre & post image usage

    carldesouza.com/.../

    Hope this helps

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans