[TIP] Get record data by PK ID without executing a search
by Karel Broer
Is it possible to get all info from a record without doing any search? The answer is yes! For this trick you only need to know the record primary key and Servoy 3.5.
//set your pk
var vCompID = 8
//set servername from record table
var vServer = controller.getServerName()
//set tablename
var vTable = 'companies'
//create a foundset
var vSet = databaseManager.getFoundSet(vServer, vTable)
//load record by ID in foundset
vSet.loadRecords(databaseManager.convertToDataSet([vCompID]))
//get record data
var vName = vSet.company_name
//or retrieve record data from the record object
var vRecord = vSet.getRecord(1)
var Mail = vRecord.company_email
So now you get a record without any searching and no complicated SQL. You might doublecheck if vSet.loadRecords() get's a record by performing:
var vCount = databaseManager.getFoundSetCount(vSet)
Comments (7)