Search Results for

    Show / Hide Table of Contents

    Worker site API

    Besides integrating with AngularJS built-in services, Casewhere provides a set of APIs to give you more flexibilities to develop worker site components, custom widget, rich-UI form activities, etc.

    API list

    AppConfig

    A constant contains all the app's config. For example:

    {
        ApiEndPoint: "https://local-api.casewhere.com/api/v0.1/",
        AuthEndPoint: "https://local-api.casewhere.com/",
        LoginEndpoint: "https://local-api.casewhere.com/signon?relayState=",
        LogoutEndpoint: "https://local-api.casewhere.com/signoff",
        RuntimeApiEndPoint: "https://local-api.casewhere.com/external/v0.1/",
        TextResourceEndPoint: "https://local-api.casewhere.com/languages/",
        WorkerSiteUrl: "https://local.casewhere.com/"
    }
    

    CurrentUser

    To interact with the user session in the worker site.

    isLoggedIn()

    Deprecated: This method no longer makes sense and will be removed in future versions. Determine whether the user is logged in. This method always returns true if the site allows anonymous users.

    Result: bool

    isAuthorized()

    Deprecated: This method no longer makes sense and will be removed in future versions. Determine whether the user is authorized.

    Result: bool

    hasClaim(type, value)

    Determine if the user has a specific claim or not.

    Result: bool

    getClaims()

    Result: The claim-set object

    loginWithDialog()

    Open the login dialog to authenticate users.

    Result: A promise

    forceLogIn(returnUrl)

    Force a login. The user after logins with be reditected to the returnUrl. If the returnUrl is not provided, Casewhere will redirect the user to the home page.

    logOut(returnUrl)

    Logout and redirect the user to the returnUrl. If the returnUrl is not provided, Casewhere will redirect the user to '/logout';

    isAuthenticated()

    To determine whether the user is authenticated on the client side.

    DataSourceService

    To get data from a data source. Read more at Restful data source.

    search(dataSourceName, query)

    Search against a data source.

    Parameters

    • dataSourceName: The name of the data source
    • query: The data query object
      • filter: The filter object
      • fields: The returned fields
      • skip: The number of records to be skipped. This is to support data paging.
      • take: The number of records to be returned. This is to support data paging.

    Result: A promise returns the data

    Example:

    var query = {
        filter: {
            Kommunenr: '101'
        }
    };
    DataSourceService.search('People', query).then(function(response) {
        console.log(response.data);
        console.log(response.total);
        console.log(response.metadata);
        console.log(response.isSearchLimitExceeded);
    });
    

    loadDataObject(dataSourceName, doId)

    Load a data object by id.

    Parameters

    • dataSourceName: The name of the data source
    • doId: The data object id

    Result: A promise returns the data

    Example

    var query = {
        filter: {
            Kommunenr: '101'
        }
    };
    DataSourceService.search('People', "person/cf732abc-7a5c-4773-9998-4d4f8ccdb023").then(function(response) {
        console.log(response.data);
    });
    

    DocumentService

    To work with the Casewhere file storage.

    generateToken(doId, propertyName)

    Generate a token for downloading a document.

    Parameters

    • doId: The data object id holding the document
    • propertyName: The data attribute holding the document

    Result: a promise returns the token object

    { tokenId: "1b2b3e7a5d0544218bcb9495cda043fd" }
    

    generateWorkflowVariableToken(workflowId, variableName)

    Generate a token for downloading a document referenced by a workflow variable.

    Parameters

    • workflowId: The workflow id
    • variableName: The workflow variable name

    Result: a promise returns the token object

    { tokenId: "1b2b3e7a5d0544218bcb9495cda043fd" }
    

    download(tokenId)

    Trigger a download given a token id.

    Parameters

    • tokenId: The token id retrieved from generateToken
    DocumentService.download(token.tokenId);
    

    getDownloadUrl

    Return a GET download endpoint.

    Parameters

    • tokenId: The token id retrieved from generateToken

    Result: an URL

    Logger

    To work with application notifications.

    Logger.log(aMessage);
    Logger.error(errorMessage, { positionClass: 'toast-top-right' });
    Logger.info(infoMessage); // default position is 'toast-bottom-right'
    Logger.warning(warningMessage, { positionClass: 'toast-bottom-right' });
    Logger.success(successMessage); // default position is 'toast-bottom-right'
    

    PluginService

    To work with a Casewhere plugins. Read more at Plugin API.

    invoke("pluginName", "pluginMethodName", parameters)

    Parameters

    • pluginName: The plugin name
    • pluginMethodName: The method name
    • parameters: The parameteres

    Result: a promise returns the plugin result

    Example:

    Note: You can only invoke public plugins from worker site.

    var parameters = { Name: "John Doe" };
    
    PluginService.invoke("pluginName", "pluginMethodName", parameters)
    	.then(function (pluginResult) {
        	console.log(pluginResult);
        }, function (error) {
        	console.log(error);
        });
    

    RuleService

    To evaluate a client-side rule.

    evaluate(ruleName, parameters)

    Parameters

    • ruleName: The rule you want to evaluate
    • parameters: The rule parameters

    Result: an object

    Example:

    Imagine you have the following client-side rule configured in Casewhere Admin:

    // name: get billing address
    function (user, parameters)
    {
    	var isBusiness = user.contains("type", "business")
        if (isBusiness) return parameters.companyAddress;
        else return parameters.personalAddress;
    }
    

    You can evaluate the rule in the worker site as below:

    var billingAddress = RuleService.evaluate("get billing address", {
    	companyAddress: "Sunset Boulevard xxx",
    	personalAddress: "Refshalevej xxx"
    });
    

    $translate

    instant(textResourceKey)

    To translate a text resource.

    Parameters

    • textResourceKey: the text resource key

    Result: The translated text

    Example:

    var text = $translate.instant("textResourceKey");
    

    WebTriggerService

    To work with web triggers.

    get(webTriggerName, data, config)

    Parameters

    • webTriggerName: The web trigger name
    • data: The data to be sent to the server as a query string
    • config: [Optional] The object describing the request to be made and how it should be processed. Read more at $http

    Result: a HttpPromise object. Read more at $http

    Example:

    LoaderService.show();
    WebTriggerService.get("export", parameters).then(function(response) {
        Logger.info(response.data);    
    }, (error) => {
        Logger.error(error);
    }).finally(function() {
        LoaderService.hide();
    });
    

    post(webTriggerName, data, config)

    Parameters

    • webTriggerName: The web trigger name
    • data: The payload
    • config: [Optional] The object describing the request to be made and how it should be processed. Read more at $http

    Result: a HttpPromise object. Read more at $http

    Example:

    WebTriggerService.post("search", data).then(
        function (response) {
            model.metadata = response.metadata;
            model.gridOpt.data = response.data.data;
            model.gridApi.grid.options.totalItems = response.data.totalItems;
        }
    );
    

    Filters

    cwFileLinkFilter

    Transform the system document name to a download link.

    Example

    Input: logo

    Output: https://local-api.casewhere.com/api/v0.1/system-documents/logo

    <img ng-src="{{'logo' | cwFileLinkFilter}}"></img>
    

    workerLink

    Transform a Worker API relative path to an absolute path.

    Example

    Input: system-documents/logo

    Output: https://local-api.casewhere.com/api/v0.1/system-documents/logo

     <img ng-src="{{'system-documents/logologo' | workerLink}}"></img>
    

    cwWorkerSiteDate

    Convert a date to the worker site time zone and render it using a given format. Learn more about the formats here.

    Example

    {{date | cwWorkerSiteDate:'shortDate'}}
    

    workerSiteLink

    Transform a Worker Site relative path to an absolute path.

    Example

    Input: resource-name

    Output: https://local-worker.casewhere.com/resource-name

    Working with worker site APIs

    All components in Casewhere Worker Site, such as worker site components, custom widget, etc., are implemented as a AngularJS directive. To work with Casewhere APIs, you will need to learn how to inject a service into a directive. Please follow this instruction and avoid the Implicit Annotation so your component can work properly when Casewhere minifies the scripts.

    image-20220121150324385

    In This Article
    Back to top Generated by DocFX