web
You’re offline. This is a read only version of the page.
close
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

Delete CRM plugin sdkmessageprocessingstep

(0) ShareShare
ReportReport
Posted on by 10

Hi all,

I am developing a plugin for auto-number on a field of any entity.plugin working fine and done following registration steps:
1.Message=Create
2.PrimaryEntity=none
3.Scoundry Entity=none

4.Stage of execution=PreOperation
5.Execution Mode=Synchronous
6.Development

Problem:
When I am uninstalling solution from then getting following error:

Auto Number Solution cannot be deleted due to dependencies from other components in the system. Remove all dependencies to allow for solution deletion.

 The above error is due to sdkmessageprocessingstep are not deleting after deleted record from CRM grid.

CODE

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
//</snippetAssignAutoNumberPlugin2>
string messageName = context.MessageName;

if (entity.LogicalName == "dots_autonumber")
{
if (messageName.ToLower() == "create")
{

SdkMessageProcessingStep step = new SdkMessageProcessingStep
{
AsyncAutoDelete = false,
Mode = new OptionSetValue((int)CrmPluginStepMode.Synchronous),
Name = _pluginTypeName + ": " + entity.Attributes["new_name"].ToString(),
EventHandler = new EntityReference("plugintype", GetPluginTypeId(OrganizationService)),
Rank = 1,
SdkMessageId = new EntityReference("sdkmessage", GetMessageId(OrganizationService)),
Stage = new OptionSetValue((int)CrmPluginStepStage.PreOperation),
//Stage = new OptionSetValue((int)CrmPluginStepStage.PostOperation),
SupportedDeployment = new OptionSetValue((int)CrmPluginStepDeployment.ServerOnly),
SdkMessageFilterId = new EntityReference("sdkmessagefilter", GetSdkMessageFilterId(entity.Attributes["new_targetentitylogicalname"].ToString(), OrganizationService)),
Description = entity.Attributes["new_targetattributelogicalname"].ToString()
};
var SdkMessageProcessingStepId = OrganizationService.Create(step);

entity.Attributes.Add("new_sdkmessageprocessingstepid", SdkMessageProcessingStepId.ToString());
}

}
else
{

var entityDetail = GetEntityByName(entity.LogicalName, OrganizationService);
if (entityDetail != null)
{
if (entity.Attributes.Contains(entityDetail.TargetAttributeLogicalName) == false)
{
var InitalValue = GetNewCode(entityDetail);
var setValue = (InitalValue == null || InitalValue == "") ? "0" : InitalValue;
string[] splitValues;
if (setValue.Contains("#"))
{
splitValues = setValue.Split('#');
entity.Attributes.Add(entityDetail.TargetAttributeLogicalName, splitValues[0] + "" + splitValues[1]);
int incrementValue = Convert.ToInt32(splitValues[1]);
IncreaseCurrentNumber(entity.LogicalName, incrementValue, OrganizationService);
}
else
{

entity.Attributes.Add(entityDetail.TargetAttributeLogicalName, setValue);
int incrementValue = Convert.ToInt32(setValue);
IncreaseCurrentNumber(entity.LogicalName, incrementValue, OrganizationService);
}
}
}

}
}
else if (context.InputParameters["Target"] is EntityReference)
{
if (context.PrimaryEntityName == "dots_autonumber")
{
if (context.MessageName == "Delete")
{

Guid id = ((EntityReference)context.InputParameters["Target"]).Id;
DSAutoNumber entity2 = OrganizationService.Retrieve(context.PrimaryEntityName, id, new ColumnSet("new_sdkmessageprocessingstepid")).ToEntity<DSAutoNumber>();
OrganizationService.Delete("sdkmessageprocessingstep", new Guid(entity2.SdkMessageProcessingStepId.ToString()));


}
}
}

Any suggestion plz.

 

I have the same question (0)
  • Joana Pinto Profile Picture
    740 on at

    Hi,

    Did you debugg your code to see if you enter in this IF?

    if (context.MessageName == "Delete")
    {
        Guid id = ((EntityReference)context.InputParameters["Target"]).Id;
        DSAutoNumber entity2 = OrganizationService.Retrieve(context.PrimaryEntityName, id, new ColumnSet("new_sdkmessageprocessingstepid")).ToEntity();
        OrganizationService.Delete("sdkmessageprocessingstep", new Guid(entity2.SdkMessageProcessingStepId.ToString()));
    }

  • Akramdots Profile Picture
    10 on at

    Thanks Joana Pinto for reply,

    No, I traced  code by using tracingService.Trace("Enter in EntityReference"); but does not enter in "context.InputParameters["Target"] is EntityReference" condition .

  • Suggested answer
    Joana Pinto Profile Picture
    740 on at

    You should debugg your code to see the type of context.InputParameters["Target"], to understand what is happening.

    Are you sure that your step is configured to the "Delete" event and not another one?

  • erhan.keskin Profile Picture
    2,253 on at

    Hi,

    Have you checked these?

    1) Dependencies of the Sdk Message Processing Step

    2) State of Sdk Message Processing Step is not Managed

    Regards,

  • Suggested answer
    Akramdots Profile Picture
    10 on at

    Thanks Joana Pinto,

    I was forget to delete step.

    Its working!!!

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

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
Tom_Gioielli Profile Picture

Tom_Gioielli 171 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 83

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans