Class RestCustomScripting

This class contains methods for calling the Generic REST Service with custom scripting.

Hierarchy

  • CslBase
    • RestCustomScripting

Properties

componentId: string = ''

The component id of the current view instance.

Accessors

  • get componentConfig(): Component
  • The configuration of the component to render.

    Returns Component

  • get htmlElement(): any
  • The rendered HTML of the view.

    Returns any

  • get viewConfig(): UpdateView | MultiRecordView | SingleRecordView | CreateView
  • The configuration of the view to render.

    Returns UpdateView | MultiRecordView | SingleRecordView | CreateView

  • get viewFields(): ViewField[]
  • The viewFields of the view.

    Returns ViewField[]

Methods

  • Executes a method.

    // Example when executing a method with no input fields.
    CSL.rest.executeMethod('Product', 'Get All Products', 'Training SQL')
    .then(methodResults => {
    // `methodResults` is an array because you are able to send more than one context record.
    methodResults.forEach(methodResult => {
    if (methodResult.hasError) {
    alert(methodResult.error);
    } else {
    methodResult.results.forEach(result => {
    // A single record in a method execution.
    console.log(result);
    });
    }
    });
    }).catch(err => {
    // Network related error or any 500 error response code from the API.
    alert(err);
    });

    // Example where the page size is set. Only items 1 to 25 are retrieved.
    const queryOptions = {
    FirstItem: 1,
    PageSize: 25
    }
    CSL.rest.executeMethod('Product', 'Get All Products', 'Training SQL', null, queryOptions)
    .then(methodResults => {
    console.log(methodResults[0].results.length); // output 25
    })
    .catch(err => { console.error(err); });

    Throws

    ApiError Any network related error or any 500 error response code from the API.

    Parameters

    • objectName: string

      The name of the object.

    • methodName: string

      The name of the method.

    • profileName: string

      The name of the profile.

    • contextRecords: ValueObject<string>[] = ...

      The context records that will be used as input for the method.

    • Optional queryOptions: QueryOptions

      Options for altering the query results. Limit results, skip items,...

    Returns Promise<MethodResult[]>

  • Get filter values of a view.

    // Filter based on product names that contain 'a' and the stock is meer dan 100.
    const expression = {
    filters: [{
    field: 'productName',
    operator: 'ct',
    value: 'a'
    }, {
    field: 'productStock',
    operator: 'gt',
    value: '100'
    }],
    logic: 'and'
    };

    const context = [{productName: 'a'}];

    CSL.rest.getFilterValues('Product', 'Get All Products', 'productName', context, { Expression: expression }).then((results) => {
    let stocks = results.map(option => option.data['productStock']);
    });

    Parameters

    • objectName: string

      The name of the object.

    • viewName: string

      The name of the view.

    • viewFieldName: string

      The name of the field you want to filter.

    • contextRecords: ValueObject<string | number>[] = ...

      The records to use as context.

    • queryOptions: QueryOptions

      The options to send with the call.

    Returns Promise<FilterOptionsListItem[]>

  • Executes the prepare call for a view.

    CSL.rest.prepareView('Product', 'Get All Products', [{productName: 'ABC'}]).then((result) => {
    // Prepare result
    });

    Parameters

    • objectName: string

      The name of the object.

    • viewName: string

      The name of the view.

    • contextRecords: ValueObject<string | number>[] = ...

      The context records to use as context in the call.

    Returns Promise<PreparedChart<BaseChart<ChartOptions>, ExecutedChart> | PreparedAdmResponse | PreparedCmResponse | [PreparedAdmResponse] | [PreparedCmResponse] | [PreparedChart<BaseChart<ChartOptions>, ExecutedChart>]>

  • Validates if the values exist.

    const valuesToValidate = [
    { fieldName: 'productName', values: ['AB', 'CD'] },
    { fieldName: 'productCategoryId', values: [7] }
    ];

    const customContext = [ {userName: 'John'} ]

    CSL.rest.validateValue('Product', 'Insert Product', valuesToValidate, customContext).then((results) => {
    // Check if all results are valid.
    const allValid = (results.find((r) => r.isValid) !== undefined);
    });

    Parameters

    • objectName: string

      The name of the object.

    • viewName: string

      The name of the view.

    • valuesToValidate: FieldValuesToValidate[]

      The values that will be validated.

    • contextRecords: ValueObject<string | number>[] = ...

      The context to send with the call.

    Returns Promise<DataSourceValidationResult[]>

Generated using TypeDoc