Skip to main content

Notifications

Announcements

No record found.

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  .
  • RE: Plugin to populate the entitlement field getting an error : The given key was not present in the dictionary

    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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Plugin to populate the entitlement field getting an error : The given key was not present in the dictionary

    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.

  • Verified answer
    Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: Plugin to populate the entitlement field getting an error : The given key was not present in the dictionary

    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

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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans