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

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Plugin Error "An unexpected error occurred from ISV code"

(0) ShareShare
ReportReport
Posted on by 92

I added a plugin on create of a new form it takes l list specified on the form and takes the equipment inside the list to create for each equipment a station equipment.
when I register the plugin on Create it doe not create any station equipment. when i remove the relation between station equipment and the project station (in the code) the records are created.
of course, I tried to use the profiler and debugged the problem, but when debugging the code runs normally without any issue (with relation too).

I tried to register the step on update to debug and got this error "An unexpected error occurred from ISV code." I tried checking the error and I think it means my code is entering an infinite loop. So, I tried to debug again and the code works fine when debugging.

of course, the step is registered on post-operation synchronous.

this is the code below

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.PrimaryEntityId != null)
{
Entity entity = (Entity) context.InputParameters["Target"];

EntityReference projStationRef = new EntityReference("mfex2193_projectstation", context.PrimaryEntityId);

Entity prjStation = Functions.GetProjStationDet(service, context.PrimaryEntityId);

EntityReference station = prjStation.Contains("mfex2193_station") ? prjStation.GetAttributeValue<EntityReference>("mfex2193_station") : null;
EntityReference list = (prjStation.Contains("mfex2193_equipmentlist") ? prjStation.GetAttributeValue<EntityReference>("mfex2193_equipmentlist") : null) ?? throw new InvalidPluginExecutionException("Please choose a list.");
List<Entity> relatedEqu = Functions.GetRelatedEquipments(service, list.Id);

if (relatedEqu != null)
{
List<Entity> insertEnt = new List<Entity>();
foreach (Entity equipment in relatedEqu)
{
var equName = equipment.Contains("Equipment.mfex2193_name") ? equipment.GetAttributeValue<AliasedValue>("Equipment.mfex2193_name").Value.ToString() : "";
EntityReference equRef = new EntityReference("mfex2193_equipment", (Guid)equipment.GetAttributeValue<AliasedValue>("Equipment.mfex2193_equipmentid").Value);

//throw new InvalidPluginExecutionException(projStationRef.Id.ToString());

Entity newEnt = new Entity("mfex2193_stationequipment")
{
//Id = Guid.NewGuid(),
Attributes =
{
new KeyValuePair<string, object>("mfex2193_name",equName),
new KeyValuePair<string, object> ("mfex2193_station", station),
new KeyValuePair<string, object> ("mfex2193_equipment", equRef),
new KeyValuePair<string, object> ("mfex2193_projectstation", projStationRef)
}
};


insertEnt.Add(newEnt);
}

Functions.BulkInsert(service, insertEnt);
}
}

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 394

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 123

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 102 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans