Simple table of books with prices.
Create a plugin to run in the Create message.
Plugin is run Synchronous and in pre-validation
Expected Result : take the price of the book and multiply it by 10% and store it in the GSTPrice field of the same record
namespace Library { public class CalcGSTPrice : IPlugin { public void Execute(IServiceProvider serviceProvider) { //Obtain the execution context from the service provider. Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); // create a trace log so you can see where in the code it breaks ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); // create access to service IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("have reached execute event in plugin."); Entity newRecord = (Entity)context.InputParameters["Target"]; if (newRecord != null) { if (newRecord.Contains("new_price")) { // Get price of book Decimal price = newRecord.GetAttributeValue("new_price").Value; // increase price of book by 10% price = Decimal.Multiply(price, (Decimal)1.1); // create new attribute and set value to new price of book newRecord.Attributes.Add("new_gstprice", new Money(price)); tracingService.Trace("Update of new_gstprice has completed"); } } tracingService.Trace("Last line of plugin execute method reached"); } } }
Actual Result: Exception is thrown but trace shows All lines of plug in were executed.
If I run the error log in debug all lines execute without an exception.
No new record is created.
Trace log shows exception message.
Exception Details |
Exception Details System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault: Download the details and load with Plug-in Profiler. |7VlLc9s2EP4rGh0y7YHiQ5REKbQyqe20msaRxnLSTi8dEFzKGFMAC4CWlF9fgCBpPSPZbhwfevBYAPa9wO4HIny3nKeNe CCMHrWdFtOswEUs5jQ2Vnz880HK2g23g3Da8gYlw1FTMWAnDVvpcwGtr1YLFqLdovxme05jmv/efVxim9hjixChUQUQ3MYnjOakFnOkVQ6GmRASXrWlDyHpl0sCvUbS8YvSpIRvSJpSgRgRmMxdEL7ONG6nMslhuyIrqlEXN6QOQw9x3Mt17Oc/o3TGXjdgdNrddsdv t3/9rQ/MCiBUlYyuGbVL49KYBvZvKtJv46QHR1s8pAmSbVv7PmJM1nhF4uAefa5FJys4z01zrSogiraM0J5kywRLYwm ugt23XsafACUrJ1yI0dvMpeapM/CUXhIIQnymRo1jP4iiAoNd1rKjda1sQua4VuSiyHMeJ26jX7yT9vua0d1n19DnjHFKTNCMPA/Jx27e8KHAt3/ViCwWxa3ndLo573T7u 6iQt8OpZy9Ubm/1wC1o6qEejZRioujp7LMAXmrr9oOTrN/HbIRmuZwgjuYgVZrL2KIjmVlynR3X1TtIcoSlqLIS7XDGSCJcklU58m2nZ09XQsK8dc7SFLAOg2j9ClTlGtfpQoPfYfUFpTlMEOHjRO1W5UG5yyqiaHAHKz24QXwGsnC3njME91pEvSvR4JJKIldrat5LJTnKJYinqaaw DtTlsMp2q8YhXXlhRY9VJEp NemSnn3G OTbHu8Ayom6QkO4IERVaUcHz IhbMRY3cNuQAqVw0VgZf0jIiIfj/H2n6nq/7avt/pvJRXqq7JXKhKfNKOGxcdYwqykL9v67k/auOpukAFKs4/zlVFpHhF4tPP8DUkoJnWnTLVDUVRBzmob EjpbFiqG1/KAY7G FwOey11quh/SDwI5sRjNJPqsIe8Le0YovQcOvRZqd/WL... (Fault Detail is equal to Exception details: ErrorCode: 0x80040265 Message: Download the details and load with Plug-in Profiler. |7VlLc9s2EP4rGh0y7YHiQ5REKbQyqe20msaRxnLSTi8dEFzKGFMAC4CWlF9fgCBpPSPZbhwfevBYAPa9wO4HIny3nKeNe CCMHrWdFtOswEUs5jQ2Vnz880HK2g23g3Da8gYlw1FTMWAnDVvpcwGtr1YLFqLdovxme05jmv/efVxim9hjixChUQUQ3MYnjOakFnOkVQ6GmRASXrWlDyHpl0sCvUbS8YvSpIRvSJpSgRgRmMxdEL7ONG6nMslhuyIrqlEXN6QOQw9x3Mt17Oc/o3TGXjdgdNrddsdv t3/9rQ/MCiBUlYyuGbVL49KYBvZvKtJv46QHR1s8pAmSbVv7PmJM1nhF4uAefa5FJys4z01zrSogiraM0J5kywRLYwm ugt23XsafACUrJ1yI0dvMpeapM/CUXhIIQnymRo1jP4iiAoNd1rKjda1sQua4VuSiyHMeJ26jX7yT9vua0d1n19DnjHFKTNCMPA/Jx27e8KHAt3/ViCwWxa3ndLo573T7u 6iQt8OpZy9Ubm/1wC1o6qEejZRioujp7LMAXmrr9oOTrN/HbIRmuZwgjuYgVZrL2KIjmVlynR3X1TtIcoSlqLIS7XDGSCJcklU58m2nZ09XQsK8dc7SFLAOg2j9ClTlGtfpQoPfYfUFpTlMEOHjRO1W5UG5yyqiaHAHKz24QXwGsnC3njME91pEvSvR4JJKIldrat5LJTnKJYinqaaw DtTlsMp2q8YhXXlhRY9VJEp NemSnn3G OTbHu8Ayom6QkO4IERVaUcHz IhbMRY3cNuQAqVw0VgZf0jIiIfj/H2n6nq/7avt/pvJRXqq7JXKhKfNKOGxcdYwqykL9v67k/auOpukAFKs4/zlVFpHhF4tPP8DUkoJnWnTLVDUVRBzmob EjpbFiq...). Exception Details-Details of the exception.
System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault: Download the details and load with Plug-in Profiler.|7VlLc9s2EP4rGh0y7YHiQ5REKbQyqe20msaRxnLSTi8dEFzKGFMAC4CWlF9fgCBpPSPZbhwfevBYAPa9wO4HIny3nKeNe CCMHrWdFtOswEUs5jQ2Vnz880HK2g23g3Da8gYlw1FTMWAnDVvpcwGtr1YLFqLdovxme05jmv/efVxim9hjixChUQUQ3MYnjOakFnOkVQ6GmRASXrWlDyHpl0sCvUbS8YvSpIRvSJpSgRgRmMxdEL7ONG6nMslhuyIrqlEXN6QOQw9x3Mt17Oc/o3TGXjdgdNrddsdv t3/9rQ/MCiBUlYyuGbVL49KYBvZvKtJv46QHR1s8pAmSbVv7PmJM1nhF4uAefa5FJys4z01zrSogiraM0J5kywRLYwm ugt23XsafACUrJ1yI0dvMpeapM/CUXhIIQnymRo1jP4iiAoNd1rKjda1sQua4VuSiyHMeJ26jX7yT9vua0d1n19DnjHFKTNCMPA/Jx27e8KHAt3/ViCwWxa3ndLo573T7u 6iQt8OpZy9Ubm/1wC1o6qEejZRioujp7LMAXmrr9oOTrN/HbIRmuZwgjuYgVZrL2KIjmVlynR3X1TtIcoSlqLIS7XDGSCJcklU58m2nZ09XQsK8dc7SFLAOg2j9ClTlGtfpQoPfYfUFpTlMEOHjRO1W5UG5yyqiaHAHKz24QXwGsnC3njME91pEvSvR4JJKIldrat5LJTnKJYinqaaw DtTlsMp2q8YhXXlhRY9VJEp NemSnn3G OTbHu8Ayom6QkO4IERVaUcHz IhbMRY3cNuQAqVw0VgZf0jIiIfj/H2n6nq/7avt/pvJRXqq7JXKhKfNKOGxcdYwqykL9v67k/auOpukAFKs4/zlVFpHhF4tPP8DUkoJnWnTLVDUVRBzmob EjpbFiqG1/KAY7G FwOey11quh/SDwI5sRjNJPqsIe8Le0YovQcOvRZqd/WL... (Fault Detail is equal to Exception details: ErrorCode: 0x80040265 Message: Download the details and load with Plug-in Profiler. |7VlLc9s2EP4rGh0y7YHiQ5REKbQyqe20msaRxnLSTi8dEFzKGFMAC4CWlF9fgCBpPSPZbhwfevBYAPa9wO4HIny3nKeNe CCMHrWdFtOswEUs5jQ2Vnz880HK2g23g3Da8gYlw1FTMWAnDVvpcwGtr1YLFqLdovxme05jmv/efVxim9hjixChUQUQ3MYnjOakFnOkVQ6GmRASXrWlDyHpl0sCvUbS8YvSpIRvSJpSgRgRmMxdEL7ONG6nMslhuyIrqlEXN6QOQw9x3Mt17Oc/o3TGXjdgdNrddsdv t3/9rQ/MCiBUlYyuGbVL49KYBvZvKtJv46QHR1s8pAmSbVv7PmJM1nhF4uAefa5FJys4z01zrSogiraM0J5kywRLYwm ugt23XsafACUrJ1yI0dvMpeapM/CUXhIIQnymRo1jP4iiAoNd1rKjda1sQua4VuSiyHMeJ26jX7yT9vua0d1n19DnjHFKTNCMPA/Jx27e8KHAt3/ViCwWxa3ndLo573T7u 6iQt8OpZy9Ubm/1wC1o6qEejZRioujp7LMAXmrr9oOTrN/HbIRmuZwgjuYgVZrL2KIjmVlynR3X1TtIcoSlqLIS7XDGSCJcklU58m2nZ09XQsK8dc7SFLAOg2j9ClTlGtfpQoPfYfUFpTlMEOHjRO1W5UG5yyqiaHAHKz24QXwGsnC3njME91pEvSvR4JJKIldrat5LJTnKJYinqaaw DtTlsMp2q8YhXXlhRY9VJEp NemSnn3G OTbHu8Ayom6QkO4IERVaUcHz IhbMRY3cNuQAqVw0VgZf0jIiIfj/H2n6nq/7avt/pvJRXqq7JXKhKfNKOGxcdYwqykL9v67k/auOpukAFKs4/zlVFpHhF4tPP8DUkoJnWnTLVDUVRBzmob EjpbFiq...). |
I'm unable to determine the cause of the issue as all lines of code in the plugin run without issue.
Any suggestions?
Erick