Tuesday, January 27, 2015

"The internal time zone version number stored in the database is higher than the version supported by the kernel (8/7). Use a newer Microsoft Dynamics AX kernel.

"The internal time zone version number stored in the database is higher than the version supported by the kernel (8/7). Use a newer Microsoft Dynamics AX kernel

After Restoration of Database from one evironment to other we found one issue in AX 2012 R3 as

"Fatal SQL condition during login. Error message: "The internal time zone version number stored in the database is higher than the version supported by the kernel (8/7). Use a newer Microsoft Dynamics AX kernel."

Solution was simple

For the resolution you need to change the value for the column value  SYSTIMEZONESVERSION  in the table "SQLSystemVariables". if you look into the event viewer you can see that it find the value 8, but you need 7 (8/7).

Hence, 
The solution is to set the value to 7.

Select SYSTIMEZONESVERSION from SQLSystemVariables

update SQLSystemVariables
set SYSTIMEZONESVERSION = 7

Thursday, July 10, 2014

Number Sequence Error in AX 2012

While creating new number sequence we may come across this error "Default scope cannot be implicitly determined by the number sequence framework for the given datatype. Please provide scope information explicitly."

This generally comes when there is a conflict in a scope which is being entered in NumberSeqModule class and later changed fix this issue by below steps

*Please try this in testing environment first this will impact currently running number sequence as well

1. Find the EDT number which is conflicting
2. Run below job with EDT number
static void delteDatatyperef(Args _args)
{
    NumberSequenceDatatypeParameterType NumberSequenceDatatypeParameterType;
    NumberSequenceDatatype      NumberSequenceDatatype,lNumberSequenceDatatype;
    
    RefRecId    RefRecId = 105035;
    
    select NumberSequenceDatatype where NumberSequenceDatatype.DatatypeId == RefRecId;
    ttsBegin;
    delete_from NumberSequenceDatatypeParameterType where NumberSequenceDatatypeParameterType.NumberSequenceDatatype == NumberSequenceDatatype.RecId;
    delete_from lNumberSequenceDatatype where lNumberSequenceDatatype.DatatypeId == RefRecId;
    ttsCommit;
    

}

3. Run NumberSeqApplicationModule.load(); in another job as per module which is conflicting 

All will be working fine after this.



Thursday, April 17, 2014

How to change the value of a default dimension of a record in AX 2012

static void changeDimensionValue(Args _args)
{
    DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
    DimensionAttribute dimensionAttribute;
    CustTable custTable = CustTable::find("US-014");
    DimensionValue oldDimensionValue;
    DimensionValue newDimensionValue = "011";
    DimensionDefault newDimensionDefault;

    #define.dimensionName("CostCenter")

    DimensionValue getDimensonValue(DimensionDefault _dimensionDefault)
    {
        DefaultDimensionView defaultDimensionView;
        select firstonly DisplayValue
        from defaultDimensionView
        where defaultDimensionView.Name == #dimensionName
            && defaultDimensionView.DefaultDimension == _dimensionDefault;

        return defaultDimensionView.DisplayValue;
    }

    // Get current value
    oldDimensionValue = getDimensonValue(custTable.DefaultDimension);

    // Build DimensionAttributeValueSetStorage
    dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);

    // Remove old dimension value
    dimensionAttribute = DimensionAttribute::findByName(#dimensionName);
    dimensionAttributeValueSetStorage.removeDimensionAttributeValue(
        DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId);

    // Set new dimension value
    if(newDimensionValue != "")
    {
        dimensionAttribute = DimensionAttribute::findByName(#dimensionName);
        dimensionAttributeValueSetStorage.addItem(
            DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, newDimensionValue));
    }

    newDimensionDefault = dimensionAttributeValueSetStorage.save();

    ttsbegin;
    custTable.selectForUpdate(true);
    custTable.DefaultDimension = newDimensionDefault;
    custTable.update();
    ttscommit;

}

Wednesday, July 17, 2013

Job to get the position of an employee to print

static void GetEmplPosition(Args _args)
{
   HcmWorker hcmWorker;
   HcmPositionWorkerAssignment workerAssignment;
   HcmPosition hcmPosition;
   HcmPositionDetail   hcmPositionDetail;
 
   while select recid, person from hcmWorker
       join worker, position from workerAssignment
       where workerAssignment.Worker == hcmWorker.RecId
       join recid from hcmPosition
       where hcmPosition.RecId == workerAssignment.Position
       join position, description from hcmPositionDetail
       where hcmPositionDetail.Position == hcmPosition.RecId
   {       
       info(strFmt("%1's position is %2",hcmWorker.name(), hcmPositionDetail.Description));
   }
}




Wednesday, June 26, 2013

How to print export Dimensions

static void DAXPrintEmplDim(Args _args)
{

    HcmWorker worker;
    HcmEmployment employment;
    #AviFiles
    SysOperationProgress    progressBar = new SysOperationProgress();
    // Method to retuen dimension name
    str getDefaultDimensionValue(RecId defaultDimension, Name dimName)
    {
        str 255 ret;
        DimensionAttributeValueSetStorage dimStorage;
        dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
        ret = dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
        return ret;
    }  
    // Initialising progress bar
    progressBar.setCaption("Printing in progress...");
    progressBar.setAnimation(#AviTransfer);

    while select worker
    {
        progressBar.setText(strfmt("Employee %1", worker.name()));
        employment = HcmEmployment::getActiveEmploymentsByWorker(worker.RecId);
        if(employment.DefaultDimension)
        {
            info(strFmt("%1, %2, Department Value: %3", worker.PersonnelNumber, worker.name(), getDefaultDimensionValue(employment.DefaultDimension, "Department")));
        }
    }
}

How to create employee ID auto numbering system

public static str getNewPersonnelNumber()
{
    int maxLenght = 4;
    str tempEmployeeID;
    str newNumber;
    int newIndex;
    str companyIdx;
    HCMWorker localWorker;
    str ret;
    str 2 companyIdFilter;

    //Pickup the first digit as company name
    companyIdx = String::trimToLength(curext(), 1);
    companyIdx = strUpr(companyIdx);
    companyIdFilter = companyIdx + '*';
    select firstOnly localWorker
        order by localWorker.PersonnelNumber desc
        where localWorker.PersonnelNumber like companyIdFilter;
    tempEmployeeID = localWorker.PersonnelNumber;
    newNumber = String::replaceAll(tempEmployeeID, companyIdx, "");
    newIndex = str2int(newNumber);
    newIndex = newIndex + 1;
    newNumber = String::fillString(maxLenght - strLen(int2str(newIndex)), '0') + int2str(newIndex);
    newNumber = companyIdx + newNumber;
    ret  = newNumber;

    return ret;
}

Tuesday, June 25, 2013

Dynamics AX 2012 Import HR Postions X++ code

static void ImportPosition(Args _args)
{
SysExcelApplication     application;
SysExcelWorkbooks       workbooks;
SysExcelWorkbook        workbook;
SysExcelWorksheets      worksheets;
SysExcelWorksheet       worksheet;
SysExcelCells           cells;
COMVariantType          type;
OMOperatingUnit         OMOperatingUnit;
int                     row=1;

Name                                name;
FileName                            filename;
HcmPosition                         HcmPosition;
HcmPositionDetail                   HcmPositionDetail;
HcmPositionWorkerAssignment         HcmPositionWorkerAssignment;
HcmPositionDuration                 HcmPositionDuration;
str                                 job;
OMOperatingUnitNumber               department;

;
application = SysExcelApplication::construct();
workbooks   = application.workbooks();

filename = "C:\\import\\HRPosition.xlsx";
ttsBegin;

try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;

    HcmPosition.PositionId = cells.item(row, 1).value().bStr();
    HcmPosition.insert();
    department = cells.item(row, 2).value().bStr();
    job = cells.item(row, 3).value().bStr();
    select firstOnly OMOperatingUnit where OMOperatingUnit.OMOperatingUnitNumber == department;
    if(OMOperatingUnit)
    {
        HcmPositionDetail.Department    = OMOperatingUnit.RecId;
        HcmPositionDetail.Job           = HcmJob::findByJob(job).RecId;
        HcmPositionDetail.Position      = HcmPosition.RecId;

        HcmPositionDetail.Title         = HcmTitle::findByTitle(HcmJobDetail::findByJob(HcmPositionDetail.Job).Description).RecId;
        HcmPositionDetail.Description   = cells.item(row, 4).value().bStr();
        HcmPositionDetail.ValidFrom     = DateTimeUtil::newDateTime(cells.item(row, 5).value().date(),timeNow());
        HcmPositionDetail.ValidTo       = DateTimeUtil::maxValue();
        HcmPositionDetail.insert();
        HcmPositionWorkerAssignment.ValidFrom   = DateTimeUtil::newDateTime(cells.item(row, 5).value().date(),timeNow());
        HcmPositionWorkerAssignment.ValidTo     = DateTimeUtil::maxValue();
        HcmPositionWorkerAssignment.Position    = HcmPosition.RecId;
        HcmPositionWorkerAssignment.Worker      = HcmWorker::findByPersonnelNumber(cells.item(row, 6).value().bStr()).RecId;
        HcmPositionWorkerAssignment.insert();
        HcmPositionDuration.Position    = HcmPosition.RecId;
        HcmPositionDuration.ValidFrom   = HcmPositionWorkerAssignment.ValidFrom;
        HcmPositionDuration.ValidTo     = DateTimeUtil::maxValue();
        HcmPositionDuration.insert();

        type = cells.item(row+1, 1).value().variantType();
    print row;
    }
    }
while (type != COMVariantType::VT_EMPTY);
application.quit();
ttsCommit;
}