Hi Experts,
I have a problem when I am uploading Purchase Order using JOB. There is one field from Purchase Order line that I need to upload, but when I do the personalized the SID is a method from PurchLine not a field.
Here is the screen shot from the Purchase Order line
![]()
The field of SID is PurchLine.ARPTaskWBSId
/////
static void UploadPOTest(Args _args)
{
InventDim inventDim;
InventSiteId inventSiteId;
InventLocationId inventLocationId;
Counter counter;
Struct struct = new Struct();
PurchTable purchTable;
PurchLine purchLine;
AssetBook assetBook;
VendTable vendTable;
AxPurchTable axPurchTable;
AxPurchLine axPurchLine;
ARPTaskTools arpTaskTools;
PurchFormLetter purchFormLetter;
PurchPrepayTable purchPrepayTable;
PurchTotals purchTotals;
container defaultDim;
int LineNum;
int row=2;
int _row=2;
int _row_prep=2;
SysExcelApplication application = SysExcelApplication::construct();
SysExcelWorkbooks workbooks = application.workbooks();
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
COMVariantType _type;
COMVariantType _type_prep;
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
;
startLengthyOperation();
dialog = new Dialog('ExcelUpload');
dialogFilename = dialog.addField(ExtendedTypeStr("FilenameOpen"));
dialogFilename.label('File Path');
dialog.filenameLookupTitle('Upload From Excel');
dialog.caption('Upload Purchase Order');
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
try
{
if (workbooks.open(filename, false, true))
{
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
//Create PO Headers
_row++;
_type = cells.item(_row, 1).value().variantType();
if (_type != COMVariantType::VT_EMPTY)
{
purchTable.clear();
vendTable = VendTable::find(cells.item(_row, 4).value().bStr());
purchTable.initFromVendTable(vendTable);
axPurchTable = AxPurchTable::newPurchTable(purchTable);
//axPurchTable.parmPurchId(NumberSeq::newGetNum(PurchParameters::numRefPurchId()).num());
axPurchTable.parmPurchId(cells.item(_row, 30).value().bStr());
axPurchTable.parmPurchaseType(PurchaseType::Purch);
axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
axPurchTable.parmProjId(cells.item(_row, 6).value().bStr());
axPurchTable.parmPurchIdLama(cells.item(_row, 3).value().bStr());
axPurchTable.parmPayment(cells.item(_row, 5).value().bStr());
axPurchTable.parmSettleVoucher(SettlementType::OpenTransact);
axPurchTable.parmWorkerPurchPlacer(HcmWorker::userId2Worker(curUserId()));
axPurchTable.parmDeliveryDate(cells.item(_row, 1).value().date()); //(str2date("11/3/2016",213));
axPurchTable.parmAccountingDate(cells.item(_row, 2).value().date());
axPurchTable.parmPurchStatus(PurchStatus::Backorder);
axPurchTable.parmOrderAccount(cells.item(_row, 4).value().bStr());
axPurchTable.parmCurrencyCode('IDR');
axPurchTable.save();
}
//Create PO Lines
row++;
type = cells.item(row, 1).value().variantType();
ttsBegin;
while (type != COMVariantType::VT_EMPTY)
{
counter++;
inventSiteId = cells.item(row, 17).value().bStr();
inventLocationId = cells.item(row, 18).value().bStr();
inventDim.InventSiteId = inventSiteId;
inventDim.InventLocationId = inventLocationId;
purchLine.clear();
purchLine.initValue();
purchLine.initFromPurchTable(purchTable);
purchLine.initFromInventTable(InventTable::find(cells.item(row, 10).value().bStr()));
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(cells.item(row, 10).value().bStr());
axpurchLine.parmInventDimId(InventDim::findOrCreate(inventDim).inventDimId);
axPurchLine.parmPurchQty(cells.item(row, 12).value().double());
axPurchLine.parmPurchPrice(cells.item(row, 13).value().double());
axPurchLine.parmDescription(cells.item(row, 11).value().bStr());
axPurchLine.parmLinePercent(cells.item(row, 14).value().double());
axPurchLine.parmTaxItemGroup(cells.item(row, 19).value().bStr());
axPurchLine.parmTaxGroup(cells.item(row, 20).value().bStr());
axPurchLine.parmInventLocationId(cells.item(row, 21).value().bStr());
axPurchLine.parmRequester(HcmWorker::userId2Worker(cells.item(row, 22).value().bStr()));
//purchline.ARPTaskWBSId() = ARPTasks::findByActivityNumber(cells.item(row, 31).value().bStr()).TaskId_Wbs;
//Kondisi untuk FixedAsset
select assetBook
where assetBook.AssetId == cells.item(row, 25).value().bStr();
if(cells.item(row, 23).value().bStr() == 'Yes')
{
axPurchLine.parmCreateFixedAsset(NoYes::Yes);
axPurchLine.parmAssetGroup(cells.item(row, 24).value().bStr());
}
else if(cells.item(row, 23).value().bStr() == 'No')
{
axPurchLine.parmAssetGroup(assetBook.AssetGroup);
axPurchLine.parmAssetId(cells.item(row, 25).value().bStr());
axPurchLine.parmAssetBookId(assetBook.BookId);
}
//Kondisi untuk Project
if(cells.item(row, 26).value().bStr() != '')
{
axPurchLine.parmProjId(cells.item(row, 26).value().bStr());
axPurchLine.parmActivityNumber(cells.item(row, 27).value().bStr());
axPurchLine.parmProjCategoryId(cells.item(row, 28).value().bStr());
axPurchLine.parmProjLinePropertyId(cells.item(row, 29).value().bStr());
axPurchLine.parmProjSalesCurrencyId(purchTable.CurrencyCode);
axPurchLine.parmProjSalesUnitId('Jam');
}
defaultDim = conNull();
struct.remove('DIVISI');
struct.remove('PROYEK');
struct.add('DIVISI', cells.item(row, 15).value().bStr());
struct.add('PROYEK', cells.item(row, 16).value().bStr());
defaultDim += struct.fields();
defaultDim += struct.fieldName(1);
defaultDim += struct.valueIndex(1);
defaultDim += struct.fieldName(2);
defaultDim += struct.valueIndex(2);
axPurchLine.parmDefaultDimension(AxdDimensionUtil::getDimensionAttributeValueSetId(defaultDim));
axPurchLine.save();
row++;
type = cells.item(row, 1).value().variantType();
}
ttscommit;
purchTable = PurchTable::find(axPurchTable.parmPurchId());
purchTotals = PurchTotals::newPurchTable(purchTable);
purchTotals.calc();
//Kondisi untuk Prepayment
_row_prep++;
_type_prep = cells.item(_row_prep, 9).value().variantType();
if (_type_prep != COMVariantType::VT_EMPTY)
{
purchPrepayTable.clear();
purchPrepayTable.initValue();
purchPrepayTable.PurchTable = purchTable.PurchId;
purchPrepayTable.Description = cells.item(_row_prep, 7).value().bStr();
purchPrepayTable.Type = PurchPrepayType::Percent;
purchPrepayTable.Value = cells.item(_row_prep, 8).value().double();
purchPrepayTable.PrepayLimit = (purchTotals.purchTotalAmount() * cells.item(_row_prep, 8).value().double()) / 100;
purchPrepayTable.PrepayAvailable = (purchTotals.purchTotalAmount() * cells.item(_row_prep, 8).value().double()) / 100;
purchPrepayTable.Currency = 'IDR';
//purchPrepayTable.PrepayCategoryId = EcoResCategory::findByName(cells.item(_row_prep, 9).value().bStr(), 5637144576).RecId;
purchPrepayTable.PrepayCategoryId = EcoResCategory::findByName(cells.item(_row_prep, 9).value().bStr(), 5637144576).RecId;
purchPrepayTable.insert();
}
info(strfmt("Inserted %1 rows",counter));
application.quit();
}
}
catch(Exception::Error)
{
info('Journal Upload Error');
application.quit();
}
}
Above is the source code of a job to Uploading Purchase Order.
Since SID is a method from PurchLine, Im a lil bit confuse how to add the code in the JOB.
Im using this code to insert po line
//Create PO Lines
row++;
type = cells.item(row, 1).value().variantType();
ttsBegin;
while (type != COMVariantType::VT_EMPTY)
{
counter++;
inventSiteId = cells.item(row, 17).value().bStr();
inventLocationId = cells.item(row, 18).value().bStr();
inventDim.InventSiteId = inventSiteId;
inventDim.InventLocationId = inventLocationId;
purchLine.clear();
purchLine.initValue();
purchLine.initFromPurchTable(purchTable);
purchLine.initFromInventTable(InventTable::find(cells.item(row, 10).value().bStr()));
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(cells.item(row, 10).value().bStr());
axpurchLine.parmInventDimId(InventDim::findOrCreate(inventDim).inventDimId);
axPurchLine.parmPurchQty(cells.item(row, 12).value().double());
axPurchLine.parmPurchPrice(cells.item(row, 13).value().double());
axPurchLine.parmDescription(cells.item(row, 11).value().bStr());
axPurchLine.parmLinePercent(cells.item(row, 14).value().double());
axPurchLine.parmTaxItemGroup(cells.item(row, 19).value().bStr());
axPurchLine.parmTaxGroup(cells.item(row, 20).value().bStr());
axPurchLine.parmInventLocationId(cells.item(row, 21).value().bStr());
axPurchLine.parmRequester(HcmWorker::userId2Worker(cells.item(row, 22).value().bStr()));
//purchline.ARPTaskWBSId() = ARPTasks::findByActivityNumber(cells.item(row, 31).value().bStr()).TaskId_Wbs;
ARPTaskWBSId is not exist in the class AxPurchLine, so Im adding new method but got some error. I think the error show up because ARPTaskWBSId is a method not an actual field.
Can anybody give some advice how to insert to a field where the field is not an actual field but a method ?
Your help mean a lot to me :)
Best Regards,
Enggar