Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Simple update of record during the Create event.

Posted on by 20

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

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Simple update of record during the Create event.

    Hi Erik,

    First of all you need to "Stop Profiling" for the plugin step in the Plugin Registration Tool. Follow the steps in the link below to "Stop Profiling".

    https://docs.microsoft.com/en-us/powerapps/developer/data-platform/tutorial-debug-plug-in?tabs=prt#stop-profiling

    If the record is still not getting created, make sure that you have registered the plugin on "Pre-operation" not on "Pre-validation".

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Simple update of record during the Create event.

    Hi,

    Code seems to be fine and it should work without any issue.

    I would recommend you to uninstall the plugin profiler.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Suggested answer
    Moh Helper Profile Picture
    Moh Helper 250 on at
    RE: Simple update of record during the Create event.

    Hi,

    Someone installed  the plugin profiler in your environment. Uninstall it and the problem will be solved.

    Kr,

    M.Helper

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans