Skip to content
UI extensions, tab customizations and more 🎉 CHT 5.2 is here!

CHT API

Introduced in v3.12.0

Provides CHT Core Framework’s functions to contact summary, targets, tasks, etc. The API is available in the cht reserved variable under the v1 version.

FunctionArgumentsDescription
hasPermissions(permissions, userRoles)permissions: String or array of permission name(s).
userRoles: (Optional) Array of user roles. Default to the current logged in user.
Returns true if the user has the permission(s), otherwise returns false.
hasAnyPermission(permissionsGroups, userRoles)permissionsGroups: Array of groups of permission name(s).
userRoles: (Optional) Array of user roles. Default to the current logged in user.
Returns true if the user has all the permissions of any of the provided groups, otherwise returns false.
getExtensionLib(name)name: String of script nameReturns an executable function identified by the given name configured as extension-libs.
analytics.getTargetDocs()Returns three target documents of the contact, calculated for the last three reporting intervals, including the current one. When viewing one of the current logged in user’s associated facilities, returns the target documents for the contact associated with the current logged in user. Returns an empty array if no target documents are found (for example when viewing a contact that does not upload targets). Introduced in v4.11.0
translate(key, interpolateParams)key: The translation key.
interpolateParams: (Optional) Object containing values to be used in the translated string.
Returns the value in the current user’s language from the app translations for the given key.
getResource(name)name: The name key of the resource to getReturns the data for a configured resource. The returned object contains a content_type property defining the type of resource (e.g. image/png). The data property contains the Base64 representation of the resource.

CHT API’s code samples

const canEdit = cht.v1.hasPermissions('can_edit');
const canManagePlaces = cht.v1.hasPermissions(['can_create_places', 'can_update_places']);
const hasAnyGroup = cht.v1.hasAnyPermission([
    ['can_view_messages', 'can_view_message_action'], 
    ['can_view_reports', 'can_verify_reports']
]);
const averageFn = cht.v1.getExtensionLib('average.js');
const targetDocs = cht.v1.analytics.getTargetDocs();
Last updated on

Did this documentation help you ?