Pages

Banner 468 x 60px

 

Wednesday, April 18, 2018

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

0 comments:

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