Creation of a production order
kurt vanhauwaert
Hi all,On my sales order form i have put some code to give the user the ability to create a production order when he click on an item in the detail grid. There are 3 types of items that can be created and the first two are easy to handle.
Only, i have a problem with the 3the item type. For this item type i have to create the production order without detail lines so the user can add the detail lines as he wishes. I know that that the production order has to have at least one item in the grid/detail.
So i tried to delete all the line but one... but that doesn't work. When i debug my code it seems that there are no items in the detail when i try to delete them. Although when i open my production order screen the po is saved and with detail....
Can somebody help me ?
thnx
=> my code <=
pVal.Form.Freeze(true);
bool llSave = true;
try
{
initCons();
string lcItemCode = "";
string lcProductionType = "";
int lnCurrentGridPos = 0;
int RetValPO = 0;
int lnDocEntry = 0;
/* Create ProductionOrder object */
SAPbobsCOM.ProductionOrders oPO = ((SAPbobsCOM.ProductionOrders) B1Connectie.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders));
/* Create and copy SalesOrder object */
SAPbobsCOM.Documents oSalesOrder = ((SAPbobsCOM.Documents) B1Connectie.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders));
Matrix ItemGrid = Matrix.GetFromUID(pVal.Form, "38");
lnCurrentGridPos = pVal.Row - 1;
lcItemCode = ItemGrid.GetValue("1", lnCurrentGridPos);
lcProductionType = ItemGrid.GetValue("U_D_REGELTP", lnCurrentGridPos);
string queryx = "SELECT DocEntry FROM ORDR WHERE DocNum = " + TextEdit.GetFromUID(pVal.Form , "8").Value;
using (System.Data.SqlClient.SqlDataReader sqlReaderx = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQuery(queryx))
{
if (sqlReaderx.Read())
{
lnDocEntry = sqlReaderx.GetInt32(0);
}
}
oPO.ItemNo = lcItemCode;
oPO.DueDate = System.DateTime.Today.Date;
oPO.PlannedQuantity = Convert.ToDouble(ItemGrid.GetValue("11", lnCurrentGridPos));
oPO.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposPlanned;
oPO.Warehouse = "01";
oPO.ProductionOrderOrigin = SAPbobsCOM.BoProductionOrderOriginEnum.bopooSalesOrder;
oPO.ProductionOrderOriginEntry = lnDocEntry;
oPO.ProductionOrderType = SAPbobsCOM.BoProductionOrderTypeEnum.bopotStandard;
switch(lcProductionType)
{
case "S":
/* Nothing to doe */
break;
case "N":
/* Nothing to doe */
break;
case "R":
for(int oPoPos = 1; oPoPos < oPO.Lines.Count ; oPoPos++)
{
[color=#FF0000]Here i try to delete the detail.... but that doesn't seems to work <<=======================================[/color]
MessageBox.Show("Delete lines", "ok");
oPO.Lines.Delete();
}
break;
}
/* Adding the Product order */
RetValPO = oPO.Add();
if (RetValPO != 0)
{
int ErrCode;
string ErrMsg;
B1Connectie.Company.GetLastError(out ErrCode, out ErrMsg);
NotifyUser(" Company Error " + ErrCode + " : " + ErrMsg, false);
}
else
{
MessageBox.Show("Aanmaken production order succes", "ok");
}
}
catch (Exception e)
{
Toolkit.MyToolKit.NotifyUser(e.ToString(), true);
MessageBox.Show("Exception", "ok");
llSave = false;
}
pVal.Form.Freeze(false);
Paolo Manfrin
Hi Kurt,which is the error returned when you try to delete the lines or save the documents?
Have you tried to first save the oPO and then reopen it via DI and delete the lines?
Regards,
paolo
kurt vanhauwaert
Hi Paolo,thanks for your reply. In fact i don't get an error. The code is executed and the order is created with the detail. When i check the Lines.Count its set at 1 ( or 0 i'm not sure anymore). If the production order is opend then all the sub products are in the detail. So it seems that when my code runs the case the detail object has to be reloaded or is only filled when the add is done.
case "R":
for(int oPoPos = 1; oPoPos < oPO[color=#FF0000].Lines.Count ; o[/color]PoPos++) <<<==== this gives 0 or 1
{
[color=#FF0000]Here i try to delete the detail.... but that doesn't seems to work <<=======================================[/color]
MessageBox.Show("Delete lines", "ok");
oPO.Lines.Delete();
}
break;
Paolo Manfrin
Hi Kurt,then try first to save the document and then reopen and cancel the lines.
This should solve the issue.
hth
paolo
kurt vanhauwaert
Thanks Paolo for you reply.i'll test this
kind regards,
Kurt
kurt vanhauwaert
Hi Paolo,i have still one problem. The Po is created and on the PO the base sales order is filled in. so far so good.
On my sales order detail there is also a field "procurement doc." this field stays empty and is read-only. How do i manage to fill out the Production Order Number there ?
kind regards
Paolo Manfrin
Hi Kurt,You cannot directly. You have to create a purchase order and you set baseLine, baseRef and baseType of such Purchase Order linked to the Sales Order.
If you do it through UI you see that first the sales order is created and then the purchase order.
hth
paolo
kurt vanhauwaert
Hi Paolo,i'm talking about the production order and the sales order. I've created a production order via the code in my first post and that works fine. The Production order is also filled out verry well. The problem is that the sales order detail has also a field that contains the link to the production order and that isn't filled in...
thnx
Paolo Manfrin
Hi Kurt,as far as I know you cannot use such field to link the SO to the PO. "Procurement Document" is stated in SAP documentation as link to Purchase Quotations or Purchase Orders,
Cheers
paolo
0
Please sign in to leave a comment.
Comments
0 comments