Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Unanswered

Error is not display on front

Posted on by 267

Hello Team,

Below i created plugin for Pre-Validation on invoice creating. 

Issue : In this code error is not throwing on front side in D365 Project and Operations but if i debug this code it is working well as per condition but same error is not display while creation of invoice if conditions true.

I checked same in Pre-Operation but still not working

my Code:

protected override void ExecuteCdsPlugin(ILocalPluginContext localContext)
{
if (localContext == null)
{
throw new InvalidPluginExecutionException(nameof(localContext));
}

ITracingService tracingService = localContext.TracingService;
IPluginExecutionContext context = (IPluginExecutionContext)localContext.PluginExecutionContext;
IOrganizationService currentUserService = localContext.CurrentUserService;
try
{

if (context.InputParameters.Contains("Target"))
{

Entity invoiceEntity = (Entity)context.InputParameters["Target"];
invoiceEntity.Id = context.PrimaryEntityId;

Entity invoiceEntityData = currentUserService.Retrieve(context.PrimaryEntityName, invoiceEntity.Id, new ColumnSet(true));

EntityReference contract = invoiceEntityData.GetAttributeValue<EntityReference>("salesorderid");
var contractId = contract.Id;

QueryExpression query = new QueryExpression { EntityName = "msdyn_contractlinescheduleofvalue", ColumnSet = new ColumnSet(true) };
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("msdyn_contract", ConditionOperator.Equal, contractId);
LinkEntity linkSetup = query.AddLink("salesorder", "msdyn_contract", "salesorderid", JoinOperator.Inner);
linkSetup.LinkCriteria.FilterOperator = LogicalOperator.And;
linkSetup.LinkCriteria.AddCondition("salesorderid", ConditionOperator.Equal, contractId);
query.Criteria.AddCondition("msdyn_invoicedate", ConditionOperator.LessThan, DateTime.Now);

DataCollection<Entity> fetchedcontractlinescheduleofvalueEntity = currentUserService.RetrieveMultiple(query).Entities;

if (fetchedcontractlinescheduleofvalueEntity.Count > 0)
{
throw new InvalidPluginExecutionException("You can not reaise invoice for this date.");
}
}

}
catch (InvalidPluginExecutionException ex)
{
throw new InvalidPluginExecutionException("An error occurred executing Plugin ISPLInvoicesValidation.ISPLInvoicesValidation.PreValidationinvoiceCreate .", ex);
}
}

Categories:

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans