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

Notifications

Announcements

Community site session details

Community site session details

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

global static variable in x++

(0) ShareShare
ReportReport
Posted on by 100
Hi,

if let's say we have this class, and this method "sendBusinessEvent" gets called from multiple places.
let's say it gets called from CustTable, DirPartyLocation, ContactPerson..etc
public class BusinessEventSender
{
    private static boolean isDisabled;

    public static boolean isDisabled(boolean _isDisabled = isDisabled)
    {
        isDisabled = _isDisabled;
        return isDisabled;
    }

    public static void sendBusinessEvent(DirPartyRecId _RecId)
    {
		//logic

    }
}

so to show the bit i'm intreseted in. I want to send the business event if there is a change from DirPartyLocation or change in ContactPerson.
But i added this isDisabledFlag because contactPerson creation also call dirPartyLocation, so i don't wan to send multiple events in this case.
 
So i added this isDisabled flag in the businessEventSender class, by default it's false

now we have this code
 
[ExtensionOf(tableStr(DirPartyLocation))]
final class DirPartyLocationTable_Extension
{


    public void update()
    {
        ttsbegin;
        
        DirPartyLocation dirPartyLocationOld = this.orig();

        next update();

        if(!BusinessEventSender::isDisabled())
        {
            BusinessEventSender::sendBusinessEvent(this.Party);
        }

        ttscommit;
    }

}



[ExtensionOf(tableStr(ContactPerson))]
final class ContactPerson_Extension
{
    public void insert(boolean _updateDateAndTime, Name _name)
    {
        ttsbegin;

        next insert(_updateDateAndTime, _name);


        BusinessEventSender::isDisabled(true);

        BusinessEventSender::sendBusinessEvent(this.ContactForParty);

        ttscommit;
    }

    public void delete()
    {
        ttsbegin;

        
        if (this.conditionMet())
        {
            BusinessEventSender::sendBusinessEvent(this.ContactForParty);
        }

        next delete();
        
        ttscommit;
    }


}
 
 
when creating contactPerson i set the isDisabled flag to true, so that when DirPartyLocation class gets called after, it won't send a BE  (because when u create a contactPerson, DirPartyLocation class gets called)
 
it works but is it safe? what if a contactPerson got created and at the same time someone was updating DirPartyLocation from another place but at the same time? in this case i want it to skip dirPartyLocation business event coming from contactPerson but it should send a business event for the other update that is not related to contactPerson. So would the value become true for both if it got called at the same time? and what to do to overcome this?

so i want two BEs in this case not three

contact person creation BE - then  yes send
dirPartyLocation called from contact person creation -- don't send skip
pure dirPartyLocation update from another place at the same time -- yes send
 
 

 
Categories:
I have the same question (0)

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

News and Announcements

Season of Giving Solutions is Here!

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 405 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 322 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans