Getting and setting values

The PolicyCenter client provides JavaScript APIs for reading and writing PCF inputs, given their full render IDs. These APIs also work for editable list view cells. However, the render IDs of cells are unreliable because they are based on the row number. Therefore, a cell with the same ID might map to different underlying values, depending on how the list view is paged, filtered, or sorted.

The JavaScript APIs contain the following functions:
  • gw.api.getValue
  • gw.api.getValues
  • gw.api.setValue
  • gw.api.setValues
The following are the API descriptions of these functions:
/**
 * Return the value of a detail view input element
 * If the internal call throws an error, this method will catch and return the error as the value
 * @param {String} id full id of the input element
 * @returns {String|Array} the client side value of the input element
 */
getValue (id: string): any | any[] | Error;
 
/**
 * Return the values of multiple detail view input elements
 * If the internal call throws an error, this method will catch and return the error as the value
 * @param {Array} ids array of full ids of the input element
 * @returns {Array} array of the client side values of the input elements
 */
getValues (ids: string[]): any[] | Error;
 
/**
 * Set the value of a detail view input element
 * Returns true/false depending on the success of the internal method call.
 * If the internal method call throw an error, this method will catch it and return the error
 *
 * The set/get value methods are often invoked by content within an PCF TemplatePanel, which
 * automatically converts a PCF element reference to its client side id for the JavaScript call.
 * For example,
 *
 *   <TemplatePanel>
 *     <TemplatePanelContents>
 *       <ReferencedWidget widget="colorCode"/>
 *       <![CDATA[
 *         <script>
 *           selectColor(color) {
 *             gw.api.setValue('${colorCode}', color);
 *           }
 *         </script>
 *       ...
 *       ]]>
 *     </TemplatePanelContents>
 *   </TemplatePanel>
 *
 * @param {String} id full id of the input element
 * @param {boolean} forceChangeEvent if true then fire a JavaScript change event after changing the input value
 * @param {String|Array} value new client side value of the input element
 */
setValue (id: string, value: string | any[], forceChangeEvent: boolean): boolean | Error;
 
/**
 * Set the value of multiple detail view input elements
 * Returns true/false depending on the success of the internal method call.
 * If the internal method call throw an error, this method will catch it and return the error
 * @param {Object} valuesById map of new input values, keyed by the full id of the corresponding input
 * @param {boolean} forceChangeEvent if true then fire a JavaScript change event after changing each input value
 */
setValues (valuesById: GwMap, forceChangeEvent: boolean): boolean | Error;

Note that the value of an input can be a simple string (most inputs), an array of strings (shuttle inputs, multiselects, check box groups) or a Boolean (a single check box or radio button).

The forceChangeEvent argument to the setter functions determines whether any behavior tied to the input (such as post-on-change) is fired when the value changes. If forceChangeEvent is true, then the call generates a JavaScript change event after updating the inputs. The change event invokes the standard PCF change handling to check for post-on-change and other behavior.