Accessing items in an AddOn Form on FormLoad with Customize/Optimizer
Roland
Dear Forum,I already found some topics about this problem but the question was - in my eyes - not answered there.
The scenario:
I add a line in the optimizer, select the FormLoad event, enter the FormType of the AddOn-form and write some simple cs-code for coloring an item.
For test-purposes the code also opens a MessageBox before coloring the item.
When the AddOn-form opens the MessageBox appears but then an error message tells that the item does not exist.
I tried this with...
...a Form of our own AddOn
...a Form of an SAP-AddOn
...a Form of the coresuite-AddOn (COR_UDT_CONFIG)
...with always the same result (item does not exist) and regardless of the BeforeEvent-Checkbox in the Optimizer.
Only with original SAP-Forms it is not a problem to color an item.
Is this a normal behaviour? How can we modify items of AddOn-forms on FormLoad with Customize/Optimizer?
Thanks in advance for your answers,
Roland
Anders Olsson
Hi Roland,This happens if the items have not been created when the form loads.
To accomodate for this scenario we have added a new event type in customize 3.70 (release date: 3 September):
FormLoadCompleted.
A workround would be to create a Timer object that checks if the item has been created in regular intervals, then colour the item and stop the timer.
Regards,
Anders
Roland
Hello Anders,thanks for your answer and please excuse me for my late reply.
I already found the FormLoadCompleted-Event in Customize 3.6 now.
If I try to color the Item in the NOT-before-Event B1 hangs and has to be killed by TaskManager
and
with the before-Event nothing happens except the form opens normally.
Maybe it will be better with Customize 3.7 ?
With a timer I had no luck - how it's done in Core-Customize and where can I define a "Timer-Tick"-Eventhandler?
Cheers,
Roland
Roland
...now I've found a solution without "FormLoadCompleted":Optimizer with CSCODE, VALIDATE, the FormType, FormLoad and the following Code:
[CODE]
try
{
//MessageBox.Show("tManDatWar einfärben per Thread...", "OK");
AdminForm = pVal.Form;
System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(SetColor_ManDatWar));
myThread.SetApartmentState(System.Threading.ApartmentState.STA);
myThread.Start();
return true;
}
catch(System.Exception ex) // Error handling
{
MessageBox.Show("Fehler in Regel: " + ex.Message, "OK");
}
// Return value: true if all ok, false if you want SAP B1 to stop proceed
return true;
[/CODE]
...and in ExtendedCode:
[CODE]
public SwissAddonFramework.UI.Components.Form AdminForm=null;
public void SetColor_ManDatWar()
{
// MessageBox.Show("tManDatWar einfärben per Thread...hier SetColor_ManDatWar() " + AdminForm.UniqueID, "OK");
SwissAddonFramework.UI.Components.Item iManDatWar=null;
int maxTrys = 0;
while( iManDatWar == null && maxTrys < 10)
{
maxTrys++;
try
{
iManDatWar = Item.GetFromUID(AdminForm, "tManDatWar");
}
catch
{
System.Threading.Thread.Sleep(100);
}
}
System.Drawing.Color color = System.Drawing.Color.FromArgb(-5570646);
SwissAddonFramework.Messaging.StatusBar.WriteWarning("Trys: " + maxTrys.ToString());
try
{
iManDatWar.BackgroundColor = color;
}
catch
{
MessageBox.Show("iManDatWar.BackgroundColor FEHLSCHLAG", "OK");
}
}
[/CODE]
Cheers,
Roland
0
Please sign in to leave a comment.
Comments
0 comments