The API Class. An instance is available via the global API.v1 variable.

//== You don't need to instantiate the API yourself, you can use:
API.v1.launchActivity();
API.v1.postActivity();
API.v1.getDataset();
API.v1.getForm();
API.v1.getReference();
API.v1.getTemplate();

Methods

  • Post activities in bulk. Can be as simple as one activity on one casetype or as complex as multiple activities over multiple cases of different casetypes.

    Parameters

    • activities: object[]

      Array of activity objects

    • OptionalreturnResult: boolean

      return the result (e.g. resultForm and/or createdCase)

    • OptionalcommitBetweenTasks: boolean

      when set to true, no rollback will be performed on earlier activities in this transaction

    Returns Promise<unknown>

    //== Simple 1 activity on current case with 2 fields
    API.v1.bulkPostActivity([{
    activity: {
    activityId: '1:4581:10033'
    },
    'case': {
    cases: [API.v1.info.getGlobalCaseId()]
    },
    fields: [{
    externalReference: 'start',
    value: new Date()
    }, {
    externalReference: 'title',
    value: 'Subject'
    }
    ]
    }
    ], false, false)
    .then(function(result) {console.info('BulkPost Completed OK', result);})
    .catch(function(error) {console.error('BulkPost Completed ERROR', error);})

    //== Activity JSON options
    {
    "activity": {
    "activityId": "1:6679:1"
    //no problem if the activity was not found, perhaps form a different casetype
    },
    "case": {
    "cases": ["1:6685:2", "1:6685:5"]
    },
    "fields": [{
    //no problem if the formfield was not found - it could be the formfield for a different casetype
    //note that the formfield should be unique for a given activity
    "id": "1:6679:1", //formfield / casetype-attribute / platform-attribute - id / src / origin /
    knownid
    "value": "value 1"
    }, {
    "externalReference": "someReference", //external reference
    "value": "value 2"
    }
    ]
    }, {
    "activity": {
    "tag": "tag123"
    },
    "case": {
    "attributeId": "1:6679:1" //the attribute value of the case of the request meta
    //an error is given if the attribute was not found on this case
    },
    "fields": []
    }, {
    "activity": {
    "activityId": "1:6679:1"
    },
    "case": {
    "datasetId": "1:6679:1",
    "columnId": "1:6679:1" //optional if cases-dataset, if empty, we use the case if the row
    //an error is given if the dataset or column was not found
    }
    //the entire fields array is optional
    }
  • Parameters

    • activityId: string
    • caseId: string

    Returns Promise<unknown>

    Promise

    API.v1.checkRights('1:4581:5436', API.v1.info.getGlobalCaseId()).then(function(hasRights) {
    if(hasRights) {
    //== do what you have to do now you know the user has the right rights
    } else {
    //== do what you have to do now you know the user does not have the right rights
    }
    })
    .catch(function(error){
    console.error('Unable to check rights', error);
    });
  • Retrieve a dataset, conditions / aggregation are available. See the Dataset class for more detailed documentation.

    Parameters

    • datasetId: string
    • caseId: string
    • OptionalwidgetId: string

    Returns Dataset

    const Dataset      = API.v1.Dataset;
    const Or = API.v1.Dataset.Or;
    const And = API.v1.Dataset.And;
    const Condition = API.v1.Dataset.Condition;

    const dSet = API.v1.getDataset('datasetId', 'caseId', 'widgetId').useExternalReference();
    const thisConditionList = And(
    Condition('amount','>','100'),
    Condition('Country','==','Netherlands'),
    Or(
    Condition('averageAge','!=','12'),
    Condition('Country','==','Belgium')
    )
    );

    //== Simple count
    dSet.where(thisConditionList)
    .aggregate('columnReference', 'count', 'amount')
    .sort('amount')
    .exec()
    .then(...)
    .catch(...);

    //== Advanced, using all functions
    dSet
    .select('personColumn', 'genderColumn') // optional, select only a few columns
    //== For aggregate datasets: Filter on unaggregated dataset with preFilter
    .preFilter(And(Condition('personColumn','==','Person'), Condition('genderColumn','==','Male')))
    .groupBy('cityColumn', 'City')
    .groupBy('countryColumn', 'Country')
    .aggregate('amountColumn', 'count', 'amount')
    .aggregate('avgColumn', 'avg', 'averageAge')
    .where(thisConditionList) //== Filter on aggregated part of th dataset
    .sort('averageAge', 'desc')
    .sort('City')
    .sort('Country')
    .limit(10)
    .skip(5)
    .exec()
    .then(function ( dataset ) {
    console.info('dataset', dataset);
    dataset.rows.forEach(function ( row ) {
    console.info('Row in dataset', row);
    });
    })
    .catch(function ( error ) {
    console.warn('dsError', error);
    });
  • Parameters

    • form: string

      CaseId of the form

    • caseId: string

      CaseId where the form should be retrieved from

    • options: { widget?: string } = {}
      • Optionalwidget?: string

        Widget's CaseId to check rights

    Returns Promise<{ attribute: any; value: any }[]>

    API.v1.getForm('1:4581:6268', homepage, { widget: '1:4581:6264' })
    .then(function(form) { console.info('form', form); })
    .catch(function(error) { console.warn('formError', error); });
  • Parameters

    • picklistId: string

      CaseId of the picklist

    • caseId: string

      CaseId where the form should be retrieved from

    • options: { widget?: string } = {}
      • Optionalwidget?: string

        Widget's CaseId to check rights

    Returns Promise<Picklist>

    API.v1.getPicklist('1:4581:6269', 'homepage', { widget: '1:4581:6264' })
    .then(function(picklist) { console.info('picklist', form); })
    .catch(function(error) { console.warn('picklistError', error); });
  • Retrieve the Plugin Options that were set in the studio.

    Returns object

    const widgetOptions = API.v1.getPluginOptions();
    console.info('MyWidgetOptions:',widgetOptions);
  • Retrieve the reference of a case.

    Parameters

    • caseId: string
    • htmlEncodeUserData: boolean = false

    Returns Promise<string>

    Promise will return a string

    API.v1.getReference('1:142:555')
    .then(function( reference ) {
    console.info('Reference for case is', reference);
    })
    .catch(function( error ) {
    console.warn('getReference error:', error);
    });
  • Parameters

    • template: string

      CaseId of the template

    • caseId: string

      CaseId on which the template will be requested (CaseData template parts in the template will use this Id)

    • options: {
          activityContext?: string;
          rightsCase?: string;
          taskContext?: string;
          widget: string;
      }
      • OptionalactivityContext?: string

        Activity context that will be used by activityMeta template parts

      • OptionalrightsCase?: string

        The rightsCase if the caseId where the widget is on differs from the caseId parameter.

      • OptionaltaskContext?: string

        Task context that will be used by taskMeta template parts

      • widget: string

        The widget to use to check rights

    Returns Promise<string>

    API.v1.getTemplate()
    .then(function( template ) {
    console.info('Template output:', template);
    })
    .catch(function( error ) {
    console.warn('getTemplate error:', error);
    });
  • Launch activity on-screen in a modal.

    Parameters

    • activityId: string

      Activity Id or Task Id

    • caseId: string

      Case Id

    • options: ActivityOptions = ...

      Options

      • prepare

        Preload picklists.

      • refreshWidgets

        Should widgets be refreshed after this activity has been completed?

      • context

        Context for the form, can be accessed in form plugins.

    Returns Promise<Record<string, string>>

    const caseId = API.v1.info.getGlobalCaseId();
    const activity = '1:4581:1668';
    API.v1.launchActivity(activity, caseId)
    .then(function() {
    console.info('Activity has been submitted by the user');
    });
  • Parameters

    • activity: string

      Activity Id to perform

    • caseId: string

      Case Id to perform activity on

    • Optionaloptions: { allowInBackground?: boolean; refreshWidgets?: boolean; silent?: boolean } = {}
      • OptionalallowInBackground?: boolean

        allowInBackground is an option introduced for minimizable modals. In some cases, forms need to be closed before proceeding. When enabled, this option allows the activity to continue running in the background without prompting you to close the form.

      • OptionalrefreshWidgets?: boolean

        Should widgets be refreshed after this activity has been, default is true completed?

      • Optionalsilent?: boolean

        Suppress the error popup when an activity fails. This allows you to handle the error manually as needed.

    • data: Record<string, unknown> = {}

      Data that should be posted. e.g. {fieldId: value,...}

    Returns Promise<{ createdCase: string; returnResult: Record<string, unknown> }>

    API.v1.postActivity('1:4581:1668', '1:4584:6', { refreshWidgets: true }, {"externalReference": "Value"})
    .then(function(data) {
    console.info('Activity completed', 'createdCase:', data.createdCase, 'resultFields:', data.returnResult);
    })
    .catch(function(error) { console.warn('ActivityError', error); });
  • Upload a single file

    Parameters

    • file: File
    • progressCallback: (progress: number, fileSize: number, fileObject: File) => void

      A function which gets called on upload-progress. Signature: function(progress, fileSize, fileObject) {}.

    Returns Promise<unknown>

    //== get files from a <input type="file"></input> field.
    const files = document.querySelector('input[type="file"]').files;
    //== loop through files
    for (let i = 0; i < files.length; i++) {
    const file = files.item(i);
    console.info('Starting upload of a file',file);
    API.v1.uploadFile(file, function(progress, fileSize, fileObject) {
    console.info('FileUpload#Progress', progress, fileSize, fileObject);
    })
    .then(function(fileInfo){
    //== `fileInfo` is a json and can be used to submit in activities
    console.info('File was upload with great succes', fileInfo);
    })
    .catch(function(error){
    //== Something went wrong, `error` describes what is was.
    console.error('Unable to upload. Reason:', error);
    })
    }