Creation of the link between a sales order and a production order
kurt vanhauwaert
Hi all,i want have managed to create a production order from an item on my sales order. The link from my production order to the sales order is set but not from the sales porder to the production order. The field procurement no stays empty. In the SDK i have found that there is an object called "productionorders_salesorderlines" that can be used to change/fill out this data but its read only.
So my question :
first : i can make the link from the production order to the sales order so why doesn't that work the other way ? I suppose that the di api will do the work automatic ?
second : first if there is an object that fills out the data in the wor2 table why can't it be used to make de link with the di-api.
my final question => is this a bug ?
here is my code : (the code in red is the part where i want to force the link)
if (pVal.Form.Mode != SwissAddonFramework.UI.Components.ModeComponent.FormModes.OK)
{
MessageBox.Show("Kan geen productie order maken in niet <<OK>> modus !", "OK");
return;
}
pVal.Form.Freeze(true);
bool llSave = true;
/*
try
{
*/
initCons();
string lcItemCode = "";
string lcProductionType = "";
Toolkit.MyToolKit.NotifyUser("start", true);
string lcExtra01 = "";
string lcExtra02 = "";
string lcExtra03 = "";
string lcExtra04 = "";
string lcExtra05 = "";
string lcExtra06 = "";
string lcExtra07 = "";
string lcExtra08 = "";
string lcExtra09 = "";
string lcExtra10 = "";
string lcDocEntry = "";
int lnCurrentGridPos = 0;
int RetValPO = 0;
int lnDocEntry = 0;
Matrix ItemGrid = Matrix.GetFromUID(pVal.Form, "38");
lnCurrentGridPos = pVal.Row - 1;
if ((ItemGrid.GetValue("158", lnCurrentGridPos).ToString() != null) && (ItemGrid.GetValue("158", lnCurrentGridPos).ToString() != ""))
{
MessageBox.Show("Er bestaat al een Productie order voor dit artikel => " + ItemGrid.GetValue("158", lnCurrentGridPos), "ok");
pVal.Form.Freeze(false);
return ;
}
lcItemCode = ItemGrid.GetValue("1", lnCurrentGridPos);
lcProductionType = ItemGrid.GetValue("U_D_REGELTP", lnCurrentGridPos);
lcExtra01 = ItemGrid.GetValue("U_D_EXTRA01", lnCurrentGridPos);
lcExtra02 = ItemGrid.GetValue("U_D_EXTRA02", lnCurrentGridPos);
lcExtra03 = ItemGrid.GetValue("U_D_EXTRA03", lnCurrentGridPos);
lcExtra04 = ItemGrid.GetValue("U_D_EXTRA04", lnCurrentGridPos);
lcExtra05 = ItemGrid.GetValue("U_D_EXTRA05", lnCurrentGridPos);
lcExtra06 = ItemGrid.GetValue("U_D_EXTRA06", lnCurrentGridPos);
lcExtra07 = ItemGrid.GetValue("U_D_EXTRA07", lnCurrentGridPos);
lcExtra08 = ItemGrid.GetValue("U_D_EXTRA08", lnCurrentGridPos);
lcExtra09 = ItemGrid.GetValue("U_D_EXTRA09", lnCurrentGridPos);
lcExtra10 = ItemGrid.GetValue("U_D_EXTRA10", lnCurrentGridPos);
/* 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));
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).Replace(".", ","));
oPO.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposPlanned;
oPO.Warehouse = "CW";
oPO.ProductionOrderOrigin = SAPbobsCOM.BoProductionOrderOriginEnum.bopooSalesOrder;
oPO.ProductionOrderOriginEntry = lnDocEntry;
//oPO.ProductionOrderOriginNumber = Convert.ToInt32(TextEdit.GetFromUID(pVal.Form, "8").Value);
oPO.ProductionOrderType = SAPbobsCOM.BoProductionOrderTypeEnum.bopotStandard;
oPO.UserFields.Fields.Item("U_D_ITEMTYPE").Value = lcProductionType;
oPO.UserFields.Fields.Item("U_D_EXTRA01").Value = lcExtra01;
oPO.UserFields.Fields.Item("U_D_EXTRA02").Value = lcExtra02;
oPO.UserFields.Fields.Item("U_D_EXTRA03").Value = lcExtra03;
oPO.UserFields.Fields.Item("U_D_EXTRA04").Value = lcExtra04;
oPO.UserFields.Fields.Item("U_D_EXTRA05").Value = lcExtra05;
oPO.UserFields.Fields.Item("U_D_EXTRA06").Value = lcExtra06;
oPO.UserFields.Fields.Item("U_D_EXTRA07").Value = lcExtra07;
oPO.UserFields.Fields.Item("U_D_EXTRA08").Value = lcExtra08;
oPO.UserFields.Fields.Item("U_D_EXTRA09").Value = lcExtra09;
oPO.UserFields.Fields.Item("U_D_EXTRA10").Value = lcExtra10;
try
{
/* Adding the Product order */
Toolkit.MyToolKit.NotifyUser("save po", true);
switch(lcProductionType)
{
case "S":
oPO.Warehouse = "CW";
break;
case "N":
oPO.Warehouse = "CW";
break;
case "R":
oPO.Warehouse = "RP";
break;
}
[color=#FF0000] oPO.SalesOrderLines.BaseAbsEntry = oSalesOrder.DocEntry;
oPO.SalesOrderLines.BaseNumber = oSalesOrder.DocNum;
oPO.SalesOrderLines.BaseLine = lnCurrentGridPos;[/color]
RetValPO = oPO.Add();
B1Connectie.Company.GetNewObjectCode(out lcDocEntry);
}
catch (Exception e)
{
Toolkit.MyToolKit.NotifyUser(e.ToString(), true);
MessageBox.Show("Exception", "ok");
llSave = false;
}
switch(lcProductionType)
{
case "S":
Form.OpenFormByKey("202", lcDocEntry);
break;
case "N":
Form.OpenFormByKey("202", lcDocEntry);
break;
case "R":
Toolkit.MyToolKit.NotifyUser("Omzetten docentry naar string", true);
oPO.GetByKey(Convert.ToInt32(lcDocEntry));
int lnDetailLines = oPO.Lines.Count;
Toolkit.MyToolKit.NotifyUser("Aantal detail lijnen berekenen", true);
for(int oPoPos = 0; oPoPos < lnDetailLines - 1 ; oPoPos++)
{
oPO.Lines.SetCurrentLine(0);
oPO.Lines.Delete();
}
oPO.Lines.SetCurrentLine(0);
oPO.Lines.ItemNo = "repair";
oPO.Lines.Warehouse = "RP";
oPO.Update();
Toolkit.MyToolKit.NotifyUser("Open repaire production order", true);
Form.OpenFormByKey("202", lcDocEntry);
break;
}
if (RetValPO != 0)
{
int ErrCode;
string ErrMsg;
B1Connectie.Company.GetLastError(out ErrCode, out ErrMsg);
NotifyUser(" Company Error " + ErrCode + " : " + ErrMsg, false);
}
/*
}
catch (Exception e)
{
Toolkit.MyToolKit.NotifyUser(e.ToString(), true);
MessageBox.Show("Exception", "ok");
llSave = false;
}
*/
pVal.Form.Freeze(false);
0
Please sign in to leave a comment.
Comments
0 comments