Accessing table definitions from extension

Accessing table definitions from extension

  
I'm currently creating an extension that needs to log to a table using the Custom Log functionality. For this I need to provide the RuntimeLogger's Log method with a CustomLog object, that needs in its constructor an object that is actually a record of the database table's type. The thing is that in my extension, I do not have such a record, so I was wondering if it is possible to create it or access it from somewhere, in order for the Custom Log to succeed.
Hi Kilian,

You can add a input parameter of type Object and then cast it to the type you need inside the extension.

Check the CustomLog technote and use the actual CustomLog extension as example if you really need to customizations.
http://www.outsystems.com/goto/technote-custom-log

Depending on your requirements you might also want to look at this topic:
http://www.outsystems.com/forums/discussion/9010/quickly-insert-large-amounts-of-records-into-a-table/

Regards,
João Rosado
Hi João, the problem I'm facing is that I need to log from within the extension, not triggered by something from an eSpace. I cannot cast it to anything inside the extension, since the structure/object I want to cast it to is a record from a table definition. What CustomLog does is pass a record from an eSpace to the static Log method of the RuntimeLogger class. But there's no way inside the extension to fill the object passed, as its type is not known within the extension.

My reason for needing this can be found here: http://www.outsystems.com/forums/discussion/6796/how-to-log-webservice-call/, perhaps that explains it better.

Nothing comes to my mind on how we could achieve this, other than manually creating the entity in the database and importing it via Integration Studio... but that's not a very maintainable solution as you need to do the entity staging yourself... The isse here is precisely the fact the entity is created in Service Studio, so we don't have any access to it on the extension.

I'm sure João will get us a super creative solution for this :)
João... what about something like passing an object in the espace to the SoapLogger extension (when registering the SoapExtension), from which the type can be infered and stored, so that later an object instance of that type is created by reflection.... ?
So... There's no way other than doing it by Reflection...
I've added an example in the other topic:
http://www.outsystems.com/NetworkForums/ViewTopic.aspx?TopicId=6796&Topic=How-to-log-webservice-call#Post29041

I know this is so way after your initial question, but OutSystems.RuntimePublic.Db has a DatabaseAccess.ForSystemDatabase() static method that gives a DatabaseProvider that points at the metadata information in OutSystems.

You can then use DatabaseProvider's GetRequestTransaction(), and use the CreateCommand() from that. You can find all the table names of the entities like this:

using (Command command = transaction.CreateCommand("SELECT Physical_Table_Name FROM ossys_Entity"))
{
   using (IDataReader reader = command.ExecuteReader())
   {
       while (reader.Read())
       {
            string displayName = reader.GetString(0);
            string name = reader.GetString(1);
       }
   }
}

"ossys" is the prefix for a lot of the tables. You can find their field names by importing the likes of Espace, Entity and Entity_Attr from (System) when you Add/Remove Dependencies in Service Studio.