Gaby Marquez
Gaby Marquez

Reputation: 53

Dynamics CRM how to bring the current Id of a entity record

I'm new in the community, I'm strugging with a plugin of a form, where I need to get all the values of that form, in order to achive this I created a preOperation Update Plugin. My plugin works perfectly only if I modify the fields inside that form. However, a normal user (I'm an admin) cannot modify any value of the form. I read that I can use the method

service.Retrieve(string entityName, Guid id, ColumnSet columnSet);

My question is how can I get the Guid id of the current record? Sorry if it is to obvious but I'm new in Dynamics CRM, I appreciate any help you can give me.

Upvotes: 1

Views: 7918

Answers (2)

Umer Sufyan
Umer Sufyan

Reputation: 166

If you dont want to use pre/post image of the entity, you can retrieve the record as you mentioned in your question. Getting id of the current record is easy if your plugin is registered on update message.

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

Also have a look at this.

https://community.dynamics.com/crm/b/crminogic/archive/2010/07/26/pre-image-38-post-image-explained-33

Upvotes: 4

dynamicallyCRM
dynamicallyCRM

Reputation: 2990

As your plugin is registered at pre-operation level, the record would not have been written to the database yet.

You will have to use the pre-entity image that you have registered to access the attributes (form values).

var pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var entity = pluginExecutionContext.PreEntityImages["ImageName"]; //the name that you have registered your image with
//iterate through all the attributes 
foreach (var attribute in entity.Attributes)
{
  //access the attribute values
  var attributeValue = attribute.Value;  
}

Upvotes: 3

Related Questions