web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Plugin to populate the entitlement field getting an error : The given key was not present in the dictionary

(0) ShareShare
ReportReport
Posted on by

Hi all, I have written a plugin asynchronously populate the entitlement field during a case creation. Although I am getting an error of (System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary), I have registered my plugin in the post-operation pipeline with asynchronous execution mode. here is my snippet :

 if (inputParams.Contains("Target") && inputParams["Target"] != null && inputParams["Target"is Entity)
                {
 
                    Entity Case = new Entity("incident");
                    Guid caseGui = Case.Id;
                    string customerName = ((EntityReference)(Case.Attributes["customerid"])).Name;
                    Entity LovQuery = new Entity("entitlement");
                    Guid Entilguid = LovQuery.Id;
                    Entity allChecker = svc.Retrieve("entitlement", Entilguid, new ColumnSet(true));
                    if (allChecker.Attributes.Contains(customerName))
                    {
                      Guid EntitlementGuid = allChecker.Id;
                       Case["entitlementid"] = new EntityReference("entitlement", EntitlementGuid);
                    }
                    svc.Update(Case);
I just started to write a plugin , forgive me if I made any newbie mistake. please help me if I made any mistake, thank you  .
I have the same question (0)
  • Community Member Profile Picture
    on at
  • Verified answer
    Pankaj Gogoi Profile Picture
    3,177 on at

    Hi Subhajit,

    In your code, you are calling Entitlement based on Entilguid. But this is empty since LovQuery.Id is empty unless you didn't paste your whole code.

    You can query Entitlement entity based on entitlement name and fetch the entitlementId. Here is a link for FetchExpression to fetch the data.

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/use-fetchxml-construct-query

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.query.queryexpression?view=dynamics-general-ce-9

    I have written a blog related to this. Please refer the blog below.

    https://letssecure.wordpress.com/2020/08/23/assign-entitlement-to-case-using-plugin/

    Hope this helps

    Best Regards

    PG

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Line

    string customerName = ((EntityReference)(Case.Attributes["customerid"])).Name;

    generates your error because you haven't retrieved your case in the code so there is no properties available in the entity.

  • Community Member Profile Picture
    on at

    Thank you Pankaj for guiding me into right direction for developing plugin, it opened  more paths for my plugin development learning, thank you for taking the trouble to provide a blog for my request

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 156

#2
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans