cancel
Showing results for 
Search instead for 
Did you mean: 

Creating tables within Simple AddOn Installer.

Former Member
0 Kudos

The B1DE tools to create addons and installers for them are great! They have really simplified my job.

But I'm still learning how to use them and I am writing an addon that needs some UDTs. I would like to programmatically add the tables to the database when the addon is being installed but I don't know if this can be done and where in the generated simple installer code, my code would be placed. I don't see where the installer is connecting to a company and I don't know where to begin.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello John,

It is great that you enjoy the tools

Actually the best practice for creating UDT and UDF is to add them during add-on start. You could check out Addon Code Generator. It will help you to create the code for adding UDT and UDF. Enjoy~~

Hope this helps,

Nick

Former Member
0 Kudos

Hi Allan & Nick,

I did use the addon generator to build my tables and this does work, but as Allan mentioned, it does really seem to slow down the start up of the addon even after the tables exist.

Allan, I'm not sure I understood your response completely. Are you saying you use a recordset to read the OUTB table for an entry with your table name to decide if they should be built or not?

Thanks again

rasmuswulff_jensen
Active Contributor
0 Kudos

Hi John...

Adding UDF and UDT using the installer is not an option since the installer need to be a 1 file program (and therefor you can't use the SAPBobsCom) ... If you really need the creation to be outside the addon, you could write a little external program that creates the metadata... Along way to go but it works...

But here's how we do it..

- First time one of our addons runs we use these two recordset methods for checking data:


public static bool ExistTable(string tableName)
{
  try
  {
    B1Recordset rs = B1Recordset.DoQuery("SELECT COUNT(*) AS antal FROM OUTB WHERE tableName='" + tableName + "'");
    int antal = rs.GetValueAsInteger("antal");
    rs = null;
    GC.Collect();
    return (antal == 1);
  }
  catch
  {
    return false;
  }
}

public static bool ExistField(string tableName, string uid)
{
  try
  {
    B1Recordset rs = B1Recordset.DoQuery("SELECT COUNT(*) AS antal FROM CUFD WHERE TableID LIKE '%" + tableName + "' AND AliasID='" + uid + "'");
    int antal = rs.GetValueAsInteger("antal");
    rs = null;
    GC.Collect();
    return (antal == 1);
  }
  catch 
  {
    return false;
  }
}

These methods are pretty fast to check with, but to make things faster we use a file with the dbName the indicate that files have been added to a specific database. Next time we do a startup we check if this file exist, and if it does it skips the part of the code that create metadata...

We have been using this approach for about 2 years now and it works pretty well...

BTW: In the example, please ignore the strange syntax of the recordset. It's just part of our wrapper around the recordset to make it faster to work with (sorry, didn't have the time to change the code back to core sdk)

Message was edited by:

Rasmus Jensen

Answers (1)

Answers (1)

Former Member
0 Kudos

I do have the creation of UDT and UDFs in my code and not in the installer.

When the program starts It checks a file where the company DB is listed if UDTs and UDFs are created successfully. If the company DB is not listed in the fil UDTs and UDFs will be created.

My experience is that the creation of UDTs can take some time, and further more it takes some time for SBO to recocnize the tables. So at startup of my addons the user wil be prompted to check the UDT as the file will be located at the Client where the Addon is running.

Hope this can inspire You.