Skip to main content

Notifications

Announcements

No record found.

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 383
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);
            }
        }
    }
}
 
  • Suggested answer
    SachinBisht007 Profile Picture
    SachinBisht007 6 on at
    How to get attributes values on Pre-Operations on Create Plugin
    Hi Himanshu Kamboj,
    I suggest using JavaScript or a Power Automate flow to populate the fields instead of a C# plugin.
  • Himanshu Kamboj Profile Picture
    Himanshu Kamboj 383 on at
    How to get attributes values on Pre-Operations on Create Plugin
    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
    Adrian Begovich Profile Picture
    Adrian Begovich 1,019 Super User 2025 Season 1 on at
    How to get attributes values on Pre-Operations on Create Plugin
    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

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…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans