Question
· Jan 13, 2016

Best way to retrieve specific record?

New to CSP and Zen.  I've been going through tutorials and have made some progress.  Using the "Contacts" tutorial as an example, I'm trying to create a "ViewContact" page.  I want this to be linkable so I'm using URI Parameters, which I understand.  However, what I'm not sure about is how to retrieve a specific record.  Should I use a SQL statement?  If so, how?

Let's say I just wanted to display the property "Name" for the contact with ID 12.  What would be the best way to do so?

Discussion (5)0
Log in or sign up to continue

In this case, in a table you just add a new column with link 

<column header="" width="5%" linkCaption="view" link="ZenTutorial.ViewContact.cls?ID=#(%query.ID)#"/>

so, now, we got an contact's ID in every row.

and then in a ViewContact page, we should add a dataController, to our Model, and define an modelId, from url

<dataController id="contactData" 
                modelClass="ZenTutorial.ContactModel"
                 modelId="#(%url.ID)#" />

You can set modelId with URI Parameters as weel, after adding a property:

Property ContactID As %ZEN.Datatype.integer(ZENURL = "ID");

and new modelId, which now uses our new Property 

modelId="#(%page.ContactID)#"


and finally form, wich connected with previously added controllerId, and it shows two fields, read only, yet. But it is not so diffucult to add editng.

<form id="MyForm" layout="vertical" controllerId="contactData">
  <text label="ID:" id="ID" name="ID" 
    dataBinding="%id" size="5"
    readOnly="true"/>

  <text label="Name:" id="Name" name="Name" 
    dataBinding="Name" size="30"
    labelClass="required" required="true"/>
</form>