Skip to main content

Notifications

Announcements

No record found.

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

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans