Bluestep JS Documentation
    Preparing search index...

    Interface Query<E>

    In all types of [[Formula]] except [[FieldMetaData.formula]], data from the [[Record]]s of a [[Query]] or report may be accessed. This is done by requiring a formula id for the query or report within the formula, and optionally defining a formula id for one or more forms from the records of the query or report. The query or report will be run as if it were being displayed in the unit of the current record being processed by the formula.

    interface Query<E extends Record> {
        add(e: E): boolean;
        add(index: number, e: E): boolean;
        addAll(c: Collection<E>): boolean;
        addAll(index: number, c: Collection<E>): boolean;
        addSearch(
            formId: string,
            field: string,
            operator: string,
            value: any,
        ): this;
        addSearch(
            fieldMetaData: FieldMetaData<any>,
            operator: string,
            value: any,
        ): this;
        addSort(formId: string, field: string, sortDirection?: SortDirection): this;
        addSort(
            fieldMetaData: FieldMetaData<any>,
            sortDirection?: SortDirection,
        ): this;
        altIdObjects(): { [name: string]: AltId<Query<E>> };
        altIds(): { [name: string]: string };
        altIdsArray(): EList<Query<E>>;
        ancestor<B extends BaseObject<B>>(classType: string | number): B;
        anchorTimestampSearch(time: number | Instant): number;
        asArray(): EList<BaseObject<any>>;
        byId(
            id:
                | string
                | Record
                | FormEntry
                | Bluestep.Relate.Entry
                | Id<Bluestep.Relate.Entry>
                | Id<FormEntry>
                | Id<Record>,
        ): E;
        children(classType?: string | number): EList<BaseObject<any>>;
        clear(): void;
        clearSearchAndSort(): boolean;
        contains(o: any): boolean;
        containsAll(c: Collection<any>): boolean;
        created(): Instant;
        creator(): User;
        currentUnit(
            identifier:
                | string
                | Id<any>
                | Unit
                | FormEntry
                | Bluestep.Relate.Entry
                | BaseRecord<any>,
        ): boolean;
        currentUnit(): Unit;
        deletedChildren(): EList<BaseObject<any>>;
        deleteUrl(): string;
        displayName(): string;
        displayName(name: string): void;
        each(action: (e: E, index?: number, elist?: EList<E>) => void): void;
        editUrl(): string;
        forEach(action: Consumer<E>): void;
        forEach(
            callbackfn: (value: E, index: number, array: E[]) => void,
            thisArg?: any,
        ): void;
        get(index: number): E;
        getAncestors(): EList<BaseObject<any>>;
        getAnchorTimestamp(): number;
        hashCode(): number;
        id(): Id<Query<E>>;
        indexOf(o: any): number;
        indexOf(searchElement: E, fromIndex?: number): number;
        isEmpty(): boolean;
        isLocked(): boolean;
        isPendingLock(): boolean;
        isPendingUnLock(): boolean;
        iterator(): Iterator<E>;
        listIterator(): ListIterator<E>;
        listIterator(index: number): ListIterator<E>;
        localCache(): LocalCache;
        lock(): Lock;
        maxRows(): number;
        maxRows(newValue: number): void;
        meetsCriteria(
            id:
                | string
                | Record
                | FormEntry
                | Bluestep.Relate.Entry
                | Id<Bluestep.Relate.Entry>
                | Id<FormEntry>
                | Id<Record>,
        ): boolean;
        meetsCriteriaResults(
            id:
                | string
                | Record
                | FormEntry
                | Bluestep.Relate.Entry
                | Id<Bluestep.Relate.Entry>
                | Id<FormEntry>
                | Id<Record>,
        ): { message: string; success: boolean };
        metaData(): QueryMetaData;
        modified(): Instant;
        modifier(): User;
        newEntries(): EList<E>;
        newRecord(): E;
        optAncestor(classType: string | number): Optional<BaseObject<any>>;
        optById(
            id:
                | string
                | Record
                | FormEntry
                | Bluestep.Relate.Entry
                | Id<Bluestep.Relate.Entry>
                | Id<FormEntry>
                | Id<Record>,
        ): Optional<E>;
        optLock(): Optional<Lock>;
        optParent(classType?: string | number): Optional<BaseObject<any>>;
        parent<B extends BaseObject<B>>(classType?: string | number): B;
        peekSearches(): EList<Search>;
        peekSorts(): EList<Sort>;
        rememberSearchAndSort(): boolean;
        remove(index: null): boolean;
        remove(o: any): boolean;
        removeAll(c: Collection<any>): boolean;
        removeIf(filter: Predicate<E>): boolean;
        replaceAll(operator: UnaryOperator<E>): void;
        reset(): void;
        resetUnit(): boolean;
        retainAll(c: Collection<any>): boolean;
        searchResultsEntriesId(): Id<any>;
        set(index: number, element: E): E;
        size(): number;
        subList(fromIndex: number, toIndex: number): List<E>;
        toArray(): any[];
        toArray<T>(a: T[]): T[];
        topId(): AltId<Query<E>> | Id<Query<E>>;
        typeName(): string;
        update(): void;
        variableName(): string;
        version(): string;
        versions(): EList<BaseObject<Query<E>>>;
        viewUrl(): string;
        [n: number]: E;
    }

    Type Parameters

    Hierarchy (View Summary)

    Indexable

    • [n: number]: E
    Index

    Methods

    • Parameters

      Returns boolean

    • Parameters

      • index: number
      • e: E

      Returns boolean

    • Parameters

      Returns boolean

    • Parameters

      Returns boolean

    • Adds a search to the current list of records. Search criteria are in addition to, not in lieu of, any search criteria specified in a [[Query]] or Report. The behavior of adding multiple search criteria is equivalent to chaining conditions together with &&. Throws an exception if an error occurs. Return itself for easy chaining.

      TODO: make a page on Searching showing all the operators on the field types.

      Parameters

      • formId: string

        The variable name you have assigned to the form via [[FormMetaData.require]].

      • field: string

        The [[FieldMetaData.formulaId]] of the field you want to search on.

      • operator: string

        The search operator, such as =, <, >=, etc.

      • value: any

        The value to apply to the field with the operator.

      Returns this

      TODO
      
    • Adds a search to the current list of records. Search criteria are in addition to, not in lieu of, any search criteria specified in a [[Query]] or Report. The behavior of adding multiple search criteria is equivalent to chaining conditions together with &&. Throws an exception if an error occurs. Return itself for easy chaining.

      TODO: make a page on Searching showing all the operators on the field types.

      Parameters

      • fieldMetaData: FieldMetaData<any>
      • operator: string

        The search operator, such as =, <, >=, etc.

      • value: any

        The value to apply to the field with the operator.

      Returns this

      TODO
      
    • Adds a sort to the current list of records. Sort criteria override any sort settings specified in the query or report, but they do not override any grouping settings, which also have the effect of sorting the records. In other words, it will sort within the groups.

      If multiple sorts are added it will search first by the first sort specified, and next by subsequent sort criteria. A maximum of three levels of sorting are allowed, including sorting caused by grouping. Throws an exception with the error message. Return itself for easy chaining.

      Parameters

      • formId: string

        The variable name you have assigned to the form via [[FormMetaData.require]].

      • field: string

        The [[FieldMetaData.formulaId]] of the field you want to search on.

      • OptionalsortDirection: SortDirection

        Default is [[SortDirection.DESCENDING_NULLS_FIRST]]. Ascending vs descending, and nulls first vs last.

      Returns this

      someQuery.addSort('someField', B.db.SortDirection.DESCENDING_NULLS_LAST);// or, using deconstructors this can be cleaner if you need to do many within the same script.const {db: {SortDirection: {DESCENDING_NULLS_LAST}}} = BsomeQuery.addSort('someField', DESCENDING_NULLS_LAST);
      
    • Adds a sort to the current list of records. Sort criteria override any sort settings specified in the query or report, but they do not override any grouping settings, which also have the effect of sorting the records. In other words, it will sort within the groups.

      If multiple sorts are added it will search first by the first sort specified, and next by subsequent sort criteria. A maximum of three levels of sorting are allowed, including sorting caused by grouping. Throws an exception with the error message. Return itself for easy chaining.

      Parameters

      • fieldMetaData: FieldMetaData<any>
      • OptionalsortDirection: SortDirection

        Default is [[SortDirection.DESCENDING_NULLS_FIRST]]. Ascending vs descending, and nulls first vs last.

      Returns this

      someQuery.addSort('someField', B.db.SortDirection.DESCENDING_NULLS_LAST);// or, using deconstructors this can be cleaner if you need to do many within the same script.const {db: {SortDirection: {DESCENDING_NULLS_LAST}}} = BsomeQuery.addSort('someField', DESCENDING_NULLS_LAST);
      
    • An object of alternate ids for this object, with values as [[AltId]]

      Returns { [name: string]: AltId<Query<E>> }

      // 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

      Returns { [name: string]: string }

      // 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';
    • An array of alternate ids for this object.

      Returns EList<Query<E>>

      // 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)

      Type Parameters

      Parameters

      • classType: string | number

      Returns B

    • For [[Query]]s and reports with search criteria based on the current date/time, causes the query/report to run as though the current date/time was timestamp. This can be used to view the results of the query/report as they would have looked in the past or as they will look in the future, assuming today's data.

      Returns the prior anchor value.

      Parameters

      • time: number | Instant

        The anchor time in millisSinceEpoch.

      Returns number

      TODO
      
    • 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]].

      Returns EList<BaseObject<any>>

      const ids = obj.asArray().map(ob => ob);
      
    • Retrieves a [[Record]], given the [[Id]] of one of the entries within the record. This method will not return a [[Record]] which is not a part of the [[Query]]/report result (before any custom searching). It's useful when you have an [[Id]] of something from another source, such as a params field or the 'current' [[Record]] or from another [[Query]], and you want to find the same [[Record]] in a different [[Query]] with different [[Form]]s available. If a short id string is passed,it needs to be of type [[Entry]]. Same as calling optById(id).orElse(null).

      Parameters

      Returns E

      const entryId = someEntry.id().shortId();
      const record = someQuery.byId(entryId);
    • Get the children of the object. This retrieval goes one level deep.

      Parameters

      • OptionalclassType: string | number

      Returns EList<BaseObject<any>>

      const childrenNames = obj.children().map(child => child.displayName());
      
    • Returns void

    • Clears any [[addSearch]], [[addSort]], and [[anchorTimestampSearch]] criteria which may have been previously set. Returns true if search or sort parameters were actually cleared by the function. Returns false if the function did not have any settings to clear.

      Returns boolean

      // check if there are any search criteria
      const hasSearch = query.clearSearchAndSort();
      hasSearch && console.log(`Nice, we did have some searches! Now I just have to... I just cleared all my searches, didn't I?`);
    • Parameters

      • o: any

      Returns boolean

    • Parameters

      Returns boolean

    • The "created at" timestamp of this object.

      Returns Instant

      const createdAt = `<div class="created-at">${baseObject.created()}</div>`;
      
    • The creator of this object.

      Returns User

      alert(`Guess who created this. It was ${baseObject.creator().fullName()}. They are to blame.`);
      
    • Sets the [[Unit]] in which the [[Query]] will run. This can also effect the location where new [[Record]]s are created. If [[rememberSearchAndSort]] is used, the current [[Unit]] will also be remembered. However, using [[clearSearchAndSort]] does not reset the unit. Return true if the passed in unit is different than the current unit.

      Parameters

      Returns boolean

      TODO
      
    • Returns the current Unit used by the query.

      Returns Unit

      TODO
      
    • 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.

      Returns EList<BaseObject<any>>

      const deleted = baseObject.deletedChildren();
      
    • Returns a delete URL for this object, else a blank string. Following the URL will delete the object, so proceed with caution.

      Returns string

      const deleteBtn = `<button data-href="${baseObject.deleteUrl()}">Go to ${baseObject.displayName()}</button>;
      
    • 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.

      Returns string

      The following assumes you have already aggregated a selection of baseObjects 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.

      Parameters

      • name: string

      Returns void

    • Same as Javascripts forEach method.

      Parameters

      • action: (e: E, index?: number, elist?: EList<E>) => void

      Returns void

    • Returns an edit URL for this object, else a blank string.

      Returns string

      const editBtn = `<button data-href="${baseObject.editUrl()}">Go to ${baseObject}</button>`;
      
    • Parameters

      Returns void

    • Performs the specified action for each element in an array.

      Parameters

      • callbackfn: (value: E, index: number, array: E[]) => void

        A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

      Returns void

    • Parameters

      • index: number

      Returns E

    • Gets an array of all the object's ancestors.

      Returns EList<BaseObject<any>>

      const numberOfAncestors = obj.getAncestors().length;
      
    • Get the current timestamp anchor, if any.

      Returns number

      const hasAnchor = !!query.getAnchorTimestamp();
      
    • Returns number

    • The [[Id]] of this object bounded to T.

      Returns Id<Query<E>>


      const displayDiv = `<div class="object-card" id="${baseObject.id()}">
      <div class="title">${baseObject}</div>
      <div class="body">Hello World!</div>
      </div>;
    • Parameters

      • o: any

      Returns number

    • Returns the index of the first occurrence of a value in an array, or -1 if it is not present.

      Parameters

      • searchElement: E

        The value to locate in the array.

      • OptionalfromIndex: number

        The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

      Returns number

    • Returns boolean

    • Returns whether the object is locked or not.

      Returns boolean

      Part of the [[Lock]] API.

      const isLocked = baseObject.isLocked();
      
    • Returns whether the object is pending a lock or not.

      Returns boolean

      Part of the [[Lock]] API.

      const isPendingLock = baseObject.isPendingLock();
      
    • Returns whether the object is pending an unlock or not.

      Returns boolean

      Part of the [[Lock]] API.

      const lockPendingUnlock = baseObject.isPendingUnLock();
      
    • Returns Iterator<E>

    • Returns ListIterator<E>

    • Parameters

      • index: number

      Returns ListIterator<E>

    • Returns the Local Cache object for this Thread/Base Object.

      Returns LocalCache

    • Same as calling optLock().orElse(null)

      Returns Lock

    • Retrives the maximum number of rows that will be returned from the [[Query]] or -1 for all rows.

      Returns number

      // set the maxRows if more than 1000
      const maxRows = query.maxRows();
      maxRows > 1000 || maxRows === -1 && query.maxRows(1000);
    • Sets the maximum number of rows that will be returned from the [[Query]]. Will over-write what is currently set in the query settings. Passing "-1" into the function will return all rows.

      Parameters

      • newValue: number

      Returns void

      // set the maxRows if more than 1000
      const maxRows = query.maxRows();
      maxRows > 1000 || maxRows === -1 && query.maxRows(1000);
    • Checks if passed in object has compatible categories and units for the [[Query]]. If you call this methd and it returns false, then byId(val) or optById(val) will thrown an exception. Same as calling `meetsCriteriaResults(param).success

      Parameters

      Returns boolean

      TODO
      
    • Checks if passed in object has compatible categories and units for the [{Query]]. Returns a results object. If results.success is false the results.message will contain a message of why.

      Parameters

      Returns { message: string; success: boolean }

      TODO
      
    • Returns the [[QueryMetaData]] object that this entry belongs to.

      Returns QueryMetaData

      const queryAltIds = curEntry.metaData().altIds();
      
      explore example
      [[QueryMetaData.altIds]]
    • The modified date of this object.

      Returns Instant

      const isModified = baseObject.modified();
      
    • The [[User]] that last modified this object.

      Returns User

      const modifierName = baseObject.modifier().fullName();
      
    • Array of new [[Record]]s created by calling [[newRecord]].

      Returns EList<E>

      TODO
      
    • Results in a new [[Record]] matching the record type and "Must Have" record category settings of the [[Query]]/report. The new record will be in the unit where the [[Query]]/report runs. If the [[Query]]/report includes [[Record]]s from multiple record types or there are no writable [[Form]]s available to populate data into the new record an Error will be thrown.

      Returns E

       // make a new person (not the traditional way)
      // this example is incorrect. don't know how to fix it yet.
      B.queries.byFID['allPeople'].require();
      const makeNewPerson = (name, dob) => {
      const newPerson = allPeople.getObject().newRecord();
      const nameFields = newPerson.forms.byFID['name'].formMetaData();
      const {firstName,
      lastName,
      birthDate} = nameFields.formMetaData().fields.byFormulaId;
      const nameSplit = name.split(' ');
      firstName.val(nameSplit[0]);
      lastName.val(nameSplit[1]);
      birthDate.val(dob);
      }
      const newPeople = [['Lari Pamona', '04/08/1997'],['Kandace Knudsen','11/19/1992'],['Buck Ahlers','2/22/92']];
      for (const person in newPeople) makeNewPerson(person[0], person[1]);
      explore example
      [[B.queries]], [[BaseObjectLookup.byFID]], [[QueryMetaData.require]], [[QueryMetaData.forms]], [[FormMetaData.require]]
    • A [[Java.Optional]] of the ancestor with the specific class.

      Parameters

      • classType: string | number

      Returns Optional<BaseObject<any>>

      const ancestors = obj.optAncestor(1000001).ifPresent(a => console.log('${a} exists'));
      
      explore example
      [[Java.Optional.ifPresent]]
    • Retrieves a optional [[Record]], given the [[Id]] of one of the entries within the record. This method will not return a [[Record]] which is not a part of the [[Query]]/report result (before any custom searching). It's useful when you have an [[Id]] of something from another source, such as a params field or the 'current' [[Record]] or from another [[Query]], and you want to find the same [[Record]] in a different [[Query]] with different [[Form]]s available. If a short id string is passed,it needs to be of type [[Entry]]. If you pass a null or string is blank, then this will return an empty Optional

      Parameters

      Returns Optional<E>

      const {util: {newRuntimeException: err}} = B;
      const identifier1 = someEntry1.id().shortId();
      const identifier2 = someEntry2.id().shortId();
      const identifier3 = someEntry3.id().shortId();
      try {
      someQuery.optById(identifier1).orElseThrow(err('could not find by identifier1: ' + identifier1));
      someQuery.optById(identifier1).orElseThrow(err('could not find by identifier2: ' + identifier2));
      someQuery.optById(identifier1).orElseThrow(err('could not find by identifier3: ' + identifier3));
      } catch (error) {
      console.error('Could not find record! Error: ' + error);
      }
      const identifier = someEntry.id().shortId();
      someQuery.optById(identifier)
      .map(record => record.forms.someForm)
      .map(form => form.fields.someField)
      .flatMap(field => field.opt())
      .ifPresentOrElse(
      entry => console.log('Record is: ' + entry),
      () => console.error('Could not find field value for this identifier: ' + identifier)
      );
    • Returns the [[Lock]]

      Returns Optional<Lock>

      Part of the [[Lock]] API.

      const lockExpire = baseObject.optLock();
      
    • A [[Java.Optional]] of the current object's parent object.

      Parameters

      • OptionalclassType: string | number

      Returns Optional<BaseObject<any>>

      const ancestors = obj.optAncestor(1000001).ifPresent(a => console.log('${a} found'));
      
      explore example
      [[Java.Optional.ifPresent]]
    • Same as calling optParent(var).orElse(null)

      Type Parameters

      Parameters

      • OptionalclassType: string | number

      Returns B

    • Get any search parameters that have been added by [[addSearch]].

      Returns EList<Search>

    • Get any sort parameters that have been added by [[addSort]].

      Returns EList<Sort>

    • This function causes any current, or future, search and/or sort critieria to be remembered and used when displaying data. Will not work if the function has already been called. Call [[clearSearchAndSort]] to make rememberSearchAndSort available again.Returns a boolean value indicating whether calling the function had an effect.

      Returns boolean

      // search a query twice with different params
      query.addSearch('appointments','selectedDay','=','MONDAY');
      query.rememberSearchAndSort();
      const monAppts = query.metaData().forms.appointments.map(a => a.current());
      query.clearSearchAndSort();
      query.addSearch('appointments','selectedDay','=','FRIDAY');
      query.rememberSearchAndSort();
      const friAppts = query.metaData().forms.appointments.map(a => a.current());
      // yeah, there's no way this example is correct
    • Parameters

      • index: null

      Returns boolean

    • Parameters

      • o: any

      Returns boolean

    • Parameters

      Returns boolean

    • Parameters

      Returns boolean

    • Parameters

      Returns void

    • Sets the results of the [[Query]] to null, i.e. clears all the [[Record]]s from the results.

      Returns void

    • Reset of the unit back to query default. Returns false if the unit is already in a reset state.

      Returns boolean

      TODO
      
    • Parameters

      Returns boolean

    • Returns the id used to do the search. It contains the search, sort, unit, and maxRows currently specified in this Query Object.

      Returns Id<any>

    • Parameters

      • index: number
      • element: E

      Returns E

    • Returns number

    • Parameters

      • fromIndex: number
      • toIndex: number

      Returns List<E>

    • Returns any[]

    • Type Parameters

      • T

      Parameters

      • a: T[]

      Returns T[]

    • The [[Id]] or [[AltId]] that the system deems most relevant.

      Returns AltId<Query<E>> | Id<Query<E>>


      const displayDiv = `<div class="object-card" id="${baseObject.topId()}">
      <div class="title">${baseObject}</div>
      <div class="body">Hello World!</div>
      </div>;
    • Returns the bluestep.js classpath for the current object.

      Returns string

      const isBool = testForm.fields.mysteryField.typeName().toLowerCase().includes('boolean')
      
    • Makes changes to the database for this object

      Returns void

    • Name of variable.

      Returns string

    • The version of this object or empty string if it doesn't exist.

      Returns string

      const version = baseObject.version();
      
    • 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.

      Returns string

      const viewBtn = `<button data-href="${baseObject.viewUrl()}">Go to ${baseObject.displayName()}</button>;