Filling the cardcode in the orderform (139)

Erik van Dongen

Hello,

What i try to achieve is to add an extra field to the orderform for selecting a business partner, based on the block field. In one way, i want the same as the cardname field is doing only then for the block field of the ocrd.

I did the following:
- i add an extra field under the field cardname and moved the fields below a little bit down

- I added a chooseFromList (from sap) to this field, based on the block

- I catch the choosefromlist after event and fill in the cardcode in the cardcode field (field 4).

So far so good but after filling in the cardcode, i got an error "bad form value". The strange thing is that the cardcode is filled in anyway.

Can anyone help me further on this? Is there a problem with automaticly filling a textbox with a choosefromlist or something? Please help.....

Here's the code, i use:
public void Run()
{
// Add handler to the load event of the order form
Form.AddHandler_Load("139", ModeComponent.FormModes.ALL, modifyOrderForm);
}

private void modifyOrderForm(FormLoad e)
{
SwissAddonFramework.UI.Components.UserDatasource EditDS = SwissAddonFramework.UI.Components.UserDatasource.CreateNew("EditDS");
EditDS.DataSourceType = UserDatasource.DataType.ShortText;
EditDS.Length = 254;
e.Form.AddUserDatasource(EditDS);
AddChooseFromList(e.Form.UniqueID);

Item tempItem = Item.GetFromUID(e.Form, "83"); // Contactperson label

Label label = Label.CreateNew("IACTOR_N2L");
label.Value = "Matchcode";
label.Top = tempItem.Top;
label.Left = tempItem.Left;
label.Height = tempItem.Height;
label.Width = tempItem.Width;
e.Form.AddItem(label);

tempItem = Item.GetFromUID(e.Form, "85"); // Contactperson TextBox
TextEdit textEdit = TextEdit.CreateNew("IACTOR_N2T");
textEdit.Top = tempItem.Top;
textEdit.Left = tempItem.Left;
textEdit.Height = tempItem.Height;
textEdit.Width = tempItem.Width;
textEdit.DataBind = DataBind.CreateNew("EditDS");
textEdit.DataBind.SetBind(true, "EditDS");
textEdit.ChooseFromListUID = "CFLErik";
textEdit.ChooseFromListAlias = "Block";
e.Form.AddItem(textEdit);


int[] itemsToMove = new int[] { 83, 87, 85, 80, 15, 14, 70, 63 };
int distance = Item.GetFromUID(e.Form, "85").Top - Item.GetFromUID(e.Form, "54").Top;
foreach (int uid in itemsToMove)
{
Item itm = Item.GetFromUID(e.Form, uid.ToString());
itm.Top += distance;
}
e.Form.Update();

textEdit.AddHandler_ChooseFromList(ModeComponent.FormModes.ALL, null, aft2);
}

private void aft2(ChooseFromList e)
{
string cardCode = e.SelectedObjects.GetValue("CardCode", 0);
string cardName = e.SelectedObjects.GetValue("CardName", 0);
string block = e.SelectedObjects.GetValue("Block", 0);

// Close the CFL to give the addon the ability to focus the cardcode
SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.ActiveForm.Close();

// Select the cardcode
//TextEdit.GetFromUID(e.Form, "4").Click(SwissAddonFramework.UI.Components.Item.ClickType.Regular);

// Fill in the block and the cardcode
TextEdit.GetFromUID(e.Form, "IACTOR_N2T").Value = block;
TextEdit.GetFromUID(e.Form, "4").Value = cardCode;
}

private void AddChooseFromList(string formUid)
{
try
{
SAPbouiCOM.ChooseFromListCollection oCFLs = null;
SAPbouiCOM.Conditions oCons = null;
SAPbouiCOM.Condition oCon = null;

oCFLs = SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.Item(formUid).ChooseFromLists;

SAPbouiCOM.ChooseFromList oCFL = null;
SAPbouiCOM.ChooseFromListCreationParams oCFLCreationParams = null;
oCFLCreationParams = ((SAPbouiCOM.ChooseFromListCreationParams)(SwissAddonFramework.B1Connector.GetB1Connector().Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_ChooseFromListCreationParams)));

// Adding 2 CFL, one for the button and one for the edit text.
oCFLCreationParams.MultiSelection = false;
oCFLCreationParams.ObjectType = "2";
oCFLCreationParams.UniqueID = "CFLErik";

oCFL = oCFLs.Add(oCFLCreationParams);

SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.Item(formUid).Update();

}
catch (Exception ex)
{
bool erik = true;
}
}
0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post