Skip to content

SystemQueryOptions

Niels Steenbeek edited this page Mar 24, 2020 · 4 revisions

SystemQueryOptions interface

The SystemQueryOptions interface wraps the complex, hard to read and hard to write $select and $expand.

Select

The select is an array of Entity field names. When the field name is a lookup, the code will automatically rewrite to: _fieldname_value.

Expands

The expand is an array of NavigationPropertyNames. Those are a little bit hard to find. Most times they are equal to the Schema Name and otherwise use /api/data/v9.1/$metadata to find the matching . A nested expand is not possible due to D365 restriction.

interface Expand {
    attribute: string;
    select: string[];
}
export interface SystemQueryOptions {
    select: string[];
    expands?: Expand[];
}

Example select

const entity = formContext.data.entity,
      id = entity.getId(),
      options: SystemQueryOptions = {
          select: ['name']
      },
      account = await AccountService.retrieveRecord(id, options);
console.log(account.name);

Example expand

const entity = formContext.data.entity,
      id = entity.getId(),
      options: SystemQueryOptions = {
          select: ['name'],
          expands: [{
              attribute: 'owninguser',
              select: ['firstname']
          }]
      },
      account = await AccountService.retrieveRecord(id, options);
console.log(account.owninguser.firstname);
Clone this wiki locally