Getting cdt data from a dse

Certified Senior Developer

I have an expression that takes in a dse and spits out the column names of everything in that dse. Unfortunately, the way it does this is by querying the dse and then running a!keys() on the first entry of the result to figure that all out. While this works perfectly well when the dse has values in it, it will error out if the table is empty. So is there any way to get the same information directly from a DSE that doesn't have data in it? 

  Discussion posts and replies are publicly visible

  • I haven't had a use case to do this with a DSE input, but I bet someone here will have a trick for you.

    Only thing I have done similar is created a view (MSSQL) based on the DB's underlying INFORMATION_SCHEMA.COLUMNS details.  Used primarily in our COE for debugging truncation errors (when we have slack on field length validations in the interface - older environment).  Then I have an interface where you can select the underlying table, and it will display all of the data points by column. 

    SELECT TOP (100) PERCENT ROW_NUMBER() OVER (ORDER BY TABLE_NAME) AS Row, 
    cast(TABLE_CATALOG as varchar(100)) 'server',
    cast(TABLE_SCHEMA as varchar(100)) 'schema',
    cast(TABLE_NAME as varchar(100)) 'tableName',
    cast(COLUMN_NAME as varchar(100)) 'columnName',
    cast(IS_NULLABLE as varchar(10)) 'nullable',
    cast(DATA_TYPE as varchar(100)) 'dataType',
    cast(CHARACTER_MAXIMUM_LENGTH as int) 'maxLength'
    FROM INFORMATION_SCHEMA.COLUMNS

  • 0
    Certified Lead Developer

    If this is static, why not just create a CDT from it? Then do a!keys() on that CDT.

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    Because it's not static. I basically have to figure out what the table looks like from the dse input so I can populate/query the table regardless of which table it is. 

  • 0
    Certified Lead Developer
    in reply to Marco

    OK. Just out of curiosity, what is your use case?

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    I have a milestone component that is used across everything in the application. There are various different activities that require the milestone, but each has its own set of steps. The steps themselves are held in one table that basically builds out the milestone based on the name of the activity type. But to know which step on the milestone the milestone is supposed to be, I need to query up data from that particular activity's history table. Each activity has a different history table, so one of the rule inputs is the history table's dse. The layouts of these tables are all different, so I need to be able to basically pull up the list of column names and figure out which column has the exact data I need to tell the milestone I'm on step x.

    Now normally there is something in the history table, so it being empty isn't USUALLY a big deal, except for the very first time you create a particular activity of a particular type. I can manually throw in some dummy value in the backend of course, but I'd rather not do that if there is a better way. 

  • 0
    Certified Lead Developer
    in reply to Marco

    That is an interesting challenge :-) Thank you for the explanation.

  • If you can create a mapping of DSE to TABLE NAME, you may be able to use my solution to reference the columns via something such as INFORMATION_SCHEMA.COLUMNS - are you on MSSQL?

    I'm not sure if it is possible to access table name dynamically via DSE input, but I have seen some work magic with XML on here for related situations..

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    Thanks. It works really well and saves us the trouble of configuring a new milestone each time we come up with a new activity or need to rework the flow of an existing activity. This one minor kink aside anyway. 

  • 0
    Certified Senior Developer
    in reply to Chris

    Wouldn't I still need something in the table to do that? I'm good on the Appian side if something is in there. 

  • No, INFORMATION_SCHEMA.COLUMNS is the database definition and does not rely on data in the tables.  This is the MSSQL version, I'm not sure what you are using for an underlying database.  Just a thought for how you might be able to return columns per DSE/table regardless on data present.

    For instance, in this case we query for "chris_test_table" and are returned all column names, data types, etc in that table (more metadata is available).  The table is empty.