controller.getPK

Hello, I’d find it very useful if we had abstract access to the primary key of a controller. Would that be possible?

Thanks!
Patrick

try:

var table = databaseManager.getTable("servername","tablename");
var columnNames = table.getColumnNames();
for(var i = 0 ; i < columnNames .lenght ;i++)
{
	if (table.getColumn(columnNames[i]).isRowIdentifier())
	{
		//found the pk
	}
}

Thanks! Just found that on the weekend!

Hi,

is there also a way to find out the pk of the childtable of a relation?

Thanks!
Hans-Peter

Interesting, I had the same problem a few days ago. As far as I can see, there is currently no way if you don’t have/know a form for a record from that relation. The problem is that getTable() is not available under the foundset node, but only the controller. I already suggested to Servoy to leave form relevant functionality (getName(), readOnly, …) under the controller node and move all data related functionality under the foundset (getTableName(), getServerName(), …) node.

Currently you have to do this in a plugin, I think (at least that’s what I did).

As far as I can see, there is currently no way if you don’t have/know a form for a record from that relation.

Yes, I agree. The only way to find out the columns of a related record is, to build a record object:

var vRecord = mgtsys_solutions_to_solutionproperties.getRecord(1)

In this object I can see all child table columns. But, how do I get out the column names of this object? I hope there is a way… I don’t have time to learn building a plugin for servoy yet :oops: .

Gruss
Hans-Peter

The column names are right there. allDataProviders gives you the column names, but how do you find out which one is the primary key? As far as I see, there is no way. You need to have a getTable() to do this, and that’s not available for a record or a foundset. You need to have a controller (a form)…

but how do you find out which one is the primary key?

We are using strong conventions! E.g.: the pk always begins with the prefix “pk_”. So, if I a have the columnnames of the childtable, then I find out the name of the pk. I know, it’s not 100% safe but to solve the problem it works.

But, what do you mean with .alldataproviders? .alldataproviders gives you the dataproviders of the current form (parenttable). Also under the relation node. Or am I doing something wrongly?

Gruss
Hans-Peter

OK. That approach is only stable as long as you know what you are doing. And somehow you are right, I didn’t get the alldataproviders to return something useful for the selected record from a related foundset either. But what you could do is this:

var record = foundset.getRecord(1);
for (property in record) {
    application.output(property);
}

This should output all dataproviders of that record.

Hope this helps.

var record = foundset.getRecord(1);
for (property in record) {
application.output(property);
}

Thank you Patrick for the tip. But this is working only if you know the property name. In my case I don’t know the property name, I only know the prefix. For your example I’d need a function like “record.getAllPropertyNames”. Is there a way to find out all property names?

Gruss
Hans-Peter

This code will output all dataproviders from a record. You don’t need to know anything… Just try it out.

Cool :D it works! Thank you Patrick. I thought that “property in record” is a placeholder. That’s why I didn’t test it that way. :oops:

Gruss
Hans-Peter