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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Error is not display on front

(0) ShareShare
ReportReport
Posted on by 277

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);
}
}

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 139

#2
11manish Profile Picture

11manish 105 Super User 2026 Season 2

#3
ParthPatel249 Profile Picture

ParthPatel249 77

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans