To execute dataListBox dinamically?

80 views
Skip to first unread message

Andreas

unread,
May 11, 2013, 5:38:08 AM5/11/13
to intersys...@googlegroups.com
Hi, men! What I need is following: I build an SQL query for my dataListBox based on some information from ZEN-page (or %session object).
So, 1) I need to get a value from my ZEN-page;
      2) Rebuild my SQL-query for my dataListBox;
      3) Show the new results into dataListBox (put on my ZEN-page) synchroniously.
How to do this? Please help me!
If need be, I could show my unworkable example.
Thank you!

Andreas

unread,
May 11, 2013, 8:04:54 AM5/11/13
to intersys...@googlegroups.com
So, I'm inclined to use OnCreateResultSet property but I can't refresh my dataListBox after a user makes changes on the page.
<dataListBox id="dlbCSub"
 OnCreateResultSet="DLBRelationsContent"/>
and
Method DLBRelationsContent(Output tSC As %Status, pInfo As %ZEN.Auxiliary.QueryInfo) As %ResultSet
{
    Set tRS = ""
    Set tSC = $$$OK
       if $Get(%session.Data("TableName"))
         {
            Set tFROM =$Get(%session.Data("TableName"))
         }
       else
         {
        Set tFROM ="Relationships"
         
    sql = "SELECT ID, Name FROM "_tFROM_" WHERE Context="_%session.Data("CurrConID")_"ORDER BY Name"
    Set tRS = ##class(%ResultSet).%New()
    Set tSC = tRS.Prepare(sql)
    Set pInfo.queryText = sql
    Quit tRS
}

Is it the right way to supply dataListBox with changing data (%session variables)?
If so, I need to refresh it as a user, for example, has chosen something in another list or typed data into a textfield.
Something like that, but it's not working. Please correct my mistake.
onchange="zenPage.setSessionVariabes();
and
ClientMethod setSessionVariabes() [ Language = javascript ]
{
        zenPage.SetSession();
        zenPage.getComponentById('dlbCSub').executeQuery();
        zenPage.getComponentById('dlbCSub').refreshContents();
   return;
}

Method SetSession() [ ZenMethod ]
  {
      s %session.Data("TableName")=..TableNameIs(%page.%GetComponentById("fsLink").value)
      q
  }
But after changing nothing happens...
I suppose I incorrectly try to refresh my dataListBox.
Cache 2012.
Thank you for your precious help!

Vlado

unread,
May 11, 2013, 8:10:00 PM5/11/13
to intersys...@googlegroups.com
Hi Andreas,

ClientMethod setSessionVariabes() [ Language = javascript ]
{
        var x=zenPage.SetSession();  //to be sinchroniously
        zenPage.getComponentById('dlbCSub').executeQuery();
        //zenPage.getComponentById('dlbCSub').refreshContents(); // you don't need this line because exequteQuery() also refreshContents;
   return;
}
Also you need "parameter" to filter the data!
Although I'am not sure it will work with "OnCreateResultSet"!!!
Use sql statement instead or you can switch to DataCombo.
Here are 2 examples. Should be loaded in "Samples" namespace.
=============================================================================

Class ZENTest.DataComboDataListBox1 Extends %ZEN.Component.page
{

/// Application this page belongs to.
Parameter APPLICATION = "ZENTest.TestApplication";

Parameter PAGENAME = "DataComboDataListBox";

/// Domain used for localization.
Parameter DOMAIN = "ZENTEST";

XData Style
{
<style type="text/css">
</style>
}

/// This XML block defines the contents of this page.
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen]
{
<page xmlns="http://www.intersystems.com/zentitle="" >
<form id="form">
<dataCombo id="City"
label="City" 
    name="dataCombo"
editable="true"
searchKeyLen="10"
valueColumn="2"
maxRows="1000"
dropdownWidth="20.0em"
displayColumns="2"
sql="SELECT ID,Home_City FROM ZENDemo_Data.Employee WHERE Home_City %STARTSWITH GROUP BY Home_City ORDER BY Home_City"
sqlLookup="SELECT Home_City FROM ZENDemo_Data.Employee WHERE Home_City = ?"
onchange="zenPage.notifyOnChange(zenThis.getValue());">
</dataCombo>
<dataListBox id="Employee"
label="Employee" maxRows="1000" listWidth="500px" listHeight="300px"
sql="SELECT ID,Name,Home_City FROM ZENDemo_Data.Employee WHERE Home_City = ORDER BY Name">
<parameter/>
</dataListBox>
</form>
</page>
}

ClientMethod notifyOnChange(value) [ Language = javascript ]
{
var ctrl zen('Employee');
ctrl.setProperty('parameters',1,value);
}

}
---------------------------------------------------------------------------------------------------------------------------

Class ZENTest.DataComboDataCombo Extends %ZEN.Component.page
{

/// Application this page belongs to.
Parameter APPLICATION = "ZENTest.TestApplication";

Parameter PAGENAME = "DataComboDataCombo";

/// Domain used for localization.
Parameter DOMAIN = "ZENTEST";

XData Style
{
<style type="text/css">
</style>
}

/// This XML block defines the contents of this page.
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen]
{
<page xmlns="http://www.intersystems.com/zentitle="" >
<dataCombo id="City"
label="City" 
    name="dataCombo"
editable="true"
searchKeyLen="10"
valueColumn="2"
maxRows="1000"
dropdownWidth="20.0em"
displayColumns="2"
sql="SELECT ID,Home_City FROM ZENDemo_Data.Employee WHERE Home_City %STARTSWITH GROUP BY Home_City ORDER BY Home_City"
sqlLookup="SELECT Home_City FROM ZENDemo_Data.Employee WHERE Home_City = ?"
onchange="zenPage.notifyOnChange(zenThis.getValue());>
</dataCombo>
<dataCombo id="Employee"
label="Employee" name="Employee"
editable="true"
searchKeyLen="10"
maxRows="1000"
dropdownWidth="20.0em"
OnCreateResultSet="CreateRS" >
<parameter/>
</dataCombo>
</page>
}

ClientMethod notifyOnChange(value) [ Language = javascript ]
{
var ctrl zen('Employee');
    this.clear(ctrl);
ctrl.setProperty('parameters',1,value);
}


ClientMethod clear(ctrl) [ Language = javascript ]
{
ctrl.clearOnLoad='true';
        ctrl.clearCache();
        ctrl.setProperty('value','');
}

Method CreateRS(Output tSC As %Status, pInfo As %ZEN.Auxiliary.QueryInfo) As %ResultSet

{
    Set tRS = ""
    Set tSC = $$$OK

    Set tSELECT = "ID,Name,Home_City"
    Set tFROM = "ZENDemo_Data.Employee"
    Set tWHERE = ""

     // Build WHERE clause
    If ($GET(pInfo.parms(2))'="") {
        Set tWHERE = tWHERE _ $SELECT(tWHERE="":"",1:" AND ") _ "Home_City = '" _ pInfo.parms(2) _ "'"_" AND "_ " Name %STARTSWITH ?"_"Order By Name"
    }
    Set sql = "SELECT " _ tSELECT _ " FROM " _ tFROM
    Set:tWHERE'="" sql = sql _ " WHERE " _tWHERE

    
    Set tRS = ##class(%ResultSet).%New()
    Set tSC = tRS.Prepare(sql)
    Set pInfo.queryText = sql
    Quit tRS
}

}
============================================================================
**Владо

Derek Day

unread,
May 11, 2013, 9:52:05 PM5/11/13
to <intersystems-zen@googlegroups.com>, intersys...@googlegroups.com
Take a look at the Parms property and maybe the filters from the 
--
You received this message because you are subscribed to the Google Groups "InterSystems: Zen Community" group.
To post to this group, send email to InterSys...@googlegroups.com
To unsubscribe from this group, send email to InterSystems-Z...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/InterSystems-ZEN?hl=en
Zen Community Terms and Conditions: http://groups.google.com/group/InterSystems-ZEN/web/community-terms-and-conditions
---
You received this message because you are subscribed to the Google Groups "InterSystems: Zen Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to intersystems-z...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Vlado

unread,
May 11, 2013, 11:06:27 PM5/11/13
to intersys...@googlegroups.com
Here is the example which doesn't seem to work.
Of course I didn't play too much but...
=============================================================================

Class ZENTest.DataComboDataListBox Extends %ZEN.Component.page
label="Employee" name="Employee" maxRows="1000"
listWidth="500px" listHeight="300px"
OnCreateResultSet="CreateRS">

<parameter/>
</dataListBox>
</form>
</page>
}


ClientMethod notifyOnChange(value) [ Language = javascript ]
{
var ctrl zen('Employee');
ctrl.setProperty('parameters',1,value);
}

Method CreateRS(Output tSC As %Status, pInfo As %ZEN.Auxiliary.QueryInfo) As %ResultSet
{
    Set tRS = ""
    Set tSC = $$$OK

    Set tSELECT = "ID,Name,Home_City"
    Set tFROM = "ZENDemo_Data.Employee"
    Set tWHERE = ""

     // Build WHERE clause
    If ($GET(pInfo.parms(2))'="") {
        Set tWHERE = tWHERE _ $SELECT(tWHERE="":"",1:" AND ") _ "Home_City = '" _ pInfo.parms(2) _ "'"_" AND "_ " Name %STARTSWITH ?"
    }
    Set sql = "SELECT " _ tSELECT _ " FROM " _ tFROM
    Set:tWHERE'="" sql = sql _ " WHERE " _tWHERE
    
    Set tRS = ##class(%ResultSet).%New()
    Set tSC = tRS.Prepare(sql)
    Set pInfo.queryText = sql
    Quit tRS
}

}
============================================================================
**Владо
To post to this group, send email to InterSy...@googlegroups.com
To unsubscribe from this group, send email to InterSystems-...@googlegroups.com

Derek Day

unread,
May 12, 2013, 8:44:50 PM5/12/13
to <intersystems-zen@googlegroups.com>, intersys...@googlegroups.com
There are several issues here.. First, as on a recent thread, it seems to work best to give the parameters and Id and set the values by id.

Second, don't set session data,for page requests... Not only does it make extra network requests, but it breaks if the user has more than one page open and isn't user friendly.

Finally, and most importantly never build query text from invalidated user input!

Sent from my iPad
To post to this group, send email to InterSys...@googlegroups.com
To unsubscribe from this group, send email to InterSystems-Z...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages