Questions:
a. Is it possible to create a dynamic drop down list ?
b. How do I change the order of translate value in drop down list for a field on a page?
The fastest way to do it is to use PeopleCode to force your values in the list by using following 2 functions of Field class.
1. Field.ClearDropDownList(): It removes the current contents of the DDL.
2. Field.AddDropDownItem([Value],[Descr]): It takes two string parameters,
[Value]: It is actual value which is mapped to the dropdown item
[Descr]: It is actual text which is visible as a dropdown item
Note that the DDL is automatically alpha sorted by Descr not value.
/* Define a field object for which you want to populate the drop down values */
&FLD_temp =Field.ACTION_RSN;
/* Clear the current dropdown values */
&FLD_temp.ClearDropDownList();
/* Following logic would be used to dynamically populate stanalone rowset with the values */
&RS_temp = CreateRowset(Record.ACTN_RSN_TBL);
&RS_temp.Fill("WHERE ACTION= .......");
/* Add the values to the dropdown list*/
For &I = 1 To &RS_temp.ActiveRowCount
&FLD_temp.AddDropDownItem(&RS_temp.GetRow(&I).GetRecord(1).ACTION_REASON.Value, &RS_temp.GetRow(&I).GetRecord(1).DESCR.Value);
End-For;
When dealing with XLAT values, you may want to consider the global approach of considering the language code.
Check whether base language <> language selected
if True
---------
&xlat1=CreateRowset(Record.PSXLATITEMLANG);
&Xlat.Fill("WHERE ....");
&Xlat_cnt = &Xlat.ActiveRowCount;
For &I = 1 To &Xlat_cnt
&CodeIn = &Xlat.GetRow(&I).GetRecord(1).FIELDVALUE.Value;
&DescIn = &Xlat.GetRow(&I).GetRecord(1).XLATLONGNAME.Value;
&FLD_temp.AddDropDownItem(&CodeIn, &DescIn);
End-For;
&Xlat = CreateRowset(Record.PSXLATITEM);
&Xlat.Fill("WITH TRANSLATES NOT EXISTS IN LANGUAGE TABLE");
&Xlat_cnt = &Xlat.ActiveRowCount;
For &I = 1 To &Xlat_cnt
&CodeIn = &Xlat.GetRow(&I).GetRecord(1).FIELDVALUE.Value;
&DescIn = &Xlat.GetRow(&I).GetRecord(1).XLATLONGNAME.Value;
&FLD_temp.AddDropDownItem(&CodeIn, &DescIn);
End-For;
If false
---------
&Xlat = CreateRowset(Record.PSXLATITEM);
&Xlat.Fill("WHERE ....");
&Xlat_cnt = &Xlat.ActiveRowCount;
For &I = 1 To &Xlat_cnt
&CodeIn = &Xlat.GetRow(&I).GetRecord(1).FIELDVALUE.Value;
&DescIn = &Xlat.GetRow(&I).GetRecord(1).XLATLONGNAME.Value;
&FLD_temp.AddDropDownItem(&CodeIn, &DescIn);
End-For;
You can place this code in the postbuild of the component or rowinit PeopleCode, depending on the requirement.
If you have a drop down list on a page and want to place items into the drop down list dynamically, here is a bit of insight on how to do it.
The SetEditTable method works with the ExecuteEdits method. It is used to set the value of a field on a record that has it's prompt table defined as %PromptField value. %PromptField values are used to dynamically change the prompt record for a field.
There are several steps to setting up a field that you can dynamically change its prompt table.
To set up a field with a dynamic prompt table:
Define a field in the DERIVED record called fieldname.
In the record definition for the field you want to have a dynamic prompt table, define the prompt table for the field as %PromptField, where PromptField is the name of the field you created in the DERIVED record.
For more information, see Creating a New Record.
Use SetEditTable to dynamically set the prompt table.
%PromptField is the name of the field on the DERIVED work record. RECORD.recordname is the name of the record to be used as the prompt table.
&MSG.SetEditTable("%EDITTABLE_1", Record.DEPARTMENT);
&MSG.SetEditTable("%EDITTABLE_2", Record.JOB);
&MSG.SetEditTable("%EDITTABLE_3", Record.PERSONAL_DATA);
&MSG.ExecuteEdits();
Every field on a record that has the prompt table field %EDITTABLE1 will have the same prompt table, such as, DEPARTMENT.
No comments:
Post a Comment