Question
· Nov 11, 2016

Adding parameter to ZEN dataCombo at runtime from server

Hi,

I try to programmatically create a parameter for a dataCombo ZEN Component (which is in turn created on the server side at runtime).

Set tParm = ##class(%ZEN.Auxiliary.parameter).%New()
Set tParm.id = "pRegion#"_pExamContainerCount, tParm.name = "pRegion#"_pExamContainerCount

Set tExam = ##class(%ZEN.Component.dataCombo).%New()
Set tExam.id = "Exam#"_pExamContainerCount, tExam.label = "Untersuchung", tExam.queryClass = "Inventory.ServiceCatalog", tExam.queryName = "QGetExaminations", tExam.showEmpty = "false", tExam.size = "52", tExam.onchange = "zenPage.updateExamDescription(zenThis.getValue());"
//Do tExam.parameters.SetAt(tParm, 1)

// add tExam to page...

Since the parameter need to be added to the Exam dataCombo I tried to use tExam.parameters.SetAt(tParm, 1) which fails at runtime with Error Collection property is not part of the page model.

I am not sure if my approach is correct. Does this anyone before? I would appreaciate any suggestions.

Best regards,

Sebastian

Discussion (2)1
Log in or sign up to continue

Hi Sebastian,

Sorry this went unanswered for so long. In case you haven't figured it out yet, one solution is:

    Do tExam.parameters.Insert(tParm)
    Do %page.%AddComponent(tParm)
    Do %page.%AddChild(tExam)

%AddComponent registers the parameter with the page, so you won't get that error. (There might be a better way to do this, but %AddComponent at least seems to work.)

Here's a full example:

Class DC.Demo.DynamicComboPage Extends %ZEN.Component.page
{

Property count As %ZEN.Datatype.integer [ InitialExpression = 0 ];

/// This XML block defines the contents of this page.
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen" title="">
<button onclick="zenPage.AddCombo();" caption="Add a Combo Box!" />
</page>
}

Method AddCombo() [ ZenMethod ]
{
    #dim %page As DC.Demo.DynamicComboPage
    Set ..count = ..count + 1
    Set tParm = ##class(%ZEN.Auxiliary.parameter).%New()
    Set tParm.id = "parameter_"_..count
    Set tParm.name = "parameter_"_..count

    Set tExam = ##class(%ZEN.Component.dataCombo).%New()
    Set tExam.id = "dataCombo_"_..count
    Set tExam.label = "Test"
    
    Do tExam.parameters.Insert(tParm)
    Do %page.%AddComponent(tParm)
    Do %page.%AddChild(tExam)
}

}