Hi, please let me know how we can resolve this issue with this plugin.
Hi, please let me know how we can resolve this issue with this plugin.
For the Delete Operation:-
Why we not using "pre operation" instead of "Pre Validation".
that means "Delete_20" instead of "Delete_10".
Can't you just use plugin registration in XRM toolbox. Upon deletion of a specific type of record then throw a webhook. Use this webhook in power automate to create a flow and funnel all the specifics of a deletion or not. Even perhaps emailing the user of why something wasn't deleted?
I guess it just depends on the speed you need, where this record is being deleted from, etc.
EntityReference is a structure with an Id property of type Guid.
You need to use it in the fetch:
""
Still facing error please help me for this.
Error:- System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: An exception System.FormatException was thrown while trying to convert input value '[REDACTED]' to attribute 'quote.opportunityid'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). (Fault Detail is equal to Exception details:
ErrorCode: 0x80040224
Message: An exception System.FormatException was thrown while trying to convert input value '[REDACTED]' to attribute 'quote.opportunityid'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
TimeStamp: 2023-05-18T13:03:11.3085608Z
OriginalException: PluginExecution
ExceptionSource: PluginExecution
--
).
Code:-
case "Delete_20":
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference && context.MessageName == "Delete")
{
tracer.Trace("hi1");
target = context.InputParameters["Target"] as Entity;
tracer.Trace("hi2");
EntityReference opportunityReference = context.InputParameters["Target"] as EntityReference;
GetDraftQuote(opportunityReference, service);
tracer.Trace("hi3");
}
break;
default:
break;
private void GetDraftQuote(EntityReference opportunityReference, IOrganizationService service)
{
string Query = @"<fetch>" +
"<entity name='quote'>" +
"<attribute name='opportunityid' />" +
"<attribute name='statecode' />" +
"<filter type='and'>" +
"<condition attribute='opportunityid' operator='eq' value='" + opportunityReference + "' />" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"</filter>" +
"</entity>" +
"</fetch>";
EntityCollection result = service.RetrieveMultiple(new FetchExpression(Query));
if (result.Entities.Count > 0)
{
throw new InvalidPluginExecutionException("Delete an opportunity with draft quotes is not allowed.");
}
}
You can run it on pre-validation (Stage 10) to trigger the error as soon as possible in the pipeline. Also, you don't need to be in the transaction.
To learn more: community.dynamics.com/.../when-to-use-the-pre-validation-stage-in-the-plugin-pipeline
Thankyou for replay delete operation run on stage 40??
post operation or else pre validation.??
// Get the opportunity from the input parameter "Target" var opportunityRef = execContext.InputParameters["Target"] as EntityReference; var hasDraftQuotesQuery = new FetchExpression($@" "); var result = orgService.RetrieveMultiple(hasDraftQuotesQuery); if (result.Entities.Count > 0) throw new InvalidPluginExecutionException("Delete an opportunity with draft quotes is not allowed.");
Thankyou for replay. but first we have to retrieve the quote that will related to particular opportunity right?? like this
@"<fetch>" +
"<entity name='quote'>" +
"<attribute name='opportunityid' />" +
"<attribute name='statecode' />" +
"<filter>" +
"<condition attribute='opportunityid' operator='eq' value='" + target + "' />" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"</filter>" +
"</entity>" +
"</fetch>";
Hi,
You can do it with a pre-validation plugin on delete message. Throw an InvalidPluginExecutionException exception if the opportunity has quotes in draft state. See: www.youtube.com/watch
Or you can create a real time workflow that trigger on pre-delete. See Goutam Das:'s answer: community.dynamics.com/.../prevent-delete-of-record
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156