Skip to main content

Script API

info

This content is intended for advanced Studio users.

Script API is a JavaScript API exposed on the Form renderer instance. It provides programmatic access to form fields, elements, values, validation, composition saving, page navigation, and more.

warning

Script API requires deep JavaScript knowledge, and scripts are generally harder to develop and maintain than dependencies defined in Form builder. Use dependencies where they are sufficient.

Access Script API by calling getScriptApi() on the renderer element reference after the onFormRendered event fires:

const scriptApi = fr.getScriptApi();

Values​

Methods for reading and writing field values, variable values, and typed field values.

getFieldValue​

Returns the value of a form field.

getFieldValue(tagOrPath, multiIndex, searchWithinContainerTag, containerMultiIndex, simpleValue)
ParameterTypeRequiredDefaultDescription
tagOrPathstringYes—Alias, path, or tag of the form field.
multiIndexnumberNo0Index of the value.
searchWithinContainerTagstringNo—Tag of the parent container to search from.
containerMultiIndexnumberNo0Index of the parent container instance.
simpleValuebooleanNotrueWhen true, returns the label for CODED_TEXT fields for backwards compatibility.

Returns: Object | undefined

getFieldSearchValue​

Returns the current search input value of a coded text field.

getFieldSearchValue(tagOrPath, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDefaultDescription
tagOrPathstringYes—Alias, path, or tag of the form field.
multiIndexnumberNo0Index of the value.
searchWithinContainerTagstringNo—Tag of the parent container to search from.
containerMultiIndexnumberNo—Index of the parent container instance.

setFieldValue​

Sets the value of a form field.

setFieldValue(tagOrPath, value, prop, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeAccepted valuesRequiredDefaultDescription
tagOrPathstring—Yes—Alias, path, or tag of the form field.
valuestring, number, or array—Yes—Value or values to set.
propstringProperty namesNovalueProperty name of the form field.
multiIndexnumber—No—Index of the value.
searchWithinContainerTagstring—No—Tag of the parent container to search from.
containerMultiIndexnumber—No0Index of the parent container instance.

setDateField​

Sets the value of a date field.

setDateField(tagOrPath, year, month, day, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDefaultDescription
tagOrPathstringYes—Alias, path, or tag of the form field.
yearnumberYes—Year value.
monthnumberYes—Month value.
daynumberYes—Day value.
multiIndexnumberNo0Index of the value.
searchWithinContainerTagstringNo—Tag of the parent container to search from.
containerMultiIndexnumberNo0Index of the parent container instance.

setDateTimeField​

Sets the value of a date-time field.

setDateTimeField(tagOrPath, year, month, day, hour, minute, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDefaultDescription
tagOrPathstringYes—Alias, path, or tag of the form field.
yearnumberYes—Year value.
monthnumberYes—Month value.
daynumberYes—Day value.
hournumberYes—Hour value.
minutenumberYes—Minute value.
multiIndexnumberNo0Index of the value.
searchWithinContainerTagstringNo—Tag of the parent container to search from.
containerMultiIndexnumberNo0Index of the parent container instance.

setTimeField​

Sets the value of a time field.

setTimeField(tagOrPath, hour, minute, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDefaultDescription
tagOrPathstringYes—Alias, path, or tag of the form field.
hournumberYes—Hour value.
minutenumberYes—Minute value.
multiIndexnumberNo0Index of the value.
searchWithinContainerTagstringNo—Tag of the parent container to search from.
containerMultiIndexnumberNo0Index of the parent container instance.

setProportionField​

Sets the value of a proportion field.

setProportionField(tagOrPath, numerator, denominator, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDefaultDescription
tagOrPathstringYes—Alias, path, or tag of the form field.
numeratornumberYes—Numerator value.
denominatornumberYes—Denominator value.
multiIndexnumberNo0Index of the value.
searchWithinContainerTagstringNo—Tag of the parent container to search from.
containerMultiIndexnumberNo0Index of the parent container instance.

clearValue​

Clears a specific value from fields that support selection values.

clearValue(tagOrPath, valueCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
valueCodestringYesCode of the value to clear.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

clearValues​

Clears all values on the form.

clearValues()

clearFormElement​

Clears the value of a form element. If the element is a container, clears all children.

clearFormElement(tagOrPath, options, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
optionsScriptApiClearOptions or stringYesClear options or the parent container tag.
containerMultiIndexnumberNoIndex of the parent container instance.

resetFormElement​

Resets a form element to its default value.

resetFormElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

getVariable​

Returns the name and value of a variable.

getVariable(variableName)
ParameterTypeRequiredDescription
variableNamestringYesName of the variable.

Returns: Variable

setVariableValue​

Sets the value of a specific variable.

setVariableValue(variableName, value)
ParameterTypeRequiredDescription
variableNamestringYesName of the variable.
valueanyYesValue to set.

clearVariableValue​

Clears the value of a specific variable.

clearVariableValue(variableName)
ParameterTypeRequiredDescription
variableNamestringYesName of the variable.

formatDate​

Formats a date value using a specified format string.

formatDate(date, format)
ParameterTypeRequiredDescription
dateDate or numberYesThe date to format.
formatstringYesFormat string. See Event types.

Visibility and state​

Methods for showing, hiding, enabling, disabling, and toggling form elements and individual input items.

showFormElement​

Shows a form element. If the element is a container, shows all children.

showFormElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

hideFormElement​

Hides a form element. If the element is a container, hides all children.

hideFormElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

hideAndClear​

Hides a form element and clears its value.

hideAndClear(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

toggleElement​

Toggles a form element between hidden and visible states.

toggleElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

disableFormElement​

Disables a form element. If the element is a container, disables all children.

disableFormElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

enableFormElement​

Enables a form element. If the element is a container, enables all children.

enableFormElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

showValue​

Shows a specific input item.

showValue(tagOrPath, valueCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
valueCodestringYesCode of the input item.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

hideValue​

Hides a specific input item.

hideValue(tagOrPath, valueCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
valueCodestringYesCode of the input item.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

hideClearValue​

Hides and clears a specific input item simultaneously.

hideClearValue(tagOrPath, valueCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
valueCodestringYesCode of the input item.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

disableValue​

Disables a specific input item on a form element by code value.

disableValue(tagOrPath, valueCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
valueCodestringYesCode of the input item to disable.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

enableValue​

Enables a specific input item on a form element by code value.

enableValue(tagOrPath, valueCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
valueCodestringYesCode of the input item to enable.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Input items​

Methods for adding, removing, and replacing coded text and form element input items, including setting values by label.

addFormElementInput​

Adds input items to a form component of type DV_TEXT or DV_CODED_TEXT.

  • For DV_TEXT: provide a plain text string.
  • For DV_CODED_TEXT: provide an object or array of objects with label and code.
addFormElementInput(tagOrPath, inputItem, insertIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
inputItem{label: string; code: string}, array, or stringYesInput item or items to add.
insertIndexnumberNoIndex at which to insert the item.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

removeFormElementInput​

Removes a form element input item by code value.

removeFormElementInput(tagOrPath, inputItemCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
inputItemCodestringYesCode of the input item to remove.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

addCodedTextInput​

Adds an input item to a coded text field.

addCodedTextInput(tagOrPath, inputItemValue, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
inputItemValueInputItemYesInput item object { label: string, code: string }.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance. Defaults to 0 if searchWithinContainerTag is set.

removeCodedTextInput​

Removes a coded text input item by code value.

removeCodedTextInput(tagOrPath, inputItemCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
inputItemCodestringYesCode of the input item to remove.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setCodedTextInputItems​

Replaces all existing input items in a coded text field with a new set.

setCodedTextInputItems(tagOrPath, inputItems, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
inputItemsInputItem[]YesReplacement input items.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setCodedTextInputs​

warning

Deprecated. Use addFormElementInput instead.

getFieldInputs​

Returns input items (code/value pairs) for a form field. Returns an empty array if no model or value set is found.

getFieldInputs(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: array

setCodedTextFieldByLabel​

Sets the value of a coded text field by label. If multiple items share the same label, the first one is set.

setCodedTextFieldByLabel(tagOrPath, value, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
valuestringYesLabel value to set.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setOrdinalFieldByLabel​

Sets the value of an ordinal field by label. If multiple items share the same label, the first one is set.

setOrdinalFieldByLabel(tagOrPath, value, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
valuestringYesLabel value to set.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setScaleFieldByLabel​

Sets the value of a scale field by label. If multiple items share the same label, the first one is set.

setScaleFieldByLabel(tagOrPath, value, multiIndex, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
valuestringYesLabel value to set.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

removeValue​

Removes a specific value from DV_ORDINAL, GENERIC_ORDINAL, DV_CODED_TEXT, GENERIC_CODED_TEXT, DV_TEXT (with values), or GENERIC_INPUT_TEXT (with values).

removeValue(tagOrPath, inputItemCode, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
inputItemCodestringYesCode of the input item to remove.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Multiplicity and containers​

Methods for managing container instances, expand and collapse states, and multiplicity buttons.

setMultiplicity​

Sets the exact number of instances rendered for a form element. More convenient than setting both min and max when you need a specific count.

setMultiplicity(tagOrPath, multiplicity, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
multiplicitynumberYesExact number of instances to render.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setMinMultiplicity​

Sets the minimum multiplicity of a form element.

setMinMultiplicity(tagOrPath, minMultiplicity, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
minMultiplicitynumberYesMinimum multiplicity value.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setMaxMultiplicity​

Sets the maximum multiplicity of a form element.

setMaxMultiplicity(tagOrPath, maxMultiplicity, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
maxMultiplicitynumberYesMaximum multiplicity value.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

duplicateModel​

Duplicates the model of a form element.

duplicateModel(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: ModelDuplicate

removeModel​

Removes a model or field from the form.

removeModel(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

expandFormElement​

Expands a container element. Optionally targets a specific multi-container instance.

expandFormElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
multiIndexstringYesIndex of the container instance to expand.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

collapseFormElement​

Collapses a container element. Optionally targets a specific multi-container instance.

collapseFormElement(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
multiIndexstringYesIndex of the container instance to collapse.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

expand​

warning

Deprecated. Use expandFormElement instead.

collapse​

warning

Deprecated. Use collapseFormElement instead.

showContainerMultiButtons​

Shows the multiplicity buttons on a container element.

showContainerMultiButtons(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
multiIndexstringYesIndex of the container instance.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

hideContainerMultiButtons​

Hides the multiplicity buttons on a container element.

hideContainerMultiButtons(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
multiIndexstringYesIndex of the container instance.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Validation​

Methods for validating the form, pages, and individual elements, checking element state, clearing errors, and applying custom validation rules.

validateForm​

Validates the entire form and returns a validation result with an errors map.

validateForm(showErrors)
ParameterTypeRequiredDescription
showErrorsbooleanNoSpecifies whether to show errors on fields.

Returns: Object

validatePage​

Validates a page and shows validation errors on it.

validatePage(pageId)
ParameterTypeRequiredDescription
pageIdstringYesID of the page.

Returns: boolean

validateElement​

Validates a form element and optionally shows errors on the field.

validateElement(tagOrPath, searchWithinContainerTag, containerMultiIndex, showErrors)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.
showErrorsbooleanNoSpecifies whether to show errors on the field.

Returns: boolean

isElementValid​

Validates a form element and returns the result without showing errors.

isElementValid(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: boolean

isPageValid​

Validates a page and returns the result.

isPageValid(pageId)
ParameterTypeRequiredDescription
pageIdstringYesID of the page.

Returns: boolean

isFormDirty​

Returns true if the user has interacted with the form.

isFormDirty()

Returns: boolean

isEmpty​

Returns true if the specified element has no value.

isEmpty(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: boolean

isNotEmpty​

Returns true if the specified element has a value.

isNotEmpty(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: boolean

clearValidationErrors​

Clears validation errors from a form element.

clearValidationErrors(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

clearPageValidationErrors​

Clears validation errors on a page.

clearPageValidationErrors(pageName)
ParameterTypeRequiredDescription
pageNamestringYesAlias, path, or tag of the page element.

requireFormElement​

Marks a form element as required or optional.

requireFormElement(tagOrPath, value, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
valuebooleanYestrue to mark as required, false to mark as optional.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setPatternValidation​

Applies a custom regex pattern validation and error message to a field.

setPatternValidation(tagOrPath, pattern, errorMessages, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesPath or tag of the form element.
patternstringYesRegex pattern.
errorMessagesstring or Record<string, string>YesError message or language-keyed map, e.g. { en: 'Error', fr: 'Erreur' }.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

removePatternValidation​

Removes a custom regex validation from a field.

removePatternValidation(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

addValidator​

Attaches a custom validator function to a field. The validator runs on every value change and must return true when the value is invalid, or false / null when it is valid.

addValidator(tagOrPath, validator, options)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
validator(value: unknown) => boolean | nullYesValidator function. Return true for invalid, false or null for valid.
optionsobjectNoSee options below.

options

KeyTypeRequiredDescription
errorTranslationstring or Record<string, string>NoError message, or language-keyed map e.g. { en: 'Invalid', de: 'Ungültig' }. Defaults to 'Field invalid'.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

markDirty​

Marks a form field as dirty and triggers validation. Use this to programmatically surface validation errors before the user interacts with the field.

markDirty(tagOrPath, options)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
optionsobjectNoSee options below.

options

KeyTypeRequiredDescription
multiIndexnumberNoIndex of the field instance.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

markPristine​

Marks a form field as pristine, resetting its dirty state. Validation errors that are only shown after user interaction are hidden.

markPristine(tagOrPath, options)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
optionsobjectNoSee options below.

options

KeyTypeRequiredDescription
multiIndexnumberNoIndex of the field instance.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Events and listeners​

Methods for registering and removing field-level and variable-level event listeners, and for destroying all event handlers on the instance.

addListener​

Registers an event listener on a form element.

addListener(tagOrPath, eventType, callbackFn, optionsParam)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
eventTypestringYesSee Event types.
callbackFnOnChangeFieldValueNoCallback function.
optionsParamScriptApiListenerOptionsNoSee Types.

removeListener​

Removes an event listener from a form element.

removeListener(tagOrPath, eventType)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
eventTypestringYesSee Event types.

addListenerForVariable​

Registers an event listener on a specific variable.

addListenerForVariable(variableName, eventType, callbackFn)
ParameterTypeRequiredDescription
variableNamestringYesName of the variable.
eventTypestringYesSee Event types.
callbackFnOnChangeFieldValueNoCallback function.

Returns: Array<Observable>

destroy​

Destroys all event handlers on the form element.

destroy()

dispatchCustomEvent​

Outputs an object { type: "CUSTOM_EVENT", payload: {} } from the form-renderer element, that can be captured by the parent application via the eventDispatched output.

dispatchCustomEvent(payload)
ParameterTypeRequiredDescription
payloadunknownYesOutput payload.

Composition​

Methods for saving, updating, and reading the composition, managing save lifecycle hooks, and setting composition-level metadata.

saveComposition​

Saves the composition to the server.

saveComposition(validate, incomplete, requestParams)
ParameterTypeRequiredDefaultDescription
validatebooleanNotrueValidates the form before saving.
incompletebooleanNofalseSaves the composition as incomplete.
requestParamsobjectNo—Additional request parameters: comment, committerName, committerId, termMappingsFor, lifecycleState, locale.

Returns: Promise

updateComposition​

Updates an existing composition on the server.

updateComposition(validate, incomplete, requestParams)
ParameterTypeRequiredDefaultDescription
validatebooleanNotrueValidates the form before updating.
incompletebooleanNofalseUpdates the composition as incomplete.
requestParamsobjectNo—Additional request parameters: comment, committerName, committerId, termMappingsFor, lifecycleState, locale.

Returns: Promise

getComposition​

Returns the current composition instance.

warning

Changes made to the returned instance are also applied to the saved composition.

getComposition()

Returns: object

addPreSaveHook​

Registers a callback that executes before each save or update.

addPreSaveHook(hookName, callbackFn, hookOptions)
ParameterTypeRequiredDescription
hookNamestringYesName of the hook.
callbackFnfunctionNoCallback function.
hookOptionsPreSaveHookOptionsNoSee Types.

addPostSaveHook​

Registers a callback that executes after the composition is saved.

addPostSaveHook(hookName, callbackFn)
ParameterTypeRequiredDescription
hookNamestringYesName of the hook.
callbackFnfunctionYesCallback function.

addTag​

Adds a tag to the composition.

addTag(name, value)
ParameterTypeRequiredDescription
namestringYesTag name.
valuestringYesTag value.

setFormSubmissionType​

Sets the submission type of the form.

setFormSubmissionType(submissionType)
ParameterTypeRequiredDescription
submissionTypeSubmissionTypeYesCREATE or UPDATE.

setFormLanguage​

Sets the language of the form.

setFormLanguage(language)
ParameterTypeRequiredDescription
languagestringYesLanguage code to set.

Methods for navigating between pages and scrolling to specific elements.

goTo​

Navigates to a specified page or summary page by ID.

goTo(pageId)
ParameterTypeRequiredDescription
pageIdstringYesID of the page or summary page to navigate to.

goToNext​

Navigates to the next page.

goToNext()

goToPrevious​

Navigates to the previous page.

goToPrevious()

scrollToElement​

Scrolls to a form element. If the element is not found, the method completes without action.

scrollToElement(tagOrPath, searchWithinContainerTag, containerMultiIndex, scrollOptions)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.
scrollOptionsScrollIntoViewOptionsNoControls scroll behaviour.

Field metadata​

Methods for reading field and form-level metadata, managing labels, annotations, feeder audit, image areas, and terminology.

getFieldModel​

Returns the model instance of a form field.

getFieldModel(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: FormElement

getValueRef​

Returns the model instance of a form element.

warning

Changes made to the returned instance are also applied to the form element model.

getValueRef(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: FormElement or FormElement[]

getFieldPosition​

Returns the position of a field in the form.

getFieldPosition(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: number

getFormInfo​

Returns metadata about the current form.

getFormInfo()

Returns: FormInfo

getSummaries​

Returns an array of summary objects, each containing name, id, and an array of tags.

getSummaries()

Returns: array

getOrdinalNumberValue​

Returns the selected ordinal number of an ordinal field.

getOrdinalNumberValue(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: number | undefined

getScaleNumberValue​

Returns the selected scale number of a scale field.

getScaleNumberValue(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: number | undefined

setFieldLabel​

Sets the label of a form field.

setFieldLabel(tagOrPath, value, language, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDefaultDescription
tagOrPathstringYes—Alias, path, or tag of the form field.
valuestring or numberYes—New label value.
languagestringYesenLocale for the label.
searchWithinContainerTagstringNo—Tag of the parent container to search from.
containerMultiIndexnumberNo0Index of the parent container instance.

setAnnotation​

Sets an annotation on a model.

setAnnotation(tagOrPath, key, value, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
keystringYesAnnotation key.
valuestringYesAnnotation value.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

removeAnnotation​

Removes an annotation from a model.

removeAnnotation(tagOrPath, key, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form element.
keystringYesKey of the annotation to remove.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

getFeederAudit​

Returns the FeederAudit for the given template.

getFeederAudit(templateId)
ParameterTypeRequiredDescription
templateIdstringNoTemplate ID.

Returns: FeederAudit

setFeederAudit​

Sets a FeederAudit parameter and its value.

setFeederAudit(param, value, templateId)
ParameterTypeRequiredDescription
paramstringYesFeederAudit parameter to set.
valuestring, number, object, or arrayYesValue of the parameter.
templateIdstringNoTemplate ID.

getImageAreas​

Returns image map areas defined on an Interactive image field. Returns undefined if more than one model is defined for the field.

getImageAreas(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: ImageArea[]

setImageAreas​

Sets new areas for an Interactive image field. If the field is not of type DV_CODED_TEXT, the method completes without action.

setImageAreas(tagOrPath, areas, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the field.
areasImageArea[] or Object[]YesNew areas to render on the image.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

getTerminologySelectedValues​

Returns the selected terminology values for a field.

getTerminologySelectedValues(tagOrPath, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Returns: Observable

setTerminologyParameter​

Sets a terminology parameter on a form field.

setTerminologyParameter(tagOrPath, paramName, paramValue, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the form field.
paramNamestringYesName of the terminology parameter.
paramValuestringYesValue of the terminology parameter.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

Widgets​

Methods for interacting with custom widgets embedded in the form.

sendActionToWidget​

Sends an action to a widget.

sendActionToWidget(tagOrPath, action, value, searchWithinContainerTag, containerMultiIndex)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the widget.
actionobjectYesAction to send to the widget.
valueobjectYesValue to send alongside the action.
searchWithinContainerTagstringNoTag of the parent container to search from.
containerMultiIndexnumberNoIndex of the parent container instance.

setWidgetConfig​

Sets the configuration of a widget.

setWidgetConfig(tagOrPath, config)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the widget.
configobjectYesConfiguration object for the widget.

API and data​

Methods for calling API connectors and data connectors, executing AQL queries, retrieving views, and refreshing data sources.

callApi​

Calls a predefined API connector or data connector by name.

callApi(apiName, apiCallName, force)
ParameterTypeRequiredDescription
apiNamestringYesName of the API connector or data connector.
apiCallNamestringRequired for API connectorsName of the API call.
forcebooleanNoBypasses the cache and forces a fresh call. Defaults to true.

Returns: Promise

executeAql​

Executes an AQL query.

executeAql(aql, params, force)
ParameterTypeRequiredDescription
aqlstringYesThe AQL query to execute.
paramsMap<string, any>NoMap of query variable values.
forcebooleanNoInvalidates the cache when true.

Returns: Promise

getAqlView​

Retrieves an AQL view by name.

getAqlView(viewName)
ParameterTypeRequiredDescription
viewNamestringYesName of the AQL view.

Returns: Promise

getApiRequestPayload​

Returns the API request payload for a given API connector and call. Variables in the payload are not resolved at retrieval time.

getApiRequestPayload(apiName, apiCallName)
ParameterTypeRequiredDescription
apiNamestringYesName of the API connector or data connector.
apiCallNamestringNoName of the API call.

Returns: unknown

setApiRequestPayload​

Sets the API request payload for an API connector or data connector.

good to know

When using this method with a data connector, the second parameter (apiCallName) can be an empty string or undefined.

setApiRequestPayload(apiName, apiCallName, payload)
ParameterTypeRequiredDescription
apiNamestringYesName of the API connector or data connector.
apiCallNamestringYesName of the API call.
payloadunknownYesPayload for the API request.

Returns: unknown

extractDataFromApiResponse​

Extracts a value from an API response by key.

extractDataFromApiResponse(response, keyName)
ParameterTypeRequiredDescription
responseanyYesThe API response object.
keyNamestringYesKey to extract from the response.

Returns: any

refreshData​

Re-fetches data for a widget or field with a defined data source.

refreshData(tagOrPath, searchWithinContainerTag)
ParameterTypeRequiredDescription
tagOrPathstringYesAlias, path, or tag of the widget or field.
searchWithinContainerTagstringNoTag of the parent container to search from.

Frequently asked questions (FAQs)​

What is Script API?

Script API is a JavaScript API exposed on the Form renderer instance that lets you interact with a rendered form programmatically — reading and setting field values, showing or hiding elements, managing multiplicity, saving compositions, navigating pages, and more.

When can I start using Script API?

Script API is safe to use after the onFormRendered event fires. Calling it before that point may produce unexpected results.

How do I access Script API?

Call getScriptApi() on the form-renderer element reference. In framework-agnostic apps: fr.getScriptApi(). In Angular: this.formRenderer.nativeElement.getScriptApi().

When should I use Script API instead of dependencies?

Use Script API for cases that cannot be expressed as dependencies in Form builder — for example, complex conditional logic that depends on external application state, or interactions requiring asynchronous operations. Dependencies are simpler to maintain and should be preferred where they are sufficient.

How do I get the value of a field?

Use getFieldValue(tagOrPath). For type-specific reads such as ordinal or scale fields, use getOrdinalNumberValue or getScaleNumberValue respectively.

How do I show or hide a field programmatically?

Use showFormElement and hideFormElement. To hide and clear the value at the same time, use hideAndClear. To toggle between hidden and visible, use toggleElement.

How do I save a composition from Script API?

Use saveComposition(validate, incomplete, requestParams). The method returns a promise. Pass false as the first argument to skip validation before saving.

How do I replace the input items in a coded text field?

Use setCodedTextInputItems to replace all existing items with a new set. To add items without replacing existing ones, use addFormElementInput.

How do I control how many instances of a container are rendered?

Use setMultiplicity to set an exact count, or use setMinMultiplicity and setMaxMultiplicity to set bounds independently.