Search Results for

    Show / Hide Table of Contents

    LookupAttribute

    An Attribute for a lookup field. Also has all the methods available in Attribute.

    Use form.attribute to get an instance of this class.

    getLookupValue

    attribute.getLookupValue(): RecordReference | null;
    

    Gets the first value for the lookup in RecordReference format.

    getLookupValueList

    attribute.getLookupValueList(): RecordReference[];
    

    Returns an array of lookup values for the field. If the field is null, an empty array is returned.

    getValueId

    attribute.getValueId(): string | null
    

    Gets the id value of the field.

    getValueEntityName

    attribute.getValueEntityName(): string | null
    

    Gets the entityType value of the field.

    getValueName

    attribute.getValueName(): string | null
    

    Gets the primary name attribute value of the target entity.

    setSingleValue

    attribute.setSingleValue(val: RecordReference | null): void;
    attribute.setSingleValue(id: string | null, logicalName: string, name: string): void;
    

    Sets the lookup field to the single specified value.

    addPreSearchFilter

    attribute.addPreSearchFilter(presearchCallback: () => string | null): void
    

    Call this method in the form on load event to register a callback to filter the lookup.

    ⚠️ This method does not allow link-entity based filters. For those, use addPreSearchCustomViewFilter and disable the view selector.

    function formOnLoad_addPreSearchFilterSample(e) {
        const form = Hsl.form(e);
        const accountLookup = form.attribute('hsl_accountid');
        accountLookup.addPreSearchFilter(() => {
            const projectType = form.attribute('hsl_projecttypecode').getValue();
            if (projectType === null)
                return null; // No filter
            return `<filter><condition attribute='hsl_projecttypecode' operator='eq' value='${Hsl.xmlEncode(projectType)}' /></filter>`;
        });
    }
    

    addPreSearchCustomViewFilter

    attribute.addPreSearchCustomViewFilter(presearchCallback: () => string | null, options?: CustomViewFilterOptions)
    

    This will be called anytime the user opens the lookup control to select a record. If you want the user to be restricted to only records in the view, go to the properties for the controls for this attribute in this form editor and select:

    • Set View Selector = Off
    • Disable most recently used items for this field = Checked
    function formOnLoad_addPreSearchCustomViewFilter(e) {
        const form = Hsl.form(e);
        const accountLookup = form.attribute('hsl_accountid');
        accountLookup.addPreSearchCustomViewFilter(() => {
            return `<link-entity name="territory" from="territoryid" to="territoryid" link-type="inner" alias="territory">
        <link-entity name="systemuser" from="systemuserid" to="managerid" link-type="inner" alias="territorymanager">
        <filter type="and">
            <condition attribute="businessunitid" operator="eq-businessid" />
        </filter>
        </link-entity>
    </link-entity>`;
        });
    }
    

    addCustomView

    attribute.addCustomView(viewId: Guid,
                entityName: string,
                viewDisplayName: string,
                fetchXml: string,
                layoutXml: string,
                makeDefault: boolean): void
    

    Adds a custom view for each control for this attribute.

    addDependency

    attribute.addDependency(_opts: AddDependencyOptions)
    
    interface AddDependencyOptions {
        /** The attributes this filter depends on */
        dependOnAttributes: string[];
        /** Callback function made when the user opens a lookup control. Should return filter xml filtering the attribute. */
        fetchFilterCallback(): string | null;
        /** Automatically set this attribute to null if one of the dependsOnAttributes changes. Default: true */
        clearOnDependencyChange?: boolean;
        /** Whether to disable this attribute if any of the dependsOnAttributes is null. Default: true */
        disableOnNullDependency?: boolean;
    }
    

    Adds a view filter dependent on particular attributes.

    function formOnLoad_addLookupDependencySample(e) {
        const form = Hsl.form(e);
        const accountLookup = form.attribute('hsl_accountid');
        accountLookup.addDependency({
            dependOnAttributes: ['hsl_projecttypecode'],
            fetchFilterCallback() {
                const projectType = form.attribute('hsl_projecttypecode').getValue();
                if (projectType === null) {
                    return `<filter><condition attribute='hsl_projecttypecode' operator='null' /></filter>`;
                }
                return `<filter><condition attribute='hsl_projecttypecode' operator='eq' value='${Hsl.xmlEncode(projectType)}' /></filter>`;
            },
            disableOnNullDependency: false,
        });
    }
    
    In This Article
    Back to top Hitachi Solutions JS Library