SetControlValue function

Syntax

SetControlValue(Value, PageName, PageFieldName [, RowNumber] [, &Field])

Description

Use the SetControlValue function to set an override string on the current field so that it simulates an end user entering data.

When a page is refreshed after a PeopleCode program completes, each field value gets set from the buffer. However, if you use this function to specify an override string for a field, the value you specify is used instead of the value in the buffer. This value is inserted directly into the control on the page, as if the end user typed it in. The field buffer remains unchanged. All validations, FieldEdit and FieldChange PeopleCode run immediately.

This function can be used in the following scenario: Suppose you have a text field that has a menu pop-up associated with it. The end user can use a secondary page to select an item to be used for the value. From the menu PeopleCode, you can verify that the value is valid, but the field doesn’t turn red and the end user can leave the field. This could potential mean saving the page with bad data. You can use this function after the secondary page is dismissed. This causes the same edits to be run as if the end user had typed in the value.

This function doesn't work for radio button or check box controls.

Parameters

Parameter Description

Value

Specify an override value on the current field. This parameter takes a string value.

pagename

Specify the name of page where the field exists.

pagefieldname

Specify the page field name. This is not the name of the field. This is the name that is assigned to the field in Application Designer, on the page field properties.

RowNumber

Specify the row number of the field. The default value is 1 if this parameter isn't set.

&Field

Specify an already instantiated field object referencing the field you want to override.

Note:

If you want to set an override string for a field on the level 1 scroll for a page, you do not need to specify either a row number or a field object. However, if you want to set the override string for a field on either the second or third level scroll for a page, you must specify both a row number and a field object for SetControlValue to work.

Returns

None.

Example

Declare Function item_seach PeopleCode FUNCLIB_ITEM.INV_ITEM_ID FieldFormula; 
&SEARCHREC = "PS_" | RECORD.MG_ITEM_OWN1_VW; 
item_seach("", SF_PRDN_AREA.BUSINESS_UNIT, "ITEM", &SEARCHREC, "", &INV_ITEM_ID,⇒
 ""); 
SetControlValue(&INV_ITEM_ID);

The following example is used in the PeopleSoft Pure Internet Architecture:

Declare Function item_search PeopleCode FUNCLIB_ITEM.INV_ITEM_ID FieldFormula; 
Component string &ITEM_ID_SEARCH; 
&ITEMRECNAME = "PS_" | Record.MG_ITEM_PDO_VW; 
item_serach("", EN_PDO_WRK.BUSINESS_UNIT, "ITEM", &ITEMRECNAME, "", &INV_ITEM_ID,⇒
 ""); 
If All(&INV_ITEM_ID) Then 
   Evaluate &ITEM_ID_SEARCH 
   When "F" 
      SetControlValue(&INV_ITEM_ID, Page.EN_PDO_COPY, "FROM_ITEMID") 
   When "T" SetControlValue(&INV_ITEM_ID, Page.EN_PDO_COPY, "TO_ITEMID") 
   End-Evaluate; 
End-If;

Considerations With Field Verification

SetControlValue only sets the value of the field. If you specify an incorrect value, SetControlValue has an error at runtime.

For example, suppose you are setting a value like "1900-01-01" into a date field that is expecting the format 01/01/1900. If the end user entered 1900-01-01 they would get an error, so SetControlValue causes an error with this value also. You may want to use a value in the format the end user might enter. You can get this value by using the FormattedValue method on a field. For example:

&DATE_IN_EFFECT = SF_PRDN_AREA_IT.DATE_IN_EFFECT.FormattedValue; 
... 
SetControlValue(&DATE_IN_EFFECT, %Page, "DATE_IN_EFFECT", &OCCURSNUM);

The FormattedValue function converts the field value from the PeopleSoft representation to the representation the end user would see and enter.

Restrictions on Use With a Component Interface

This function is ignored (has no effect) when used by a PeopleCode program that’s been called by a Component Interface.