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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to get attributes values on Pre-Operations on Create Plugin

(0) ShareShare
ReportReport
Posted on by 429
Hi all,
 
I have a requirement, where I need to update contact fields on create event before the creation(Pre-Operation).
 
Like I have integrated the Dynamics with the third party application and from there I am creating the contacts but the time of creation few address fields are mandatory on contact level, which is blank on third party app side, so during the sync operation from third party app to dynamics 365, records is not getting create because of these mandatory fields are blank.
 
So I am thinking like, I will write a plugin to update those mandatory fields as N/A, during the creation of contact records so that creation of contact will not be fail.
And I am trying to Update one string type of id field (which is I am getting during the sync process from third party app) to another string type of field for my reference.
 
But the issue is, I am getting the null value in every fields which is having the values during the sync operation.
 
Anyone has any Idea about it, please provide your inputs.
 
I have pasted my code here
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace ACL.Plugins.Fintrx
{
    public class PrePopulatingAccountsField : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            try
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory orgFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService orgService = orgFactory.CreateOrganizationService(context.UserId);
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                if (context.Depth > 1)
                {
                    tracingService.Trace(/Inside Depth Check, Depth is grater than 1. Actual Depth:/ + context.Depth);
                    return;
                }
                // Obtain the target entity from the input parameters.
                Entity target = null;
                Entity entPreImage = null;
                if (context.MessageName.ToLower().Equals(/create/))
                {
                    target = (Entity)context.InputParameters[/Target/];
                   
                    tracingService.Trace(/Create Event Triggered.../);
                }           
                string firmcrdid = target.Contains(/abc_firmcrdid /) ? target.GetAttributeValue<string>(/abc_firmcrdid /) : null;       
                tracingService.Trace(/updated firmcrdid: /+ firmcrdid);
              
                if (firmcrdid != null )
                {
                    target[/abc_id/] =  firmcrdid;
                    tracingService.Trace(/Copied the firmcrdid./);
                  
                }
            }

            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
    }
}
 
I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at
    Hi Himanshu Kamboj,
    I recommend using JavaScript or a Business Rule to populate the fields instead of C# plugin.
     
    You cannot obtain a pre-image on a Create message.
    Message NameStage NamePre-ImagePost-Image
    CreatePre-OperationNoNo
    CreatePost-OperationNoYes
    UpdatePre-Operation
    YesNo
    UpdatePost-Operation
    Yes
    Yes
    DeletePre-Operation
    Yes
    No
    DeletePost-Operation
    Yes
    No
  • Himanshu Kamboj Profile Picture
    429 on at
    Hi Andrian,
     
    Thanks for the suggestion, but I can not create BR because I need to pre-populate the fields before the records creation, that's why I have registered my plugin on Create pre-operation. 
  • Suggested answer
    SachinBisht007 Profile Picture
    6 on at
    Hi Himanshu Kamboj,
    I suggest using JavaScript or a Power Automate flow to populate the fields instead of a C# plugin.

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 59 Super User 2025 Season 2

#3
TAHER Mehdi Profile Picture

TAHER Mehdi 37

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans