Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 175888

RE: Strange issue of calling AX method by AIF

$
0
0
Below is the re-upload's code

[AifCollectionTypeAttribute('BOMRMList', Types::Class, classStr(CSMDataMember_BOMRMinfo)), SysEntryPointAttribute(true)] public str RMBOM(Qty pa,Qty pb,Qty pc,Qty pd,Qty pe) //List BOMRMList ,int Action) { InventTable inventtabletable; InventTable inventTable; KGGMaster kggmastertable; BOMTable bomtable; InventSiteId siteid; str ErrorStr; BOMVersion bomversiontable; BOM BOMline; InventDim inventDim; HcmWorker hcmworker; BOMMeasureHeight Thickness; str Material; InventTable InvvTable; InventModelGroupItem imgi; InventTable Parentinventtable; InventTable Childinventtable; Qty parentdimension; Qty childdimension; BOM Bomline2; boolean ret1 ; ItemId ChildRmID; boolean BOMLINEupdate; BOMQty BOMLineQty; int icount; str strLog; str log; boolean existSameItemMark = false; // CSMDataMember_BOMRMinfo bomMember; // Enumerator en; // en = BOMRMList.getEnumerator(); try { ttsBegin; //bomMember = en.current(); icount = 0; //[P-01] Read a record in released product(Item master) //[D-51] Is KGG ended in KGG master? while select * from inventtabletable //where inventtabletable.itemid == '107-FG1'//'Nick1' join imgi where imgi.ItemId == inventtabletable.ItemId && (imgi.ModelGroupId == "FG" || imgi.ModelGroupId == "SFG") join kggmastertable where kggmastertable.KGG == inventtabletable.KGG && kggmastertable.ended == NoYes::No { icount++; strLog = date2str(today(),321,DateDay::Digits2, DateSeparator::Hyphen, // separator1 DateMonth::Digits2, DateSeparator::Hyphen, // separator2 DateYear::Digits4 ); strLog += " "+time2str(timeNow(),TimeSeparator::Colon,TimeFormat::Hour24); strLog = strFmt("%1 Line %2 :", strLog ,icount); //[P-03] Check "Use RM" //[D-52] is "Use RM" TRUE or FALSE? if (inventtabletable.useRM == NoYes::Yes ) { //[P-05] Check "Material" //[D-54] if( inventtabletable.Material == '' || inventtabletable.Material == "0") { //[Log-92] log = log +"\r\n"+ strLog + strFmt("Skipped, (%1), Item ID %2 does not have material code in released products.",inventtabletable.ItemId,inventtabletable.ItemId); continue; } //[P-06] Check "Thickness" //[D-55] if ( inventtabletable.Height <= 0) { //[D-62] Check "MaterialTypeNumber" if (inventtabletable.MaterialTypeNumber == "") { //[Log-93] log = log +"\r\n"+strLog + strFmt("Skipped, (%1), Item ID %2 does not have thickness information in released products.",inventtabletable.ItemId,inventtabletable.ItemId); continue; } } //[P-07] Check BOM header of the item. //[D-56] Does BOM header record of the item exist? bomtable = BOMTable::find(inventtabletable.ItemId,false); if (bomtable == null) { //Begin [P-10] Insert a BOM header record. siteid = "Shop3"; bomTable.initValue(); bomTable.BOMId = inventtabletable.ItemId; bomTable.Name = inventtabletable.ItemId; bomTable.SiteId = siteid; bomTable.ItemGroupId = inventtabletable.itemGroupId(); hcmworker = HcmWorker::findByPersonnelNumber('99999'); if (hcmworker == null ) { log = log + "\r\n" + strFmt('personnelNumber %1 does not exist in the hcmworker','99999'); continue; } bomTable.Approver = hcmWorker.RecId; bomTable.Approved = true; bomTable.insert(); //End [P-10] } //[P-08] Check BOM version. //[D-57] Does BOM version record of the item exist? select * from bomversiontable where bomversiontable.ItemId == inventtabletable.ItemId && bomversiontable.BOMId == bomtable.BOMId; if (bomversiontable == null) { //Begin [P-09] Insert a BOM version record. inventDim.initvalue(); inventDim.InventSiteId = "Shop3"; inventDim = InventDim::findOrCreate(inventDim); hcmworker = HcmWorker::findByPersonnelNumber('99999'); bomversiontable.initValue(); bomversiontable.BOMId = bomtable.BOMId; bomversiontable.ItemId = bomtable.BOMId; bomversiontable.InventDimId = inventdim.inventDimId; //bomVersion.FromDate = fromdate; //bomVersion.ToDate = todate; bomversiontable.FromQty = 0; bomversiontable.Active = true; bomversiontable.Approved = true; bomversiontable.Approver = hcmWorker.RecId; bomversiontable.insert(); //End [P-09] } //[D-63] Check "Thickness" blank?. if (inventtabletable.Height <= 0) { //[P-11-2] select * from InvvTable where InvvTable.MaterialTypeNumber == inventtabletable.MaterialTypeNumber && InvvTable.ItemId != inventtabletable.ItemId && InvvTable.Material == inventtabletable.Material join imgi where imgi.ItemId == InvvTable.ItemId && imgi.ModelGroupId == "RM-BOM"; } else { //[P-11] Get a Child RM-BOM item code. select * from InvvTable where InvvTable.Material == inventtabletable.Material && InvvTable.Height == inventtabletable.Height && InvvTable.ItemId != inventtabletable.ItemId join imgi where imgi.ItemId == InvvTable.ItemId && imgi.ModelGroupId == 'RM-BOM'; } //[D-58] Can find Child RM-BOM item code in released product.(Item master) if (InvvTable != null) { ChildRmID = InvvTable.ItemId; } else { ChildRmID = ''; //[Log-94] log = log +"\r\n"+ strLog + strFmt("Fail, (%1), Item ID %2 cannot find applicable RM-BOM item in released products master.",inventtabletable.ItemId,inventtabletable.ItemId); continue; } //Check quantity before set BOM line's quantity. try { select * from Parentinventtable where Parentinventtable.ItemId == bomtable.BOMId; select * from Childinventtable where Childinventtable.ItemId == ChildRmID; if (inventtabletable.MaterialTypeNumber == "") { parentdimension = (Parentinventtable.Width+ pb) * (Parentinventtable.Depth + pc); childdimension = (Childinventtable.Width - pd) * (Childinventtable.Depth - pe); } else { parentdimension = Parentinventtable.Depth + pc; childdimension = Childinventtable.Depth - pe; } //BOMLineQty = parentdimension * Parentinventtable.ProductionQty / (childdimension* pa); if (childdimension* pa != 0) { BOMLineQty = parentdimension / (childdimension* pa); } else { BOMLineQty = 0; } } catch { BOMLineQty = 0; } if (BOMLineQty <= 0 ) { //[Log-95] log = log +"\r\n"+ strLog + strFmt("Fail, (%1), Item ID %2 Quantity is zero, negative or infinite. Confirm Width, Length and Production Qty data in released products.",inventtabletable.ItemId,inventtabletable.ItemId); continue; } //[D-59-0] Are there multiple RM-BOM line? select count(RecId) from BOMline where BOMline.BOMId == bomtable.BOMId join imgi where imgi.ItemId == BOMline.ItemId && imgi.ModelGroupId == "RM-BOM"; if (BOMline.RecId >= 2) { //[Log-96] log = log + "\r\n" + strLog + strFmt("Fail, %1, has multiple RM-BOM items", inventtabletable.ItemId); continue; } //[P-12] Check BOM line records under the BOM header. //[D-59] Is there any BOM line records which child item has "item model group" = RM-BOM? existSameItemMark = false; while select forUpdate * from BOMline where BOMline.BOMId == bomtable.BOMId // && BOMline.ItemId == ChildRmID join imgi where imgi.ItemId == BOMline.ItemId && imgi.ModelGroupId == "RM-BOM" { //[P-13] Compare existing Child code and Child RM-BOM item code obtained in [P-11]. //[D-60] Are they same item code? if (BOMline.ItemId == ChildRmID) { //Begin [P-16] Update the BOM line record. inventDim.initvalue(); inventDim.InventSiteId = "Shop3"; InventDim.InventLocationId = "RM"; inventDim = InventDim::findOrCreate(inventDim); BOMline.BOMId = bomtable.BOMId; BOMline.ItemId = ChildRmID; BOMline.BOMType = BOMType::Item; BOMline.Calculation = true; BOMline.BOMQty = BOMLineQty; BOMline.BOMQtySerie = 1; BOMline.UnitId = "PC"; BOMline.Formula = BOMFormula::Formula0; BOMline.BOMConsump= BOMConsumpType::Variable; BOMline.ProdFlushingPrincip = ProdFlushingPrincipBOM::Manual; BOMline.RoundUp = BOMRoundUp::No; //BOMline.LineNum = 1; BOMline.InventDimId = inventDim.inventDimId; BOMline.update(); //End [P-16] existSameItemMark = true; //[Log-95] log = log +"\r\n"+ strLog + strFmt("Success, (%1)",inventtabletable.ItemId); continue; } else { //[P-14] Delete the BOM line record. BOMline.delete(); } //Begin [P-15] Insert a new BOM line record for RM-BOM. inventDim.initvalue(); inventDim.InventSiteId = "Shop3"; InventDim.InventLocationId = "RM"; inventDim = InventDim::findOrCreate(inventDim); Bomline2.initValue(); BOMLine2.BOMId = bomtable.BOMId; Bomline2.ItemId = ChildRmID; Bomline2.BOMType = BOMType::Item; Bomline2.Calculation = true; Bomline2.BOMQty = BOMLineQty; Bomline2.BOMQtySerie = 1; Bomline2.UnitId = "PC"; Bomline2.Formula = BOMFormula::Formula0; Bomline2.BOMConsump= BOMConsumpType::Variable; Bomline2.ProdFlushingPrincip = ProdFlushingPrincipBOM::Manual; Bomline2.RoundUp = BOMRoundUp::No; Bomline2.LineNum = 1; Bomline2.InventDimId = inventDim.inventDimId; Bomline2.insert(); existSameItemMark = true; //[Log-95] log = log +"\r\n"+ strLog + strFmt("Success, (%1)",inventtabletable.ItemId); continue; //End [P-15] } if (existSameItemMark == false) { //Begin [P-15] Insert a new BOM line record for RM-BOM. inventDim.initvalue(); inventDim.InventSiteId = "Shop3"; InventDim.InventLocationId = "RM"; inventDim = InventDim::findOrCreate(inventDim); Bomline2.initValue(); BOMLine2.BOMId = bomtable.BOMId; Bomline2.ItemId = ChildRmID; Bomline2.BOMType = BOMType::Item; Bomline2.Calculation = true; Bomline2.BOMQty = BOMLineQty; Bomline2.BOMQtySerie = 1; Bomline2.UnitId = "PC"; Bomline2.Formula = BOMFormula::Formula0; Bomline2.BOMConsump= BOMConsumpType::Variable; Bomline2.ProdFlushingPrincip = ProdFlushingPrincipBOM::Manual; Bomline2.RoundUp = BOMRoundUp::No; Bomline2.LineNum = 1; Bomline2.InventDimId = inventDim.inventDimId; Bomline2.insert(); //[Log-95] log = log +"\r\n"+ strLog + strFmt("Success, (%1)",inventtabletable.ItemId); continue; //End [P-15] } } else { //[D-53] Is there existing BOM line of the item which child item has RM-BOM as "Item model group"? while select forUpdate * from bomline where bomline.BOMId == inventtabletable.ItemId join inventTable where inventTable.ItemId == BOMline.ItemId join imgi where imgi.ItemId == inventTable.ItemId && imgi.ModelGroupId == "RM-BOM" { //[P-04] bomline.delete(); //[Log-91] log = log +"\r\n" + strLog + strFmt("Skipped, (%1), Item ID %2 does not use RM and existing BOM record with RM-BOM has been deleted.",inventtabletable.ItemId,inventtabletable.ItemId); } continue; } } ttsCommit; } catch { ttsAbort; strLog = date2str(today(),321,DateDay::Digits2, DateSeparator::Hyphen, // separator1 DateMonth::Digits2, DateSeparator::Hyphen, // separator2 DateYear::Digits4 ); strLog += " "+time2str(timeNow(),TimeSeparator::Colon,TimeFormat::Hour24); throw Global::error( log + "\r\n" + log + "\r\n" +strFmt("%1 %2", strLog , Exception::Error)); } return log; }

Viewing all articles
Browse latest Browse all 175888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>