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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to create new custom entity record from C# plugin code

(0) ShareShare
ReportReport
Posted on by

I am trying to create new custom entity record from C# plugin code, like:

Entity documentlog = new Entity("tal_documentsubmissionlog");
documentlog["tal_name"] = "Test Account";
Guid accountId = _iOrgService.Create(documentlog);
throw new InvalidPluginExecutionException("LOg creation test >>" + accountId.ToString());

I am able to throw exception like: "LOg creation test >>484b17a2-30e1-e611-8108-3863bb360098"

but records are not shown in CRM .

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at

    Hi

    Try the below code

    try{

    Entity documentlog = new Entity("tal_documentsubmissionlog");

    documentlog["tal_name"] = "Test Account";

    Guid accountId = _iOrgService.Create(documentlog);

    }

    catch(Exception ex)

    {

    throw new InvalidPluginExecutionException(ex.message);

    }

    Put InvalidPluginExecutionException in  the catch

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Please make sure the connection part is right.

  • Community Member Profile Picture
    on at

    I am calling plugin from custom entity ("tal_abcd" ) and i am able to access all data from "tal_abcd" entity , so i think connection part is right.

  • Verified answer
    Community Member Profile Picture
    on at

    I got the solution, if we throw exception from plugin then record will not create,so avoid to throw exception from plugin.

  • Community Member Profile Picture
    on at

    Hi! I know a plugin that can help log calls automatically in MS Dynamics. That app is Tenfold, a CTI and sales acceleration platform that offers features like call logging and call monitoring. You can check out Tenfold on the integrations page if you'd like to know more. www.tenfold.com/.../dynamics

  • Suggested answer
    Community Member Profile Picture
    on at

    catch (InvalidPluginExecutionException)
    {
    throw;
    }
    catch (Exception ex)
    {
    throw new InvalidPluginExecutionException("PluginName Plugin Error : " + string.Concat(ex.Message, ":", num, Environment.NewLine, num));
    }

  • Suggested answer
    Jeevarajan Kumar Profile Picture
    781 Most Valuable Professional on at

    Hi Pawan,

    Yes, as you said, once the exception is thrown, if a plug-in is executing in the database transaction, the entire transaction will be rolled back.

    Note: Pre-operation and Post-operation plugins will execute in the DB transaction for sure, Pre-validation might execute outside of the DB transaction as well.

    From MSDN:

    Plug-ins may or may not execute within the database transaction of the Microsoft Dynamics 365 platform. Whether a plug-in is part of the transaction is dependent on how the message request is processed by the pipeline. You can check if the plug-in is executing in-transaction by reading the IsInTransaction property inherited by IPluginExecutionContext that is passed to the plug-in. If a plug-in is executing in the database transaction and allows an exception to be passed back to the platform, the entire transaction will be rolled back. Stages 20 and 40 are guaranteed to be part of the database transaction while stage 10 may be part of the transaction.

    Any registered plug-in that executes during the database transaction and that passes an exception back to the platform cancels the core operation. This results in a rollback of the core operation. In addition, any pre-event or post-event registered plug-ins that have not yet executed and any workflow that is triggered by the same event that the plug-in was registered for will not execute

     

    Please mark this as answer if it is helpful.

  • Community Member Profile Picture
    on at

    Try using TracingService for logging.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans