Creatio development guide
PDF
This documentation is valid for Creatio version 7.11.0. We recommend using the newest version of Creatio documentation.

How to call a configuration service

Glossary Item Box

Calling of a service from code of configuration schemas

To call a configuration web-service from client JavaScript code, take the following actions:

  1. Connect the ServiceHelper module to a module of the page, from which the service is called. This module provides a convenient interface for execution of queries to the server through Terrasoft.AjaxProvider query provider, implanted in the client core.
  2. all the callService(serviceName, serviceMethodName, callback, serviceData, scope) method from ServiceHelper module by transferring the following parameters to it (Table 1).

Table 1. — callService() method parameters

Parameter Description
serviceName Is a name of a configuration service. It corresponds to the class name in C# that implements the service.
servcieMethodName Is a name of a called method of configuration service. The method can accept input parameters and return resultant values.
callback(response)

Is a function of callback where a service response is processed. The function accepts response object as a parameter. If a called service method returns any value, you can get it in the client through the response object property.

The name of the property, where the method output-value is returned, is formed by the following rule: [Service method name]+[Result].

For example, if GetSomeValue() method is called then the returnable value will be included into the response.GetSomeValueResult property.

scope Is an execution context.
 

Example of service calling from configuration schema

It is required to add a button on the new contact creation page. Clicking on the button will call a configuration web-service. The results, returnable by web-service method, will be displayed in the info window.

The example uses a web-service from an example, which is described in the How to create own configuration service article.

Case implementation algorithm

1. Create replacing contact edit page and add a button to it

The process of adding a button to the edit page is described in the article How to add a button to an edit page in the new record add mode.

Add localized GetServiceInfoButtonCaption string with title name, for example "Call service" to the schema of replacing module of contact edit page.

Connect the ServiceHelper module as a dependency in the declaration of the edit page module.

2. Add button handler and call web-service method in it

Use the callService method of the ServiceHelper module to call a web-service. Transfer the name of configuration service class, name of called service method, object with initialized input parameters for service method, callback function where you have to process server results, and also execution context to the ServiceHelper module.

Source code of replacing module of edit page is shown below.

define("ContactPageV2", ["ServiceHelper"],
    function(ServiceHelper) {
        return {
            // Name of edit page object schema.
            entitySchemaName: "Contact",
            details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
            // Collection of methods of edit page view model.
            methods: {
                // Method verifies whether the [Full name] field of the page is completed.
                isContactNameSet: function() {
                    return this.get("Name") ? true : false;
                },
                // The method-handler of button clicking.
                onGetServiceInfoClick: function() {
                    var name = this.get("Name");
                    // Object that initializes input parameters for service method.
                    var serviceData = {
                        // Property name coincides with name of input parameter of service method.
                        inputParam: name
                    };
                    // Calling of web-service and processing of results.
                    ServiceHelper.callService("CustomConfigurationService", "GetTransformValue",
                        function(response) {
                            var result = response.GetTransformValueResult;
                            this.showInformationDialog(result);
                        }, serviceData, this);
                }
            },
            diff: /**SCHEMA_DIFF*/[
                // Metadata for adding new control item, i.e. user button, to the page.
                {
                    //It specifies that adding item to the page is performed. 
                    "operation": "insert",
                    //Metaname of parent control item, to which the button is added. 
                    "parentName": "LeftContainer",
                    // It indicates that the button is added to collection of control items of 
                    // parent item (metaname of which is indicated in parentName. 
                    "propertyName": "items",
                    //Metaname of added column. 
                    "name": "GetServiceInfoButton",
                    //Additional properties of the field.
                    "values": {
                        //Type of added item - button. 
                        itemType: Terrasoft.ViewItemType.BUTTON,
                        // Linking of column title to localizable schema string. 
                        caption: {bindTo: "Resources.Strings.GetServiceInfoButtonCaption"},
                        //Linking of method -handler of button clicking 
                        click: {bindTo: "onGetServiceInfoClick"},
                        //Linking of button accessibility property. 
                        enabled: {bindTo: "isContactNameSet"},
                        // Setting of filed layout.
                        "layout": {"column": 1, "row": 6, "colSpan": 2}
                    }
                }
            ]/**SCHEMA_DIFF*/
        };
    });

3. Save a scheme in the configuration

Case execution result is shown on Fig. 1.

Fig. 1. — Result of configuration service calling case

© bpm'online 2002-2018.

Did you find this information useful?

How can we improve it?