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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Store Global variables in Temporary Table

(0) ShareShare
ReportReport
Posted on by 46

Hello all,

I have the need to modify the originals methods JmgJobBundle\makeRegistration() and  JmgJobBundle\postTime() in order to insert a new custom column (AKS_CostCategory)  value in the JmgTermReg and JmgStampJournalTrans tables respectively.

the obstacule I have is that the values I need are declared in \Forms\JobRegistration which are ProdId prodId and RouteCostCategoryId costCatId . bypassing those values into jmgJobBundle class requires to change a lot parameters from many methods.

I wonder you guys can advice me if creating some kind of temporary table (AKS_CostCategoryTEMP) would be a good idea so i can store those values there and the access those values globally inside those methods by calling

IF (aks_CostCategoryTEMP) 

     AKS_CostCategoryTEMP::find().CostCatId

or is there a better way?

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Temporary table exists only in your current context (for example in the method where it's declared) so you can't use it to pass some information in later stage of a process.

    AKS_CostCategoryTEMP::find() will always return an empty buffer.

    You can use SysGlobalCache to store information that will be available later in the same session. But I recommend exploring other options first.

  • CBNestor Profile Picture
    46 on at

    Hi Nikolaos,

    The selected CostCatId will change as the workers start new jobs during the day. so many frequent the system needs to use it. How bad can the SysGlobalCache be?. or a normal Table will maybe do the job?

  • nmaenpaa Profile Picture
    101,172 Moderator on at

    Normal table would also work.

    With both approaches you need to be careful with transactions. If some transaction rolls back but your table / cache data doesn't, it might cause issues.

  • CBNestor Profile Picture
    46 on at

    The table wont store transaction history.

    I am thinking about creating just one row in which the fields I need (costCategoryId) will be updated every time a workers starts new jobs from the job registration.

    I dont know if update-read-update will be best than: insert-read-delete-insert.

  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Are you sure that one record in the table would work correctly when you have multiple users using the system at the same time?

    Also, my transaction comment has nothing to do with transaction history.

    What I mean was:

    1) User starts a process. You write some information to this table or global cache

    2) Transaction starts in Dynamics (ttsbegin)

    3) Transaction fails for any reason (ttsabort)

    4) Your data from step 1 stays in the system and might corrupt the next user's process (or same user's next attempt)

    So, you must make sure that whenever the standard process fails, your data gets cleaned up. If you use the table approach, just make sure that your table operations are in the same transaction scope than the actual process. If you use global cache, you could add a "finally" statement in the try-catch around the transaction. But unfortunately "finally" doesn't exist in AX2012, only in D365, so this will not be possible for you and you need some other solution.

  • Verified answer
    Martin Dráb Profile Picture
    239,647 Most Valuable Professional on at

    Don't forget that there may be hundreds of users using the same functionality at once. If you use just a single record, they would keep overwriting it and the result would be wrong.

    For example, user A runs the logic with category 1. But before it gets to the check, user B runs it too and set the category to 2, therefore user A will get category 2 as well. And user 3 won't set anything but the system will think that he set category 2.

    A workaround may be using session IDs, or using something that gets stored only in context of a single session (which should be true for static fields and SysGlobalCache).

    There is a reason why global data is consider an anti-pattern that should be avoided. Maybe you decide not to avoid it, but you should be very careful.

  • CBNestor Profile Picture
    46 on at

    Hi Martin,

    now you make me rethink about the approarch :,) , I forgot about that big detail, youre right.

    I haven't work with global variables or session IDs yet. Can you help get a better understanding. When  workers logs in the Job registration; a session ID is created? from there I should be able to store my "Sessioned global" variable?

  • CBNestor Profile Picture
    46 on at

    Hi Nikolaos,

    I see your point now, in that case would be better to have new transactions, but how to make sure that the last transaction stored is the one related to the user process in question...

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    You could store the transaction id in the table. And as long as you are inside a transaction, the changes are not committed to the database and not visible to others.

  • CBNestor Profile Picture
    46 on at

    That sound insteresting. May I ask you to develop a litte bit more. sorry for asking a lot.

    I set the CreatedTransactionId to Yes. but how to know which transactionId is which? when inserting from \Forms\JobRegistration and reading from Classes\JmgJobBundle? sorry That I dont follow you very well

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 692

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 532 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 478

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans