This post is machine-translated. The original post in german language can be found here.

Create cost center by code

If you are ever embarrassed to have to create a cost center by code, this job may serve as inspiration:

static void createCostCenter(Args _args)
{
    str 30 _costCenter = "0815"; // Cost center id to create

    OMOperatingUnit omOperatingUnit;
    NumberSeqFormHandler numberSeqFormHandler;
    NumberSeq numberSeq;

    if (_costCenter)
    {
        if (!OMOperatingUnit::findName(
            _costCenter, OMOperatingUnitType::OMCostCenter))
        {
            ttsbegin;
            numberSeq = NumberSeq::newGetNumFromId(
                OMOperatingUnit::getNumberSequenceReference().NumberSequenceId);

            omOperatingUnit.clear();

            omOperatingUnit.initValue();
            omOperatingUnit.omOperatingUnitNumber = numberSeq.num();
            omOperatingUnit.Name = _costCenter;    // Id used as name
            omOperatingUnit.NameAlias = _costCenter;
            omOperatingUnit.omOperatingUnitType = OMOperatingUnitType::OMCostCenter;
            omOperatingUnit.LanguageId = CompanyInfo::languageId();

            if (omOperatingUnit.validateWrite())
            {
                omOperatingUnit.insert();
            }
            ttscommit;
        }
    }
}
These post applies to following version:
Dynamics AX 2012

 
 

 

 
 
 
Posts of the actual month
November 2024
MoTuWeThFrSaSu
 123
45678910
11121314151617
18192021222324
252627282930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.