Make relation programmatically on the temporary table

I create empty dataSet and fill after data. I have only 2 fields itemid and parentid.
I try to setup relation between 2 fields. It works if I use global variable on left side and failed if I use actual Field . Why? Here the last part of code
var rel = solutionModel.newRelation(‘myRelation’, ItemDataSource, ItemDataSource, JSRelation.INNER_JOIN);
rel.initialSort = ‘itemid asc’ // ‘sortseq asc’;
rel.allowCreationRelatedRecords = true;
rel.allowParentDeleteWhenHavingRelatedRecords = true;

this part works:
rel.newRelationItem(‘scopes.globals.glb_item_id’, ‘=’, ‘parent_id’);

this part failed
rel.newRelationItem(‘item_id’, ‘=’, ‘parent_id’);

The code doesnot bomb,just myRelation not created
How to setup relation programmatically on the temporary tables(memory buffered dataset).

Leonid,

That should work, here is a small code snippet that shows it works.

	var ds = databaseManager.createEmptyDataSet(0,['a', 'b'])
	ds.addRow([1, 100])
	ds.addRow([100, 123])
	var uri = ds.createDataSource('mydata', [JSColumn.INTEGER, JSColumn.INTEGER]);
	var rel = solutionModel.newRelation('rel',uri,uri,JSRelation.INNER_JOIN)
	rel.newRelationItem('b','=','a')
	var fs = databaseManager.getFoundSet(uri)
	fs.loadAllRecords()
	application.output(fs.getRecord(1)['rel'].b) // prints 123

Rob

Thanks,it works.