Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieve method does not work in dynamics 365 online (version 9.0)

(0) ShareShare
ReportReport
Posted on by

Here is full code, when i trying to retrieve data. it does not work saying,

d8be1dff-fb39-e811-a833-000d3a33bdbd: Test.Test: Retrieve of contact] (full error file is attached with this thread)ErrorDetails-_2800_35_2900_.txt

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace Test
{
public class Test : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
throw new NotImplementedException();
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));

// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));

if (context.Depth == 1)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

// Obtain the target entity from the input parmameters.
EntityReference entity = (EntityReference)context.InputParameters["Target"];
//EntityReference entity = (EntityReference)context.OutputParameters["BusinessEntity"];


tracingService.Trace("3 - entity");
var contact = service.Retrieve("contact", entity.Id, new ColumnSet(true));
tracingService.Trace("4 - entity");
if (contact != null)
{
if (contact.Attributes.Contains("address1_name") == false)
{
Random rndgen = new Random();
contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString());
}
else
{
contact["address1_name"] = "i already exist";
}
service.Update(contact);
}
}
}
}
}

*This post is locked for comments

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    Hi,

    What is available under Target, it depends on message on which plugin is registered, can you share your details on which event you are registring your plugin ??

  • Suggested answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    Hi Vinay,

    I think you should have use below syntax, if you want to go with Entity as a Target.

    Because Target as an Entity does not have property entity.Id while Target as an EntityReference has.

    You need to get record guid from context instead of Entity object.If you use Target as an Entity.

    Entity entity = (Entity)context.InputParameters["Target"];

    tracingService.Trace("3 - entity");

    var contact = service.Retrieve("contact", context.PrimaryEntityId, new ColumnSet(true));

    Can also check below article for more info:

    [View:https://community.dynamics.com/crm/f/117/t/201583]

    Also, I would recommend to use Pre-Image instead of performing Retrieve query in order to get context entity unchanged field's data.

    It will avoid one additional DB call and improve plugin performace.

    Hope it helps

    Mark this as answer. If it helps.

    Cheers

    Arpit

  • RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    Getting 404 while opening your link.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    msdn.microsoft.com/.../gg309673.aspx;MSPPError=-2147217396

    Hi, you can check this one. If you using (EntityReference)context.InputParameters["Target"]   and it's works. It should be in  Delete message.

  • RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    Thank you everyone your suggestion helped me resolved my issue. while i'm trying to use "Entity" it does not work but it works with "EntityReference.

    Please let me know what is reason behind this

                 //Entity entity = (Entity)context.InputParameters["Target"];

                   EntityReference entity = (EntityReference)context.InputParameters["Target"];

                   tracingService.Trace("3 - entity");

                   var contact = service.Retrieve("contact", entity.Id, new ColumnSet(true));

                   tracingService.Trace("4 - entity");

                   if (contact != null)

                   {

                       if (contact.Attributes.Contains("address1_name") == false)

                       {

                           Random rndgen = new Random();

                           contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString());

                       }

                       else

                       {

                           contact["address1_name"] = "i already exist";

                       }

                       service.Update(contact);

                   }

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    You need to comment this line             //  throw new NotImplementedException();

  • Verified answer
    Abby Kong Profile Picture
    Abby Kong 6 on at
    RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    Hi K,

    The error says NotImplementedException.
    Try search in your plugin project source code to see if there is any throw new NotImplementedException()

    Regards,
    Abby

  • Verified answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    Hi Vinay,

    You have been written -

    throw new NotImplementedException in very first line inside the Execute method.

    And in your error file..it also gives the same error.

    Comment out this line and try.

    namespace Test

    {

       public class Test : IPlugin

       {

           public void Execute(IServiceProvider serviceProvider)

           {

               throw new NotImplementedException();

               ITracingService tracingService =

                   (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    If my answer helped to resolve your issue, kindly verify it by clicking 'Yes'. It would be helpful to the other community members seeking to resolve a similar issue.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.in

     

  • RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    namespace Test

    {

       public class Test : IPlugin

       {

           public void Execute(IServiceProvider serviceProvider)

           {

               throw new NotImplementedException();

               ITracingService tracingService =

                   (ITracingService)serviceProvider.GetService(typeof(ITracingService));

               // Obtain the execution context from the service provider.

               IPluginExecutionContext context = (IPluginExecutionContext)

                   serviceProvider.GetService(typeof(IPluginExecutionContext));

               if (context.Depth == 1)

               {

                   IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

                   IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                   // Obtain the target entity from the input parmameters.

                   Entity entity = (Entity)context.InputParameters["Target"];

                   //EntityReference entity = (EntityReference)context.OutputParameters["BusinessEntity"];

                   tracingService.Trace("3 - entity");

                   var contact = service.Retrieve("contact", entity.Id, new ColumnSet(true));

                   tracingService.Trace("4 - entity");

                   if (contact != null)

                   {

                       if (contact.Attributes.Contains("address1_name") == false)

                       {

                           Random rndgen = new Random();

                           contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString());

                       }

                       else

                       {

                           contact["address1_name"] = "i already exist";

                       }

                       //service.Update(contact);

                   }

               }

           }

       }

    }

    Still not working base on your suggestion same error again,

    i've register my plugin for "preoperation"

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Retrieve method does not work in dynamics 365 online (version 9.0)

    Hi,

    On which event you have registered your plugin ??

    // Obtain the target entity from the input parmameters.
    EntityReference entity = (EntityReference)context.InputParameters["Target"];

    you are not retrieving entity here instead you are using entityreference, to get entity you need to use below code

    Entity entity=(Entity)context.InputParameters["Target"];

    var contact = service.Retrieve("contact", entity.Id, new ColumnSet(true));
    tracingService.Trace("4 - entity");
    if (contact != null)
    {
    if (contact.Attributes.Contains("address1_name") == false)
    {
    Random rndgen = new Random();
    contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString());
    }
    else
    {
    contact["address1_name"] = "i already exist";
    }
    service.Update(contact);
    }

    It seems you are trying to update some attribute based on the address1_name exists or not ?? if yes you can simply write a pre create plugin where you don't need to use update statement instead you can simply add your attribute to property bag like you are using here, no need to call update method in this case

    contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString());

    Let me know if you need more information

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

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,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans