3

According to the Peoplebook here, CreateRowset function has the parameters {FIELD.fieldname, RECORD.recname} which is used to specify the related display record.

I had tried to use it like the following (just for example):

&rs1 = CreateRowset(Record.User, Field.UserId, Record.UserName);
&rs1.Fill();

For &k = 1 To &rs1.ActiveRowCount
MessageBox(0, "", 999999, 99999, &rs1(&k).UserName.Name.Value);
End-for;

(Record.User contains only UserId(key), Password.
Record.UserName contains UserId(key), Name.)

I cannot get the Value of UserName.Name, do I misunderstand the usage of this parameter?

Coleman
  • 33
  • 3
  • 1) Is this the actual code? I don't have a "User" record in my installation. 2) I've never done it with a related display record. Is there a reason you can't use the other syntax with just a record name? – qyb2zm302 Feb 18 '16 at 21:16
  • 1
    1. Sorry, this is only the idea and not the actual code. The problem I want to ask is that I cannot get any values of any fields from the related display record by using CreateRowset with the parameters {FIELD.fieldname, RECORD.recname} – Coleman Feb 19 '16 at 01:18
  • 1
    2. In fact the original code is e.g. &rs1 = CreateRowset(record.A), and now I have to include some related values into this rowset at the same level from another record (e.g record.B) which is related to the primary record (record.A) by key. I may create a record view from record.A and B to replace the record.A, but many codes under this &rs1 will be affected. – Coleman Feb 19 '16 at 01:28

1 Answers1

2

Fill is the problem. From the doco:

Note: Fill reads only the primary database record. It does not read any related records, nor any subordinate rowset records.

Having said that, it is the only way I know to bulk-populate a standalone rowset from the database, so I can't easily see a use for the field in the rowset.

Simplest solution is just to create a view, but that gets old very soon if you have to do it a lot. Alternative is to just loop through the rowset yourself loading the related fields. Something like:

For &k = 1 To &rs1.ActiveRowCount
  &rs1(&k).UserName.UserId.value = &rs1(&k).User.UserId.value;
  &rs1(&k).UserName.SelectByKey();
End-for;
Barney
  • 2,786
  • 2
  • 32
  • 34