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)

Global class variables in plug-ins - Microsoft Dynamics CRM

(0) ShareShare
ReportReport
Posted on by 990

Hi All,

I have a requirement where I need to get the unique sequence number from oracle database and assign it to entity record on pre-operation.

I have used global variables in my plugin, in that case the unique sequence number which is being fetched from database got repeated for entity records.

How to overcome this situation.

Regards,
Rahul

*This post is locked for comments

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at

    Don't use global variables in a plugin - you have no control over the instantiation of plugin class instances, so cannot rely on data consistency in global variables.

    If the oracle database is providing unique numbers, then can't you just query the oracle database each time to get a unique number ?

  • Rahul-Waghmare Profile Picture
    990 on at

    Thanks for reply,

    I am doing the same thing to get the new sequence number from oracle database and storing it in global variable to use it in plugin function. If I debug the plugin its working perfect, new number getting generated from database its getting stored in global variable as well. But if I register the plugin and try to run directly its generating same record number for me all the time.

    Regards,

    Rahul

  • Suggested answer
    Andreas Cieslik Profile Picture
    9,267 on at

    It does not help to use global variables to increment the sequence number as after each time the plugin fires the variables will not have the last incremented value automatically. You should try implement a more robost and thread-safe way of the numbering mechanismn.

    This article explains it very well:

    www.greenbeacon.com/.../how-to-implement-robust-auto-numbering-using-transactions-in-microsoft-dynamics-crm

    The way would be to fetch the value from the Oracle DB each time the plugin fires and increment it if necessary.

    Better approach would be to access a custom entity with the sequence numbers because this type of access is faster than establishing database connection each time the plugin fires.

    On this site is a free autonumber plugin source code available:

    celedonpartners.com/.../celedon-autonumber-solution-for-dynamics-crm

    Maybe you can adapt something from it.

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