Hsl.Dialog.lookup
Shows a dialog to the user prompting them to select a record of the specified type.
Hsl.Dialog.lookup(settings: LookupDialogSettings): Promise<LookupResult>;
interface LookupResult {
/** Indicates that the user cancelled out of the dialog instead of selecting a result. */
cancelled: boolean;
/** The record(s) selected by the user. */
records: RecordReference[];
}
interface LookupDialogSettings {
/** Logical name of the entity this lookup will select. Shortcut for
* targets with a single item in the array. Specify either this
* or targets. */
target?: string;
/** Array of logical names of the entities this lookup can select.
* Specify either this or target. */
targets?: ReadonlyArray<string>;
/** Default: first value specified in targets. Logical name of entity that
* should be selected when the lookup opens. */
defaultTarget?: string;
/** Default: true. Whether to show the New button. */
showNewButton?: boolean;
/** Default: true. Whether to show the Properties button. */
showPropButton?: boolean;
/** Default: false. Whether to disable the view picker. */
disableViewPicker?: boolean;
/** Default: false. Whether to disable quick find. */
disableQuickFind?: boolean;
/** Default: null. The id of the view which should be selected by default. */
defaultViewId?: string | Guid;
/** Default: false. Whether to allow selecting of multiple records. */
lookupMultiple?: boolean;
/** Default: false. If true, search and view selector are hidden. */
browse?: boolean;
/** Default: null. When the New button is used to create a new record, values from
* this record are mapped to the new record as defined by the relationship's mappings. */
parentEntity?: EntityReference;
/** Default: null. Fetch XML string of the form "<filter>...</filter>" that filters
* the records available for selection to ones that match the filter. */
additionalFilterXml?: string;
/** Default: null. Array of custom view definitions which will be
* available in the dialog. */
customViews?: ReadonlyArray<LookupCustomView>;
/** Default: []. Array of existing items that should be preselected when
* the dialog opens. Only applies when lookupMultiple is true. */
existingItems?: ReadonlyArray<EntityReference>;
/** Default: null. Text that should appear in the search box when the dialog opens. */
searchText?: string;
/** Default: null. This value no longer seems to be used by CRM's lookup
* dialog and will likely be removed from the next version of the library. */
contextEntity?: {
id: string;
logicalName: string;
};
/** Additional fields to return in the select list. These can be accessed in the response using the field names.
* For example `Hsl.Dialog.lookup({ target: 'contact', select: ['emailaddress1'] }).then(resp => console.log(resp.records[0].name + ': ' + resp.records[0].emailaddress1))`
* This setting requires Eff Grid at least 8.4.0. */
select?: readonly string[];
}
interface LookupCustomView {
/** Default: Hsl.Guid.getNew(). Any valid guid. Use this setting with defaultViewId. */
id?: string | Guid;
/** Default: "Filtered Lookup View". The name of the view that will appear in the
* view selector dropdown. */
name?: string;
/** Id of a view to fetch from CRM which will provide starting values for fetchXml
* and layoutXml. */
baseViewId?: string | Guid;
/** Use with baseViewId. The filter xml specified is appended to the existing fetch
* query for the view. */
additionalFilterXml?: string;
/** Default: value of defaultTarget from settings object. The logical name of the
* entity this view targets. If targets options from settings object specifies
* multiple entities, this value is required. */
recordType?: string;
/** The fetch XML query for the view. Advanced Find or third-party tools can be
* used to generate this value. If baseViewId is not set, this value is required.
* If baseViewId is set, this value overrides that which came from baseViewId. */
fetchXml?: string;
/** The layout XML definition for the view. If baseViewId is not set, this value is
* required. If baseViewId is set, this value overrides that which came from baseViewId. */
layoutXml?: string;
/** Specify any options available with the Effective Grid's ViewSelector options. */
effGridOptions?: any;
}
async function lookupSample() {
var _a, _b;
const result = await Hsl.Dialog.lookup({
target: 'account',
showNewButton: false,
select: ['creditonhold', 'primarycontactid']
});
if (result.cancelled)
return;
const record = result.records[0];
const id = record.id;
const name = record.name;
const creditOnHold = record.creditonhold;
const primaryContactId = (_a = record.primarycontactid) === null || _a === void 0 ? void 0 : _a.Id;
const primaryContactName = (_b = record.primarycontactid) === null || _b === void 0 ? void 0 : _b.Name;
const client = Hsl.WebApi.getClient('9.1');
return client.update(result.records[0], {
statecode: 1,
});
}