Defines a reference to a particular record.
WebApiReference
typescript type WebApiReference = PrimaryIdReference | AlternateKeyReference
APIs accepting a WebApiReference can be passed either a PrimaryIdReference or AlternateKeyReference
PrimaryIdReference
A reference to a record based on the record's primary id.
export interface PrimaryIdReference {
entityType: string;
id: Guid;
}
var myReference = {
entityType: 'account',
id: '964b10a5-4a45-4fb6-baa9-c1b93fc1773f',
};
AlternateKeyReference
A refrence to a record based an alternate key.
Microsoft's Documentation on Alternate Keys
export interface AlternateKeyReference {
entityType: string;
[altKey: string]: number | string | LiteralKeyValue;
}
interface LiteralKeyValue {
literal: string;
}
- Strings and numeric data types can be specified using the string or numeric value as you'd probably expect.
- Alternate keys composed of lookups need to use _ATTRIBUTENAME_value as the key and the guid as the value.
- Date and Date/Time need to use { literal: encodedDateValue }.
function stringAlternateKey() {
const client = Hsl.WebApi.getClient('9.1');
client.retrieve({
entityType: 'account',
accountnumber: '2018421',
}, ['hsl_name']);
}
function numericAlternateKeys() {
const client = Hsl.WebApi.getClient('9.1');
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
hsl_decimal: 4.22,
hsl_wholenumber: 7120,
hsl_picklist: 296010004,
}, ['hsl_name']);
}
function lookupAlternateKeys() {
const client = Hsl.WebApi.getClient('9.1');
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
_hsl_accountid_value: Hsl.WebApi.encodeGuid('3157fbae-742c-6c4e-c295-ae93ed5a5bc1'),
_hsl_projectiontype_value: Hsl.WebApi.encodeGuid('f4a47d91-5c16-a143-768d-a0825a754a2b'),
}, ['hsl_name']);
}
// { literal } notation is needed for date or date/time alternate keys
function dateAlternateKeys() {
const client = Hsl.WebApi.getClient('9.1');
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
hsl_dateonly: { literal: '2020-01-05' },
}, ['hsl_name']);
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
hsl_dateonly: { literal: Hsl.WebApi.encodeDateOnly(new Date(2020, 5, 3)) },
}, ['hsl_name']);
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
hsl_datetimeuserlocal: { literal: '2020-05-02T10:00:00Z' },
}, ['hsl_name']);
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
hsl_datetimeuserlocal: { literal: new Date(2020, 4, 2, 6).toISOString() },
}, ['hsl_name']);
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
hsl_datetimetzi: { literal: '2020-05-02T10:30:00-00:00' },
}, ['hsl_name']);
client.retrieve({
entityType: 'hsl_testalternatekeyentity',
hsl_datetimetzi: { literal: Hsl.WebApi.encodeTziDateTime(new Date(2020, 5, 3, 3, 10)) },
}, ['hsl_name']);
}
function lookupAndDateAltKey() {
const client = Hsl.WebApi.getClient('9.1');
client.retrieve({
entityType: 'hsl_accountdailylog',
_hsl_accountid_value: '2ecb5f87-88ce-a04c-c6a8-34f72384f682',
hsl_date: { literal: Hsl.WebApi.encodeDateOnly(new Date(2020, 2, 15)) },
}, ['hsl_logvalue']);
}