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

I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 60 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans