This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Fire Template from Code

How can I fire a template from code.

dbObject.ExecuteTemplates() does nothing.

I know there is this a way with sql (exec vid_InsertForHandleObject_0 'ExecuteTemplates', 'Person', '', @ProcID=newid) but I do not want to call sql from code, it should actually be possible from code directly?

  • I've used this script in the past (v6.x)

    Public Sub ExecuteTemplate(ByVal tableName As String, ByVal columnName As String, ByVal whereClause As String)
    Dim f As ISqlFormatter = Connection.SqlFormatter
    Dim tableEntries As IColDbObject = Connection.CreateCol(tableName)
    tableEntries.Prototype.WhereClause = f.CleanWhereClause(whereClause)
    tableEntries.Prototype(columnName).IsDisplayItem = True
    tableEntries.Load()
    For Each entry As IColElem In tableEntries
    Dim dbObject As ISingleDbObject = entry.Create
    Dim column As IDbColumn = dbObject.Columns(columnName)
    column.ExecuteTemplate()
    dbObject.Save()
    Next
    End Sub

    Worth a shot!

    HTH
    Kunal
  • How did you detect that the ExecuteTemplates method is doing nothing?

    I assume you missed to save the object after executing the method.

  • Ok it worked now, when I tested it from a process call. Before I was testing it only in Script Tester. It is a bit inconvenient creating a whole process and process plan to be able to test such things.
  • This should work in ScriptTester as well. It all depends on the save after the method call.
  • Nope, this doesnt work in script tester, event with save after the method call:

    Public Function Q1C_TestExecuteTemplate() As String
    Dim dbPerson As ISingleDbObject
    dbPerson = Connection.CreateSingle("Person", "44f5ea7a-10e2-463b-b74e-0f629a0edf7b")
    dbPerson.Load()
    dbPerson.ExecuteTemplates()
    dbPerson.Save()
    Return ""
    End Function
  • Hi,

    The reason this doesn't work in the script tester in Designer is possibly/probably because you have the 'Use transaction' flag set under 'Options':

    If this flag is set ..... anything you do to the database will be done as a transaction and rolled back at the end.

    HTH, Barry.

  • I just checked, it is set. I see you use the new version of D1IM. I am still on 6.1.3, maybe it is a bug, I can't say. But it doesn't work in script tester for me, I tested it several times.
  • Hi eMiFR,

    If the flag is set ..... you need to un-set it ...... then your test script should work. The flag/option is the same for V6/V7.

    HTH, B.