Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
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);
}
}

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans