Statements > Data Access > Fetch Records

Fetch Records

Tags:  

Fetch Records

Forms are structures that contain data in Zoho Creator. The form data is stored in a relational database and Deluge provides an easy wrapper called collection variable for accessing these data. The collection variables hold one or more records fetched from a form, based on a given criteria, sort by and range. To access the currently submitted/persisted field values, you can use the Deluge variable named input with syntax input.<fieldname>

Syntax

<collection var> = formname[<criteria>] sort by <field> range from <x> to <y>;

where,

  • formvariable - it is the name of the collection variable that contains form data.

  • formname - name of the form whose data has to be fetched.

  • criteria expression - the criteria expression that evaluates to a value

  • sort by <field> - the field based on which the records will be sorted. Specifying the sort by <field> is optional.
  • range from <x> to <y> - range enables you to limit the records fetched within the start index (x) and end index (y). If range is not specified, all the records in the form that satisfy the given criteria, will be fetched.

Example

In the following example, the on add -> on success script is written to fetch specific records from the Book form with Name same as the currently submitted book name. The record fetched is stored in the collection variable named myBook. You can now access any field in this record, from the myBook variable.

on success
{
//fetch the book row from the 'Book' form
if (count(Book [Name == input.book]) > 0)
myBook = Book [Name == input.book];

//modify the 'Status' of this book to 'Issued'.
myBook.Status = "Issued";
}

Related Links



2 Comments  Show recent to old
ipsquiggle, 30 - days ago  

But what if it returns no results?
e.g.

myCollection = A_Form[ID == -1];
myCollection.A_Field = "Foo";

I would expect to be able to do this:
if (myCollection.length == 1){
myCollection.A_Field = "Foo";
}

Or something along those lines. Otherwise, it just errors and there's no chance for me to handle it.

zohocreator, 30 - days ago  

You can use the Deluge count function to check if the records satisfying the given criteria is > 0, and then proceed with fetching the records. The sample code in this topic is modified accordingly.

For more information on the count function, refer the topic given below:
http://zohocreator.wiki.zoho.com/Count-Function.html

Post a comment


 RSS of this page