Skip to content

Instantly share code, notes, and snippets.

@sweded
Last active December 22, 2015 22:29
Show Gist options
  • Save sweded/6540439 to your computer and use it in GitHub Desktop.
Save sweded/6540439 to your computer and use it in GitHub Desktop.
Provides Quickbase query methods. Returns records, record ID's, and qbAceKey
/**
* @file /usr/local/Cellar/tomcat/7.0.37/libexec/webapps/pony/components/qbQuery.cfc
* @author Gernot Bartels 2013
* @description Provides Quickbase query methods. Returns records, record ID's, and qbAceKey
*/
component extends="qbAuth"
output="false"
accessors="true"
displayname="Quickbase query methods"
hint="getQbResult(), getQbRecords(), getRecordIds(), getQbLatestRecordId(), getQbAceKey() "
{
property
name="uuid"
type="string"
default=""
hint="The object ID in a persistence context.";
property
name="qbResult"
type="xml"
default=""
hint="The return request provided by Quickbase.";
property
name="qbRecords"
type="array"
default=""
hint="The returned records.";
property
name="qbRecordIds"
type="string"
default=""
hint="An array of record Id's";
property
name="qbLatestRecordId"
type="string"
default=""
hint="The latest [highest value] Record ID.";
property
name="qbAceKey"
type="string"
default=""
hint="The latest [highest value] Record ID.";
public any function init() {
this.setUuid(CreateUUID());
return this;
}
/*
Sets up query object and returns XML and record ID's */
public any function qFieldValue(query_data) {
http
method="GET"
result="qbReturn"
url="#SESSION.qb_url#/#query_data.qb_tableID#?act=API_DoQuery&ticket=#SESSION.qb_ticket#&apptoken=#query_data.qb_appToken#&query={'#query_data.uField#'.EX.'#query_data.uValue#'}&clist=#query_data.uList#&includeRids=1";
this.setQbResult(qbReturn.Filecontent);
this.setQbRecords(xmlSearch(QbResult, "//qdbapi/record/"));
variables.arrQbRecordIds = xmlSearch(QbResult, "//qdbapi/record/record_id_");
for (i = 1; i LTE ArrayLen(getQbRecords()); i = i + 1)
{
arrayAppend(arrQbRecordIds, getQbRecords()[i].XmlAttributes.rid);
this.setQbRecordIds(arrQbRecordIds[i]);
}
if (arrayLen(getQbRecords()) > 0) {
numQbRecordIds = arrayLen(getQbRecords());
this.setQbLatestRecordId(getQbRecords()[numQbRecordIds].XmlAttributes.rid);
}
return this;
}
/*
Return QB AceKey.
Used on Students table as AceKey is primary key on that table.
This is necessary to check if student record exists to determine
whether to Create or Update related student record. */
public any function qAceKey(query_data) {
this.setQbAceKey(xmlSearch(qFieldValue(query_data).getQbResult(), "//qdbapi/record/acekey")[1].XmlText);
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment