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;
}

Dynamics AX 2012 Code to meagre MainAccount Dimesion and Default Dimesion

Below is the to Code to meagre  MainAccount Dimesion and Default Dimesion   to get Ledger Dimension Account which is used in segmented while creating Journal voucher in LedgerJournalTrans

static void CreateLedgerDimension(Args _args)
{
    LedgerDimensionAccount  ledgerDimension,defaultDimension;
    LedgerDimensionAccount  empledgerdimension;
    LedgerDimensionAccount  mainAccDimension;
    HcmPositionDefaultDimension (empPositionDimension
    HcmPositionWorkerAssignment HcmPositionWorkerAssignment;
   
mainAccDimension = PayHeadTable::find('BasicRate').DebitAccount;

HcmPositionWorkerAssignment =   HcmPositionWorkerAssignment::getActivePositionWorkerAssignment(HcmWorker::findByPersonnelNumber('PID-0937').RecId);
       
select empposdimension where empposdimension.Position == HcmPositionWorkerAssignment.Position;
       
if(empPositionDimension)
empledgerdimension  =   empPositionDimension.DefaultDimension;

    defaultDimension = DimensionDefaultingService::serviceCreateLedgerDimension(mainAccDimension, empledgerdimension);


     info(strFmt("Before: %1", DimensionAttributeValueCombination::find(defaultDimension).DisplayValue));
 

}

Dynamics AX 2012 inserting data in Resource Dimension and fetching Default Dimension

DimensionDefault getDimension(ResourceTable _Resource)
{

DimensionAttribute DimensionAttribute;
DimensionFinancialTag  DimensionFinancialTag;

Struct struct = new Struct();

container defaultDimensionCon;
DimensionDefault workerDimensionDefault;

;
DimensionAttribute =  DimensionAttribute::findByName('Resource');

DimensionFinancialTag = DimensionFinancialTag::findByFinancialTagCategoryAndValue(DimensionAttribute.financialTagCategory(),_Resource.value,true);
        if(!DimensionFinancialTag)
        {
            DimensionFinancialTag.clear();
            DimensionFinancialTag.Description=_Resource.description;
            DimensionFinancialTag.Value=_HcmWorker.PersonnelNumber;
            DimensionFinancialTag.FinancialTagCategory=DimensionAttribute.financialTagCategory();
            DimensionFinancialTag.insert();


struct.add('Resource', _HcmWorker.PersonnelNumber);

defaultDimensionCon += struct.fields();

defaultDimensionCon += struct.fieldName(1);

defaultDimensionCon += struct.valueIndex(1);

workerDimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(defaultDimensionCon);

return workerDimensionDefault;
    }
    else
        return 0;
}

Monday, September 6, 2010

Enable User ID from SQL in AX 2009

Enabling user Id in Axapta 3.0 from SQL was easy you need to update enable field to 1 only this but in AX 2009 if coincidently you have disable userID having Administrator access then updating enable filed will not work few days back coincidently i had done the same :) disabled my ID now being only user having administrator privledge i got stuck.

Now to enable it from back end SQL you need to update enable flag to 1 and provide SID in UserInfo table to get SID you can user following job as provided in Screenshot in some other application in  but in same domain



then use following query in SQL 

select * from USERINFO where  ID = 'secu'

update USERINFO set ENABLE = 1 where ID = 'secu'

update USERINFO set SID = 'S-1-5-21-2656439898-1577874530-2966910584-8962' where ID = 'secu' 

all this to enable from SQL ...........
Cheerz.......

Friday, May 14, 2010

Microsoft Dynamics Convergence 2010 Web Seminar Series

Take time to review these highly rated web seminars from the Convergence Virtual Partner Briefing. They will give you important updates on upgrades & renewals, how to compete effectively against NetSuite, Partner Development Centers, new MPN requirements and Partner Business Systems.

Microsoft Dynamics Convergence 2010 Web Seminar Series

*Require partner source login

Tuesday, May 11, 2010

Sure Step 2010 Now Available

Microsoft Dynamics Sure Step 2010 is available for download now it provides a complete methodology—including project management discipline and field-tested best practices—plus user-friendly tools that enable you to more successfully deploy, migrate, configure, and upgrade.
Download and Install Sure Step* – NEW Sure Step 2010!
For more information on installing and using Sure Step, read the Sure Step User Guide.*

*Requires Partner source access

Monday, April 26, 2010

Open any object from code editor to in AOT node(Editor script)


I have posted a editor script method earlier that can open and browse table for code editor.using below code developer will have ease of opening any object from AX code editor to AOT node

TO USE THIS CODE COPY AND PASTE THE METHOD IN EDITOR SCRIPT CLASS

void AX_OpenInAOT(Editor e)
{
#AOT
TreeNode treeNode;
FreeText selectedLine;
str 1 curSymbol;
int iCopyFrom;
int iCopyTo;
Set selectedNodesSet = new Set(Types::Class);
SetIterator setIterator;
Map map;

void add2Set(TreeNodePath _path)
{
;
treeNode = TreeNode::findNode(_path + #AOTRootPath + selectedLine);
if (treeNode)
selectedNodesSet.add(treeNode);
}
;
if (e.markMode() != MarkMode::NoMark && e.selectionStartCol() != e.selectionEndCol())
{
selectedLine = strLRTrim(subStr(e.currentLine(), e.selectionStartCol(), e.selectionEndCol() - e.selectionStartCol()));
}
else
{
selectedLine = e.currentLine();
for (iCopyFrom = e.columnNo()+1; iCopyFrom >= 0; iCopyFrom--)
{
curSymbol = subStr(selectedLine, iCopyFrom, 1);
if (!strAlpha(curSymbol))
break;
}
for (iCopyTo = e.columnNo()+1; iCopyTo <= strLen(selectedLine); iCopyTo++) { curSymbol = subStr(selectedLine, iCopyTo, 1); if (!strAlpha(curSymbol)) break; } selectedLine = (iCopyFrom <> 0)
{
setIterator = new SetIterator(selectedNodesSet);
setIterator.begin();
if (selectedNodesSet.elements() == 1)
{
treeNode = setIterator.value();
}
else
{
map = new Map(Types::String, Types::String);
while (setIterator.more ())
{
treeNode = setIterator.value();
map.insert(treeNode.treeNodePath(), treeNode.AOTparent().treeNodeName());
setIterator.next();
}
treeNode = TreeNode::findNode(pickList(map, "Location", "Select element type"));
}
if (treeNode && treeNode.treeNodePath() != TreeNode::rootNode().treeNodePath())
{
if (SysTreeNode::hasSource(treeNode))
{
if (treeNode.AOTparent().treeNodePath() == #macrosPath && subStr(e.currentLine(), e.selectionStartCol () - 1, 1) != '#')
return;
treeNode.AOTedit();
}
else
{
treeNode.AOTnewWindow();
}
}
}
}
}