Pages

Banner 468 x 60px

 

Thursday, April 19, 2018

Get workflow information using x++

0 comments
Hi Guys, I share how to Get Workflow Information AX using X++ :

Get workflow information using x++ :

Display str ApproveDate()
{
    WorkflowTrackingStatusTable     workflowTrackingStatus;
    WorkflowTrackingTable           workflowTrackingTable;
    WorkflowTrackingCommentTable    workflowTrackingCommentTable;
    UserInfo                        userInfo;
    Name                            _name;

    select firstFast RecId, User from workflowTrackingTable
    order by RecId desc
    join workflowTrackingCommentTable
    where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId
    join UserInfo
    where UserInfo.id == WorkflowTrackingTable.User
    exists join workflowTrackingStatus
    where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId
    && workflowTrackingStatus.ContextRecId == _getPR.RecId
    && workflowTrackingStatus.ContextTableId == tableNum(PurchreqTable) //PurchTable
    && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval;
    if (workflowTrackingTable.RecId > 0)
    {
        return ": " + strFmt('Approve Date : %1 - Approve Name : %2',  datetime2str(workflowTrackingCommentTable.createdDateTime,123), userInfo.name);
    }
    else
    {
        return '';
    }
}

Ask me if you have a problem, please email to : adityomagnet@gmail.com
Read more...

Wednesday, April 18, 2018

Rename Product Name in EcoresProductTranslation AX 2012

0 comments
  1. Hai guys, I want to share how to Rename Product Name in EcoresProductTranslation Table AX 2012 :


If you have problem, please email to me : adityomagnet@gmail.com

Thanks in advance
Read more...

throw error in x++

0 comments

throw error in x++ :

public void closeOk()
{
    List                ordersToUpdate = new List(typeName2Type(extendedTypeStr(RecId)));
    FormRun             callerForm = element.args().caller();
    MultiSelectionHelper selection = MultiSelectionHelper::createFromCaller(element.args().caller());
    SalesTable          salesTable = selection.getFirst();
    CustTrans           custTrans;
    BankPaymCancel      bankPaymCancel;
    Args                args;
    MCRCustPaymTable    mcrCustPaymTable;
    UserId              User1, User2;
    ABUUserParameter    ABUUserParameter;
    User2 = curUserId();
    User1 = ABUUserParameter::findUser(User2).User;   
    //if(curUserId() != User1)
    if(curUserId() == User1) // test
    {
        if(salesTable.DocumentStatus == DocumentStatus::PackingSlip ||
           salesTable.DocumentStatus == DocumentStatus::PickingList ||
           salesTable.DocumentStatus == DocumentStatus::Invoice ||
           salesTable.DocumentStatus == DocumentStatus::Confirmation) // test
        {
            throw error("Order sudah di packing / picking / invoice, silahkan konfirmasi ke gudang untuk cancel order");
        }
    }
    //end

    while (salesTable)
    {
        ordersToUpdate.addEnd(salesTable.RecId);
        salesTable = selection.getNext();
    }

    SalesUpdateRemain::cancelRemainderOnManySalesOrders(ordersToUpdate.pack());

    salesTable = selection.getFirst();
    while (salesTable && RetailPricingEngine::isMCROrder(salesTable.SalesId))
    {
        mcrCustPaymTable = MCRCustPaymTable::findByRefRecIDRefTableID(salesTable.RecId, salesTable.TableId);

        if(mcrCustPaymTable && mcrCustPaymTable.CustPaymType == MCRCustPaymType::GiftCard)
        {
            while select forUpdate custTrans
                where custTrans.MCRPaymOrderID == salesTable.SalesId
                      && custTrans.CancelledPayment == NoYes::No
            {
                bankPaymCancel = BankPaymCancel::newBankPaymCancel(custTrans, true);

                args = new Args();
                args.caller(bankPaymCancel);
                args.record(custTrans);
                BankPaymCancel::serverRun(args);
            }
        }

        salesTable = selection.getNext();
    }

    if (callerForm)
    {
        callerForm.dataSource().research(true);
    }

    super();
}

Read more...

create Purchase Requisitions using x++

0 comments
create Purchase Requisitions using x++ :

void clicked()
{
    PurchReqTable                   purchReqTable;
    PurchReqApprovalEventHandler    PurchReqApprovalEventHandler;
    PurchReqLine                    purchReqLine;

    // Get Procurement Category
    InventTable                     _inventTable;
    EcoResProduct                   _EcoResProduct;
    EcoResProductCategory           _EcoResProductCategory;

    ProjTable                       _projTable = projTable::find(RUM_MasterProjectHeader.Value);

    // Get Clicked
    RUM_MasterProjectLines          GetClicked_RUM_MasterProjectLines;

    // Get UnitID
    EcoResProductName               _productName;
    EcoResProductTranslation        _EcoResProductTranslation;


    // get defaultdimension
    DimensionAttribute              _DimensionAttribute;
    DimensionAttributeValue         _DimensionAttributeValue;
    DimensionFinancialTag           _DimensionFinancialTag;
    DimensionAttributeValueSetItem  _DimensionAttributeValueSetItem;
 
    purchReqLine                    _purchReqLine;

    ;

    ttsBegin;
    purchReqTable.clear();
        purchReqTable.initValue();
        purchReqTable.PurchReqId        = NumberSeq::newGetNum(PurchReqTable::numRefPurchReqId()).num();
        purchReqTable.PurchReqName      = RUM_MasterProjectHeader.Description;
        PurchReqTable.ProjId            = RUM_MasterProjectHeader.Value;
        purchReqTable.ProjIdDataArea    = RUM_MasterProjectHeader.dataAreaId;
        PurchReqTable.RequisitionStatus = RUM_MasterProjectHeader.Status;
    purchReqTable.insert();
    ttsCommit;

     for(GetClicked_RUM_MasterProjectLines = getFirstSelection(RUM_MasterProjectLines_ds); GetClicked_RUM_MasterProjectLines; GetClicked_RUM_MasterProjectLines = RUM_MasterProjectLines_ds.getNext() )
    {
           ttsbegin;
           purchReqLine.clear();
                purchReqLine.LineType = PurchReqLineType::Item;
                purchReqLine.initValue();
                purchReqLine.InventDimId                      = GetClicked_RUM_MasterProjectLines.InventDimId;
                purchReqLine.initFromPurchReqTable(purchReqTable);

                //_inventTable = InventTable::find(GetClicked_RUM_MasterProjectLines.itemnumber);
               // select _EcoResProduct where _EcoResProduct.RecId == _inventTable.Product;
               // select _EcoResProductCategory where _EcoResProductCategory.Product == _EcoResProduct.RecId;

                purchReqLine.BuyingLegalEntity                = CompanyInfo::find().RecId;
                purchReqLine.ItemId                           = GetClicked_RUM_MasterProjectLines.ItemNumber;
                purchReqLine.InventDimIdDataArea              = curext();

                // purchReqLine.ProcurementCategory              = _EcoResProductCategory.Category;
                //  purchReqLine.ActivityNumber = salesLine.ActivityNumber;
                //  purchReqLine.ReceivingOperatingUnit = 22565423099;
                //  purchReqLine.DefaultDimension = str2int64("22565466744");
     
                _DimensionAttribute = DimensionAttribute::findByName(RUM_MasterProjectHeader_dimensionlist.text(PurchParameters::find().BITDimensionlist));
                select firstOnly _DimensionAttributeValue where _DimensionAttributeValue.DimensionAttribute == _DimensionAttribute.RecId;
                select firstOnly _DimensionAttributeValueSetItem where _DimensionAttributeValueSetItem.DimensionAttributeValue ==_DimensionAttributeValue.RecId;
             
                purchReqLine.DefaultDimension = _DimensionattributeValueSetItem.DimensionAttributeValueSet;//_DimensionattributeValueSetItem.DimensionAttributevalue;


                purchReqLine.PurchQty           = GetClicked_RUM_MasterProjectLines.QtyPlan;
                purchReqLine.PurchPrice         = GetClicked_RUM_MasterProjectLines.PricePlan;
                purchReqLine.LineAmount         = GetClicked_RUM_MasterProjectLines.QtyPlan * GetClicked_RUM_MasterProjectLines.PricePlan;
                purchReqLine.CurrencyCode       = GetClicked_RUM_MasterProjectLines.CurrencyCode;
                PurchReqLine.RequisitionStatus  = GetClicked_RUM_MasterProjectLines.Status;


                purchReqLine.initFromInventTable(InventTable::find(GetClicked_RUM_MasterProjectLines.itemnumber), true , false);

                //purchReqLine.initFromProjTable(_projTable);
            purchReqLine.insert();
            ttsCommit;
    }

                if (purchReqLine.CurrencyCode != purchReqLine.orig().CurrencyCode && purchReqLine.orig().CurrencyCode)
                {
                    purchReqLine.write();
                }
                if (PurchReqWFStatusTransitionHelper::setPurchReqTable2InReview(purchReqTable.RecId))
                {
                    Workflow::activateFromWorkflowType("PurchReqReview", purchReqTable.RecId, "Auto-Submitted into workflow", false, curUserId() );
                }
                PurchReqWFStatusTransitionHelper::setPurchReqTable2Approved(purchReqTable.RecId,false);

    info(strFmt('Purchase Requisition has been created : %1', purchReqTable.PurchReqId));
}





















void clicked()
{
    PurchReqTable                   purchReqTable;
    PurchReqApprovalEventHandler    PurchReqApprovalEventHandler;
    PurchReqLine                    purchReqLine;

    // Get Procurement Category
    InventTable                     _inventTable;
    EcoResProduct                   _EcoResProduct;
    EcoResProductCategory           _EcoResProductCategory;

    // Get Clicked
    RUM_MasterProjectLines          GetClicked_RUM_MasterProjectLines;

    // Get UnitID
    EcoResProductName               _productName;
    EcoResProductTranslation        _EcoResProductTranslation;

    // get defaultdimension
    DimensionAttribute              _DimensionAttribute;
    DimensionAttributeValue         _DimensionAttributeValue;
    DimensionAttributeValueSetItem  _DimensionAttributeValueSetItem;
    ;

    ttsBegin;
    purchReqTable.clear();
        purchReqTable.initValue();
        purchReqTable.PurchReqId        = NumberSeq::newGetNum(PurchReqTable::numRefPurchReqId()).num();
        purchReqTable.PurchReqName      = RUM_MasterProjectHeader.Description;
        PurchReqTable.ProjId            = RUM_MasterProjectHeader.Value;
        purchReqTable.ProjIdDataArea    = RUM_MasterProjectHeader.dataAreaId;
        PurchReqTable.RequisitionStatus = RUM_MasterProjectHeader.Status;
    purchReqTable.insert();
    ttsCommit;

     for(GetClicked_RUM_MasterProjectLines = getFirstSelection(RUM_MasterProjectLines_ds); GetClicked_RUM_MasterProjectLines; GetClicked_RUM_MasterProjectLines = RUM_MasterProjectLines_ds.getNext() )
    {
           ttsbegin;
           purchReqLine.clear();
                purchReqLine.initValue();
                purchReqLine.initFromPurchReqTable(purchReqTable);

                purchReqLine.InventDimId                      = GetClicked_RUM_MasterProjectLines.InventDimId;

                _inventTable = InventTable::find(GetClicked_RUM_MasterProjectLines.itemnumber);
                select _EcoResProduct where _EcoResProduct.RecId == _inventTable.Product;
                select _EcoResProductCategory where _EcoResProductCategory.Product == _EcoResProduct.RecId;
                select _EcoResProductTranslation where _EcoResProductTranslation.Product == _EcoResProduct.RecId;
                purchReqLine.ProcurementCategory              = _EcoResProductCategory.Category;

                purchReqLine.BuyingLegalEntity                = CompanyInfo::find().RecId;
                purchReqLine.ItemId                           = GetClicked_RUM_MasterProjectLines.ItemNumber;
                purchReqLine.InventDimIdDataArea              = curext();

                //  purchReqLine.ActivityNumber = salesLine.ActivityNumber;
                //  purchReqLine.ReceivingOperatingUnit = 22565423099;

                _DimensionAttribute = DimensionAttribute::findByName(RUM_MasterProjectHeader_dimensionlist.text(PurchParameters::find().BITDimensionlist));
                select firstOnly _DimensionAttributeValue where _DimensionAttributeValue.DimensionAttribute == _DimensionAttribute.RecId;
                select firstOnly _DimensionAttributeValueSetItem where _DimensionAttributeValueSetItem.DimensionAttributeValue ==_DimensionAttributeValue.RecId;
                purchReqLine.DefaultDimension = _DimensionattributeValueSetItem.DimensionAttributeValueSet;

                purchReqLine.PurchQty                       = GetClicked_RUM_MasterProjectLines.QtyPlan;
                purchReqLine.PurchPrice                     = GetClicked_RUM_MasterProjectLines.PricePlan;
                purchReqLine.LineAmount                     = GetClicked_RUM_MasterProjectLines.QtyPlan * GetClicked_RUM_MasterProjectLines.PricePlan;
                purchReqLine.CurrencyCode                   = GetClicked_RUM_MasterProjectLines.CurrencyCode;
                PurchReqLine.RequisitionStatus              = GetClicked_RUM_MasterProjectLines.Status;
                purchReqLine.initFromInventTable(InventTable::find(GetClicked_RUM_MasterProjectLines.ItemNumber), true, false);

            purchReqLine.insert();
            ttsCommit;
    }


                if (purchReqLine.CurrencyCode != purchReqLine.orig().CurrencyCode && purchReqLine.orig().CurrencyCode)
                {
                    purchReqLine.write();
                }
                if (PurchReqWFStatusTransitionHelper::setPurchReqTable2InReview(purchReqTable.RecId))
                {
                    Workflow::activateFromWorkflowType("PurchReqReview", purchReqTable.RecId, "Auto-Submitted into workflow", false, curUserId() );
                }
                PurchReqWFStatusTransitionHelper::setPurchReqTable2Approved(purchReqTable.RecId,false);

    info(strFmt('Purchase Requisition has been created : %1', purchReqTable.PurchReqId));
}
Read more...

Convert time to GMT using x++ :

0 comments
Convert time to GMT using x++ :

DateTimeUtil::date(DateTimeUtil::removeTimeZoneOffset(PurchTable.createdDateTime, TimeZone::GMTPLUS0700_BANGKOK_HANOI_JAKARTA));
Read more...

Display item name product from product number using x++

0 comments
Display item name product from product number using x++ :

display SalesLineShowItemName itemnameproduct()
{
    return EcoResProductTranslation::findByProductLanguage(this.inventTable().Product,"en-us").Name;
}
Read more...

Monday, April 16, 2018

X++ code for check license Microsoft Dynamics AX 2012 R3

0 comments
Hi Everybody,

I want to share X++ code  for check license Microsoft Dynamics AX 2012 R3 :

static void ABUCheckLisense(Args _args)
{

    SysSecRoleEntryPointsTmp    srepTbl;
    SysUserLicenseMetadataTmp   slsaTmp;
    SecurityRole                securityRole;
    CommaTextIo                 commaTextIo;
    FileIOPermission            permission;
    MenuFunction                menuFunction;
    str                         menuLabel;
    str                         fileName = @"C:\Temp\TEST.csv";
    //str                         fileName = "C:\Temp\.csv";
    FromTime                    startTime = timeNow();
    #File

    //delete_from srepTbl;
    //delete_from slsaTmp;

    SysUserLicenseMiner::BuildLicenseMetadataTable(slsaTmp);
    SysUserLicenseMiner::BuildRoleToUserTypeInfo(slsaTmp, srepTbl);

    permission = new FileIOPermission(fileName,#io_write);
    permission.assert();
    commaTextIo = new CommaTextIo(fileName,#io_write);

    //Header
    commaTextIo.write(
        "Entry type",
        "Entry point AOT name",
        "Entry point label",
        "Role AOT name",
        "Role name",
        "License type");

    while select srepTbl
    /*    join securityRole
        where srepTbl.RoleRecId == 1085499//srepTbl.RoleRecId
        && securityRole.RecId == srepTbl.RoleRecId*/
    {
        menuFunction    = null;
        menuLabel       = '';
        switch (srepTbl.EntryPointType)
        {
            case EntryPointType::MenuItemAction:
                menuFunction = new MenuFunction(srepTbl.EntryPointName, MenuItemType::Action);
                break;

            case EntryPointType::MenuItemDisplay:
                menuFunction = new MenuFunction(srepTbl.EntryPointName, MenuItemType::Display);
                break;

            case EntryPointType::MenuItemOutput:
                menuFunction = new MenuFunction(srepTbl.EntryPointName, MenuItemType::Output);
                break;
        }

        if (menuFunction)
        {
            menuLabel = menuFunction.label();
        }

        commaTextIo.write(
            strFmt("%1",srepTbl.EntryPointType),
            srepTbl.EntryPointName,
            menuLabel,
            srepTbl.RoleAotName,
            SysLabel::labelId2String(securityRole.Name),
            strFmt("%1",srepTbl.UserLicType)
            );
    }
    CodeAccessPermission::revertAssert();

    info(strFmt("Total time: %1", timeConsumed(startTime, timeNow())));

}
Read more...

A financial dimension value is based on the record and has been used on a transaction. You cannot delete the record

  SOLUTION delete in table DimensionAttributeLevelValue base on Bank Account  :  and Delete the Bank Account FINISH