Abstract
Returns an array of all active [[OptionItem]]s for this field.
// get the CSS classes of all the active OptionItems
const activeClasses = field.activeOptions().map(op => [op, op.cssClass()])
Returns an array of all possible [[OptionItem]]s for this field, active
, disabled
, locked
, and obsolete
.
// get the stati of all the OptionItems
const statuses = field.allOptions().map(op => [op, op.status()]);
An object of alternate ids for this object, with values as [[AltId]]
// you've marked certain forms with the FID of deprecated and want to filter for those
const warningMessage = baseObject.altIdsObject().FID.value().includes('deprecated') && 'Please use a different form';
An object of alternate ids for this object, with values as strings
// you've marked certain forms with the FID of deprecated and want to filter for those
const warningMessage = baseObject.altIds().FID.includes('deprecated') && 'Please use a different form';
Same as calling optAncestor(var).orElse(null)
If this object is a Collection it returns it as an array. The majority of objects in the system are Collections. For most objects, this is the same as calling [[children]].
const ids = obj.asArray().map(ob => ob);
Get the children of the object. This retrieval goes one level deep.
Optional
classType: string | numberconst childrenNames = obj.children().map(child => child.displayName());
The deleted children of this object. Only looks one level deep. E.g. a form's deleted children could include fields and form entries. A folder's deleted children could include folders, forms, and formulas, but not any of those forms' entries.
const deleted = baseObject.deletedChildren();
Returns an array of all disabled [[OptionItem]]s for this field. A disabled
[[OptionItem]] will show up on a form, but it won't be selectable.
// get the indexes of all the disabled OptionItems
const disabledIndexes = field.disabledOptions().map(op => [op, op.index()])
The default display name of this object. For the most part, this is the same as calling toString()
, which is the same as inserting the object into a string.
The following assumes you have already aggregated a selection of baseObject
s into an array
const displayNames = [];
for (const o of baseObjects) displayNames.push(o.displayName());
const namesList = `<ul><li>${displayNames.join('</li><li>')}</li></ul>`;
Sets the Display Name.
Returns this field's [[FormMetaData]] object.
const form = firstName.form();
const fieldNames = [];
for (field in form) fieldNames.push(form[field].displayName());
Gets an array of all the object's ancestors.
const numberOfAncestors = obj.getAncestors().length;
Returns whether the field is multi-select.
// get selected export values without knowing if it's single or multi
const selectedExport = field.isMultiSelect() ?
field.selectedExportValues() : field.optSelected().exportValue();
Returns the Local Cache object for this Thread/Base Object.
Returns an array of all locked [[OptionItem]]s for this field. A locked
[[OptionItem]] will show up on a form, but it won't be selectable.
// see if any locked OptionItems are selected
const selectedLocked = field.lockedOptions().filter(op => op.isSelected())
The lookup function finds a single option in the list of options using the custom lookup properties of the option items. Custom lookup properties come in two varieties: unique and non-unique. Names beginning with an underbar (_
) do not have to be unique. Names that do not begin with an underbar must be unique name/value pair for any one type of Relate element within a single organization. Thus, if the name begins with an underbar there could be more than one option that has the same name/value pair associated with it. In this case, the first matching option will be returned.
// see whether the lowest or highest priority options were selected
// assumes you already have the functions handleLowest, handleHighest, and handleOther
const selExpVal = field.optSelected().map(op => op.exportValue());
const low = field.lookup('_priorityLevel', 'lowest');
const high = field.lookup('_priorityLevel', 'highest');
low.isSelected() && handleLowest(low);
high.isSelected() && handleHighest(high);
!low.isSelected() && !high.isSelected() && handleOther(selExpval);
Returns the [[FieldMetaData]] object that this describes this field.
const firstNameClass = firstName.metaData().styleClass();
Returns an array of all obsolete [[OptionItem]]s for this field. [[OptionItem]]s are marked obsolete
if they are never going to be used again, but still need to exist for legacy data. Will not show up on a form.
// get the groups containing each of the obsolete OptionItems
const obsoleteGroups = field.obsoleteOptions().map(op => [op, op.groups()])
Optional value for this field. Same as [[valOpt]]. Try to use this as often as you can over val()
; Null-pointer exceptions can be a pain, and this will provide a measure of safety. Try to reserve val()
for situations where a field is required and you know that the value cannot be null.
const middleName = middleName.opt().orElse('No Middle Name Set!');
// or, similarly
const middleName = middleName.val() || 'No Middle Name Set!'
A [[Java.Optional]] of the ancestor with the specific class.
const ancestors = obj.optAncestor(1000001).ifPresent(a => console.log('${a} exists'));
A [[Java.Optional]] of the current object's parent object.
Optional
classType: string | numberconst ancestors = obj.optAncestor(1000001).ifPresent(a => console.log('${a} found'));
Returns an object where the members are the export value and the values are [[OptionItem]].
// get an alphabetized list of the export values
const orderedExportVals = Object.keys(field.optionsByExport()).sort();
Returns an object where the members are the name and the values are [[OptionItem]].
// only get the options shorter than 20 characters
const onlyShortOps = Object.keys(field.optionsByName()).filter(key => key.length < 20)
Same as calling optParent(var).orElse(null)
Optional
classType: string | numberReturns a list of selected [[OptionItem]]s.
// get the stati of the selected OptionItems
const selStatus = field.selectedOptions().map(op => [op, op.status()]);
Sets or clears the OptionItem with the given ID. Returns true
if successful.
The ID of the OptionItem to set
Optional
checked: booleanDefaults to true
Gets the field's value if there is one, and will otherwise return null. Some overrides of this method have default return-values for convenience but, that would not make sense for this: the general-use case. In situations where the value might be null
(e.g. non required field), consider using optional chaining: field.val()?.toString()
.
The preferred method to handle null
s in bs.js is simply [[opt]]/[[valOpt]]; as the methods available off of that can handle virtually any situation.
This is identical to calling field.opt().orElse(null)
.
// it is important to notice that, due to how JavaScript works, doubleVal will evaluate to 0 if numberField.val() is null.
const doubleVal = numberField.val() * 2;
Set the field's value.
The value to be put into the field.
// make the field say `hello`
field.val('hello');
The versions of this object.
const versions = baseObject.versions();
Returns a view URL for this object, if it has one. This value is always a relative URL, meaning it does not contain the protocol prefix or domain name such as http://xyz.bluestep.net
.
const viewBtn = `<button data-href="${baseObject.viewUrl()}">Go to ${baseObject.displayName()}</button>;
Generated using TypeDoc
Contains common methods to [[SingleSelectField]] and [[MultiSelectField]].