Idea
Discussion

Hi everyone! We have released a new version of Clio and Clio Explorer.

What's new:

  1. .NET 6 is supported and Clio is now compatible with iOS on M series processors.

  2. OAuth settings are supported in the UI for easy connection with the Creatio trial version.

  3. Quick access to all Clio settings in Clio Explorer for advanced users.

  4. Support for working with auto-generated code in the package assembly for local development in workplaces.

3 comments

Links on Clio explorer and clio

You might want to reclassify as "Article" :)

Clio explorer seems awsome. Kudos to the team

Show all comments

Has anyone been successful using the CreatioSDK in sending date updates via either InsertQuery or UpdateQuery?

 

I've tried sending dates in all the following formats but all result in an error:

 

yyyy-MM-dd

yyyy-MM-ddTHH:mm:ss

yyyy-MM-ddTHH:mm:ss.fff 

yyyy-MM-ddTHH:mm:ss.fffffffZ

M/d/yyyy

d/M/yyyy

dd/MM/yyyy

 

The dates I'm trying to send are defined as DataValueType.Date and I've tried specifying that in the Update/InsertQuery and in desperation also tried specifying as DataValueType.DateTime. 

 

If I omit dates from the Insert/Update queries the updates are successful. 

 

I can successfully enter dates in the records I'm trying to update via the Creatio UI.

 

Here's an example of a stripped down InsertQuery request, including the DueDate column causes an error 500, if excluded the insert is successful:

 

{

  "QueryId": null,

  "QueryKind": 0,

  "ColumnValues": {

    "Items": {

      "Title": {

        "ExpressionType": 2,

        "IsBlock": false,

        "ColumnPath": null,

        "Parameter": {

          "DataValueType": 1,

          "Value": "Test SDK Three",

          "ArrayValue": null,

          "ShouldSkipConvertion": false

        },

        "FunctionType": 0,

        "MacrosType": 0,

        "FunctionArgument": null,

        "FunctionArguments": null,

        "DateDiffInterval": 0,

        "DatePartType": 0,

        "AggregationType": 0,

        "AggregationEvalType": 0,

        "SubFilters": null,

        "ArithmeticOperation": 0,

        "LeftArithmeticOperand": null,

        "RightArithmeticOperand": null

      },

      "Contact": {

        "ExpressionType": 2,

        "IsBlock": false,

        "ColumnPath": null,

        "Parameter": {

          "DataValueType": 0,

          "Value": "fede06a3-1270-4464-8049-c7afb144a018",

          "ArrayValue": null,

          "ShouldSkipConvertion": false

        },

        "FunctionType": 0,

        "MacrosType": 0,

        "FunctionArgument": null,

        "FunctionArguments": null,

        "DateDiffInterval": 0,

        "DatePartType": 0,

        "AggregationType": 0,

        "AggregationEvalType": 0,

        "SubFilters": null,

        "ArithmeticOperation": 0,

        "LeftArithmeticOperand": null,

        "RightArithmeticOperand": null

      },

      "DueDate": {

        "ExpressionType": 2,

        "IsBlock": false,

        "ColumnPath": null,

        "Parameter": {

          "DataValueType": 8,

          "Value": "2022-05-28",

          "ArrayValue": null,

          "ShouldSkipConvertion": false

        },

        "FunctionType": 0,

        "MacrosType": 0,

        "FunctionArgument": null,

        "FunctionArguments": null,

        "DateDiffInterval": 0,

        "DatePartType": 0,

        "AggregationType": 0,

        "AggregationEvalType": 0,

        "SubFilters": null,

        "ArithmeticOperation": 0,

        "LeftArithmeticOperand": null,

        "RightArithmeticOperand": null

      },

      "Amount": {

        "ExpressionType": 2,

        "IsBlock": false,

        "ColumnPath": null,

        "Parameter": {

          "DataValueType": 5,

          "Value": 6718.35,

          "ArrayValue": null,

          "ShouldSkipConvertion": false

        },

        "FunctionType": 0,

        "MacrosType": 0,

        "FunctionArgument": null,

        "FunctionArguments": null,

        "DateDiffInterval": 0,

        "DatePartType": 0,

        "AggregationType": 0,

        "AggregationEvalType": 0,

        "SubFilters": null,

        "ArithmeticOperation": 0,

        "LeftArithmeticOperand": null,

        "RightArithmeticOperand": null

      },

      "Budget": {

        "ExpressionType": 2,

        "IsBlock": false,

        "ColumnPath": null,

        "Parameter": {

          "DataValueType": 5,

          "Value": 0.0,

          "ArrayValue": null,

          "ShouldSkipConvertion": false

        },

        "FunctionType": 0,

        "MacrosType": 0,

        "FunctionArgument": null,

        "FunctionArguments": null,

        "DateDiffInterval": 0,

        "DatePartType": 0,

        "AggregationType": 0,

        "AggregationEvalType": 0,

        "SubFilters": null,

        "ArithmeticOperation": 0,

        "LeftArithmeticOperand": null,

        "RightArithmeticOperand": null

      }

    }

  },

  "RootSchemaName": "Opportunity",

  "IncludeProcessExecutionData": false

}

 

  

Like 0

Like

1 comments
Best reply

Hello Jerry, 



Please try to pass Date into Creatio with the following format in UTC time:

 

      "dataValueType":8,
      "value":"\"2000-01-01T00:00:00.000\""

Kind regards,
Roman

Hello Jerry, 



Please try to pass Date into Creatio with the following format in UTC time:

 

      "dataValueType":8,
      "value":"\"2000-01-01T00:00:00.000\""

Kind regards,
Roman
Show all comments

Question

When I paste a RICH_TEXT element, its toolbar looks as follows:

Could you clarify what might be wrong with it?

Answer

The reason might be that some of the base styles  in your configuration might be overridden, e.g., the .t-btn-image style.

Like 0

Like

Share

0 comments
Show all comments

Case

We need to create users of an "Our company" type for the employees of any company, and not only for those belonging to the "Our company" that exists out-of-the-box.

Solution

Change the PrepareEmployeeEditFilter method in the UserEditPage  schema as follows:

var filters = e.Filters;
filters.Add(new Dictionary<string, object> {
    {"comparisonType", FilterComparisonType.Equal},
    {"leftExpressionColumnPath", "[SysAdminUnit:Contact].Id"},
    {"aggregationType", AggregationTypeStrict.Count},
    {"useDisplayValue", false},
    {"rightExpressionParameterValues", new object[] {0}}});
filters.Add(new Dictionary<string, object> {
    {"comparisonType", FilterComparisonType.Equal},
    {"leftExpressionColumnPath", "Account.Type"},
    {"useDisplayValue", false},
    {"rightExpressionParameterValues", new object[] { new Guid("57412fad-53e6-df11-971b-001d60e938c6")}}});
e.ParametersValue.Add("hideButtons", true);

where "57412fad-53e6-df11-971b-001d60e938c6" is the ID of the AccountType table that corresponds to the "Our company" value.

Necessary conditions

For version 7.4 only

Like 0

Like

Share

0 comments
Show all comments

Question

When creating a case through the portal, the user sets the case Assignee using a code. Though, the [Assignee] field remains blank after saving the record.

Answer

When you save a Case object (the Portal package), you basically run the event sub-process defined in the CaseInserting event of the object. If you meet the UserType = SSP condition in this process,  the [Assignee] field is cleared.

Like 1

Like

Share

0 comments
Show all comments

Case

I need to create a widget

Solution

You can use widgets to display data from in-built modules. It enables displaying data in non-standard views.

Example of implementing a widget:

define('SxClientUnitTable', ['ext-base', 'terrasoft', 'sandbox', "BaseFiltersGenerateModule", 'SxClientUnitTableResources', "ChartModuleHelper", "css!SxClientUnitTableCss", "ServiceHelper"],
	function(Ext, Terrasoft, sandbox, BaseFiltersGenerateModule, resources, ChartModuleHelper, css, ServiceHelper, ConfigurationConstants) {
 
		function getViewModel() {
					return Ext.create('Terrasoft.BaseViewModel', {
				//todo SysModuleAnalyticsChart deleted
						entitySchema: 'Order',
						methods: {
							getChart: function(key) {
							debugger
								sandbox.publish('GenerateChart', key);
								var filters = this.getReportFilters();
							},
							load: function() {
 
							}
						}
					});
				};
		var result = "";
		function generateMainView(renderTo) {
 
			var resultConfig = Ext.create('Terrasoft.Container', {
				id: 'tableOtchetMetkiParamContainer',
				selectors: {
					wrapEl: '#tableOtchetMetkiParamContainer'
				},
				renderTo: renderTo
			});
			return resultConfig;
		}
		function getInfoMetki(parameters) {
 
			var serviceData = {
				site: parameters[0].toString(),
				ownerId: parameters[1].toString(),
				startDate: parameters[2].toString(),
				dueDate: parameters[3].toString(),
				countryId: parameters[4].toString()
			};
 
			ServiceHelper.callService("UsrOtchetMetkiGetCollectionConfigurationService", "GetCollectionOtchetMetki",
				function (response) {
				debugger
					if (response.status == 404) {
						this.showInformationDialog("\t Error: \n" + response.message);
					}
					else if(response.GetCollectionOtchetMetkiResult.length > 0){
						result = response.GetCollectionOtchetMetkiResult;
						var arrR = result.split(":");
						var htmlAdded = "<table><tr><th>Mark</th><th>Number of orders</th><th>Being specified</th><th>% Specified.</th><th>Confirmed</th><th>% Conf.</th><th>Completed</th><th>% Compl.</th><th>Canceled</th><th>% Canc.</th></tr>";
						for(var i = 0; i < arrR.length - 1; i++){
							//get items
							var strArr = arrR[i].split(" ");
							var metkaOne = strArr[0].replace("{","");
							var metka = metkaOne.replace("}","");
 
							htmlAdded += "<tr><td>" + metka + "</td><td>" + strArr[1].toString() + "</td><td>"  + strArr[2].toString() + "</td><td>" + strArr[3].toString() + "</td><td>" + strArr[4].toString() + "</td><td>" + strArr[5].toString() + "</td><td>" + strArr[6].toString() + "</td><td>" + strArr[7].toString() + "</td><td>"  + strArr[8].toString() + "</td><td>" + strArr[9].toString() + "</td></tr>";
						}
						//end table
						htmlAdded += "</table>";
						var el = Ext.get('tableOtchetMetkiParamContainer').setHTML(htmlAdded);
						var elemV = Ext.get('Module1');
						elemV.toggleCls('my-table');
					}
					else
						result = null;
				}, serviceData, this);
		}
		function getReplaceString(str, separator){
		debugger
		var arSt = str.split(separator);
			var res = arSt[2] + separator + arSt[1] + separator + arSt[0];
			while(res.indexOf(separator) > 0){
				res = res.replace(separator,"-");
			}
			return res;
		}
 
		var render = function(renderTo) {
 
 
			debugger
			var viewConfig = generateMainView(renderTo);
			var viewModel = getViewModel();
			var getStartD = Ext.get("fixedFilterDateView-wrap").dom.innerText;
			var getEndD = Ext.get("fixedFilterDateDueView-wrap").dom.innerText;
 
			var startD = getStartD.indexOf("Начало") > 0 ? "2016-05-01" : getReplaceString(getStartD, ".");
			var endD = getEndD.indexOf("Завершение") > 0 ? "2016-07-04" : getReplaceString(getEndD, ".");
			var ar = [];
			ar.push("all");
			ar.push("all");
			ar.push(startD);
			ar.push(endD);
			ar.push("a570b005-e8bb-df11-b00f-001d60e938c6");
			getInfoMetki(ar);
 
 
			viewConfig.bind(viewModel);
			//viewConfig.render(renderTo);
		};
		return {
			schema: 'Order',
			methods: {
				onLookupChange: function(newValue, columnName) {
 
                                this.callParent(arguments);
                                if (columnName === "UsrCityFilter") {
                                        this.set("UsrCityFilter", newValue);
                                        this.onUsrCityFilterChanged();
                                }
                        },
 
                        onUsrCityFilterChanged: function() {
                                this.reloadGridData();
                        },
				getOrdersForFilter: function(){
					var items = [];
					var selOrders = Ext.create("Terrasoft.EntitySchemaQuery", {
						rootSchemaName: "Order"
					});
					selOrders.addColumn("SxMark.Name");
					selOrders.addColumn("SxCountry.Name");
					var filterByUser = Terrasoft.createColumnFilterWithParameter(
					Terrasoft.ComparisonType.EQUAL, "SxCountry.Name", "Россия");
					selOrders.filters.addItem(filterByUser);
					selOrders.getEntityCollection(function (response) {
					debugger
						if (response.collection.collection.length > 0)
							items = result.collection.getItems();
						else
							items = null;
					}, this);
					return items;
				}
 
			},
			userCode: function() {
 
			},
			init: function() {
 
			},
			filterChanged: function( filter, eOpts ){
				debugger
				var c = [];
			},
			render: render
		};
	}
)
;

 

 

Like 0

Like

Share

0 comments
Show all comments

Case

Access to section disappeared for all users, except for the Supervisor. Standard script for granting access permissions works but does not add records.

Solution

The [CreatedById] field in the user's database table is not populated. To solve the issue, populate the field and specify "Supervisor" as a creator:

Update Account --change the object
SET CreatedById = (SELECT id FROM Contact c WHERE c.Name = 'Supervisor')
where CreatedById is null;

 

Like 0

Like

Share

0 comments
Show all comments

Question

We cannot add contacts. The page freezes when doing so.

Answer

The details "Detail: Contact address" and "Detail: Contact communication options" have been deleted from the contact page. That is the reason why you cannot add new contacts.

Restore the details and you will receive no errors.

To do this, add the below code to the ContactPageV2 schema:

details: {
    "AccountAddress": {
        "schemaName": "AccountAddressDetailV2",
        "entitySchemaName": "AccountAddress",
        "filter": {
            "detailColumn": "Account",
            "masterColumn": "Account"
        },
        "useRelationship": true,
        "filterMethod": "accountAddressFilter"
    },
    "AccountCommunication": {
        "schemaName": "AccountCommunicationDetail",
        "entitySchemaName": "AccountCommunication",
        "filter": {
            "detailColumn": "Account",
            "masterColumn": "Account"
        },
        "useRelationship": true,
        "filterMethod": "accountAddressFilter"
    }
},
/**......*/
methods: {
    accountAddressFilter: function() {
        var account =  this.get("Account");
        var accountId = this.Terrasoft.GUID_EMPTY;
        if (account && account.value) {
            accountId = account.value;
        }
 
        var filterGroup = new this.Terrasoft.createFilterGroup();
        filterGroup.logicalOperation = this.Terrasoft.LogicalOperatorType.AND;
        filterGroup.add("AccountFilter", this.Terrasoft.createColumnFilterWithParameter(
        this.Terrasoft.ComparisonType.EQUAL, "Account", accountId));
        return filterGroup;
    }
},
/**......*/

 

Like 0

Like

Share

0 comments
Show all comments

Symptoms

When creating details via the "Detail wizard" and switching to the "Page" tab, the browser fails and provides the below error:

message: The 7f889822-86af-4b53-bd7d-b8b153f0a5c4 key element Does not exist

Solution

Find an element with the necessary CardSchemaUId in the SysModuleEdit table of the database and delete it.

Necessary conditions and restrictions

Occurred in version 7.7

Like 1

Like

Share

0 comments
Show all comments

Customization of the unsupscribe function is represented in the following php codes:

Functions:

<?php
function BPMAuth(){
    $url = 'https://bpmonline.com/ServiceModel/AuthService.svc/Login';//someBPMURL
    $requestData["UserName"] = "";
    $requestData["UserPassword"] = "";    
    $jcres = json_encode($requestData);    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jcres);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($jcres))
    );
    $result = curl_exec($ch);
    curl_close($ch);
}
function BPMQuery($json,$operation) {
    //Operations: 1-Add Data; 2 - Update Data; 3 - batch Data; 4 - SelectQuery
    switch ($operation) {
    case 1:
        $queryOperation='InsertQuery';
        break;
    case 2:
        $queryOperation='UpdateQuery';
        break;
    case 3:
        $queryOperation='BatchQuery';
        break;
    case 4:
        $queryOperation='SelectQuery';
        break;
}
    $url = 'https://bpmonline.com/0/DataService/json/SyncReply/'.$queryOperation;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($json))
    );
    return curl_exec($ch);
    curl_close($ch);
} // Sends Update Query to BPM
function BuildIdFilter(array $array){
    $i=0;
    $filter='';
    foreach ($array as $item)
        {
            if ($i!=0) $filter.=',';
            $filter.='
            "CustomFilters'.$i.'":{
            "filterType":1,
            "comparisonType":3,
            "isEnabled":true,
            "trimDateTimeParameterToDate":false,
            "leftExpression":{
    		   "expressionType":0,
    		   "columnPath":"Id"
    			},
            "rightExpression":{
               "expressionType":2,
               "parameter":{
                  "dataValueType":0,
                  "value":"'.$item.'"
               }
            }
         }';
        $i++;  
 
        }
    return $filter;
} // Build Json Array Filter
function BuildSubscribeJson($filter,$bool){
    //$filter is filter to be applied in Json
    //$bool - to set true (Subscribed) or false(unsubscribed) for subscription
    if($bool==true) {$subsvalue='1a5cd9b8-b999-4b65-b8a8-bd3168792128';}
    else {$subsvalue='c8947f80-a374-412a-bbc8-ea9068a8b78e';}
    return '{
                           "rootSchemaName":"BulkEmailSubscription",
                           "operationType":2,
                           "filters":{
                              "items":{
                                 '.$filter.'
                              },
                              "logicalOperation":1,
                              "isEnabled":true,
                              "filterType":6
                           },
                           "columnValues":{
                              "items":{
                                 "BulkEmailSubsStatus":{
                                    "expressionType":2,
                                    "parameter":{
                                       "dataValueType":10,
                                       "value":"'.$subsvalue.'"
                                    }
                                 }
                              }
                           },
                           "isForceUpdate":false
                        }';
 
}
function JsonAddNewSubscriber($contactId,array $bulkemailtype,$bool_subsctiption){
    //$contactId Id of contuct to be subscribed
    //$bulkemailtype is id of bulk email to be subscribed
    //$bool_subsctiption - to set true (Subscribed) or false(unsubscribed) for subscription
    if($bool_subsctiption==true) {$subsvalue='1a5cd9b8-b999-4b65-b8a8-bd3168792128';}
    else {$subsvalue='c8947f80-a374-412a-bbc8-ea9068a8b78e';}
    $i=0;
    $insertItems='';
 
 
    foreach ($bulkemailtype as $value) {
        if ($i!=0) $insertItems.=',';
        $insertItems.='{
            "__type": "Terrasoft.Nui.ServiceModel.DataContract.InsertQuery",
 
           "rootSchemaName":"BulkEmailSubscription",
           "operationType":1,
           "columnValues":{
              "items":{
                 "Contact":{
                    "expressionType":2,
                    "parameter":{
                       "dataValueType":10,
                       "value":"'.$contactId.'"
                    }
                 },
                 "BulkEmailType":{
                    "expressionType":2,
                    "parameter":{
                       "dataValueType":10,
                       "value":"'.$value.'"
                    }
                 },
                 "BulkEmailSubsStatus":{
                    "expressionType":2,
                    "parameter":{
                       "dataValueType":10,
                       "value":"'.$subsvalue.'"
                    }
                 }
              }
           }
 
        }';
        $i++;
    }
    return '{"items": ['.$insertItems.']}';
}
function ContactUnsubscribe($contactId,$bool){
    return '{
  "rootSchemaName": "Contact",
  "operationType": 2,
  "filters": {
    "items": {
      "primaryColumnFilter": {
        "filterType": 1,
        "comparisonType": 3,
        "isEnabled": true,
        "trimDateTimeParameterToDate": false,
        "leftExpression": {
          "expressionType": 1,
          "functionType": 1,
          "macrosType": 34
        },
        "rightExpression": {
          "expressionType": 2,
          "parameter": {
            "dataValueType": 0,
            "value": "'.$contactId.'"
          }
        }
      }
    },
    "logicalOperation": 0,
    "isEnabled": true,
    "filterType": 6
  },
  "columnValues": {
    "items": {
      "DoNotUseEmail": {
        "expressionType": 2,
        "parameter": {
          "dataValueType": 12,
          "value": '.$bool.'
        }
      }
    }
  },
  "isForceUpdate": false
}'; // Json Request
}
function JsonSelectSubscriptions($contactId){
    $json= '{
       "rootSchemaName":"BulkEmailSubscription",
       "operationType":0,
       "filters":{
          "items":{
             "customFilterContact_BulkEmailSubscription":{
                "filterType":1,
                "comparisonType":3,
                "isEnabled":true,
                "trimDateTimeParameterToDate":false,
                "leftExpression":{
                   "expressionType":0,
                   "columnPath":"Contact"
                },
                "rightExpression":{
                   "expressionType":2,
                   "parameter":{
                      "dataValueType":10,
                      "value":"'.$contactId.'"
                   }
                }
             }
          },
          "logicalOperation":0,
          "isEnabled":true,
          "filterType":6
       },
       "columns":{
          "items":{
             "Id":{
                "caption":"",
                "orderDirection":0,
                "orderPosition":-1,
                "isVisible":true,
                "expression":{
                   "expressionType":0,
                   "columnPath":"Id"
                }
             },
             "BulkEmailType":{
                "caption":"Bulk email type",
                "orderDirection":0,
                "orderPosition":-1,
                "isVisible":true,
                "expression":{
                   "expressionType":0,
                   "columnPath":"BulkEmailType"
                }
             },
             "BulkEmailSubsStatus":{
                "caption":"Subscription status",
                "orderDirection":0,
                "orderPosition":-1,
                "isVisible":true,
                "expression":{
                   "expressionType":0,
                   "columnPath":"BulkEmailSubsStatus"
                }
             }
          }
       },
       "isDistinct":false,
       "rowCount":30,
       "rowsOffset":0,
       "isPageable":false,
       "allColumns":false,
       "useLocalization":true,
       "useRecordDeactivation":false,
       "serverESQCacheParameters":{
          "cacheLevel":0,
          "cacheGroup":"",
          "cacheItemName":""
       },
       "queryOptimize":false,
       "useMetrics":false,
       "querySource":0,
       "ignoreDisplayValues":false,
       "conditionalValues":null,
       "isHierarchical":false
    }'; // Json Request
    return $json;
}
function JsonSelectdefaultchannels(){
    $json= '{"rootSchemaName":"BulkEmailType","operationType":0,"filters":{"items":{"64ae0f22-cb41-4599-97c1-3571c0fe56f3":{"items":{},"logicalOperation":0,"isEnabled":true,"filterType":6}},"logicalOperation":0,"isEnabled":true,"filterType":6},"columns":{"items":{"Id":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"Id"}},"Name":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"Name"}},"Description":{"caption":"Description","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"Description"}},"IsSignable":{"caption":"Can be subscriber","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"IsSignable"}},"EntryPointsCount":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":3,"aggregationType":1,"columnPath":"[EntryPoint:EntityId].Id","subFilters":{"items":{"c0c2fa11-5faa-415d-98d6-83df4bb90770":{"filterType":1,"comparisonType":3,"isEnabled":true,"trimDateTimeParameterToDate":false,"leftExpression":{"expressionType":0,"columnPath":"IsActive"},"rightExpression":{"expressionType":2,"parameter":{"dataValueType":1,"value":true}}}},"logicalOperation":0,"isEnabled":true,"filterType":6}}},"CreatedOn":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"CreatedOn"}},"CreatedBy":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"CreatedBy"}},"ModifiedOn":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"ModifiedOn"}},"ModifiedBy":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"ModifiedBy"}},"ProcessListeners":{"caption":"","orderDirection":0,"orderPosition":-1,"isVisible":true,"expression":{"expressionType":0,"columnPath":"ProcessListeners"}}}},"isDistinct":false,"rowCount":30,"rowsOffset":0,"isPageable":true,"allColumns":false,"useLocalization":true,"useRecordDeactivation":false,"serverESQCacheParameters":{"cacheLevel":0,"cacheGroup":"","cacheItemName":""},"queryOptimize":false,"useMetrics":false,"querySource":0,"ignoreDisplayValues":false,"conditionalValues":null,"isHierarchical":false}';
    return $json;
}
function JsonSelectEmailStatus($contactId){
    $json= '{
       "rootSchemaName":"Contact",
       "operationType":0,
       "filters":{
          "items":{
    		 "CustomFilters":{
    			"filterType":1,
    			"comparisonType":3,
    			"isEnabled":true,
    			"trimDateTimeParameterToDate":false,
    			"leftExpression":{
    			   "expressionType":0,
    			   "columnPath":"Id"
    			},
    			"rightExpression":{
    			   "expressionType":2,
    			   "parameter":{
    				  "dataValueType":0,
    				  "value":"'.$contactId.'"
    			   }
    			}
    		 }
    	  },
          "logicalOperation":0,
          "isEnabled":true,
          "filterType":6
       },
       "columns":{
          "items":{
             "DoNotUseEmail":{
                "caption":"Do not use email",
                "orderDirection":0,
                "orderPosition":-1,
                "isVisible":true,
                "expression":{
                   "expressionType":0,
                   "columnPath":"DoNotUseEmail"
                }
             }
          }
       },
       "isDistinct":false,
       "rowCount":30,
       "rowsOffset":0,
       "isPageable":false,
       "allColumns":false,
       "useLocalization":false,
       "useRecordDeactivation":false,
       "serverESQCacheParameters":{
          "cacheLevel":0,
          "cacheGroup":"",
          "cacheItemName":""
       },
       "queryOptimize":false,
       "useMetrics":false,
       "querySource":0,
       "ignoreDisplayValues":false,
       "conditionalValues":null,
       "isHierarchical":false
    }';
    return $json;
}

Unsubscription channels:

<?php
$contactId=$_GET['contactId'];
//contactId for test = 2480fb60-43d1-4a58-9011-0f859b431670 for test
require_once( MODX_CORE_PATH . 'model/bpmintegration/bpm_bulk_subscriptionsFunctions.php');
BPMAuth();
$jsonUseEmailQuery = JsonSelectEmailStatus($contactId);
$result = BPMQuery($jsonUseEmailQuery,4);
$r0 = json_decode($result,true);
$requestData1 = JsonSelectSubscriptions($contactId);
$result = BPMQuery($requestData1,4);
$r=json_decode($result, true);
$requestData1=JsonSelectdefaultchannels();
$result = BPMQuery($requestData1,4);
$r2=json_decode($result, true);
{//building html form 
    echo '<form method = "post" action = "/index.php?id=14&contactId='.$contactId.'">';
    if ($r0["rows"]["0"]["DoNotUseEmail"]==1) {
 
        echo '<h4>You are currently Unsubscribed from all emails, please uncheck Subscribe me back, if you wish to keep current setting on.</h4>';
        echo '<input type="checkbox" name="Subscribemeback" value="1" checked> Subscribe me back <br>';
    }
    echo '<h2>Subsctiption types</h2>';
    //print_r($r);
    foreach ($r["rows"] as $value) {
        echo '<input type="checkbox" style="display:none" name="SubscriptionData[]" value="'.$value["Id"].'" checked>';
        if ($value["BulkEmailSubsStatus"]["displayValue"]=='Subscribed'){
            echo '<input type="checkbox" name="CurrentSubscription[]" value="'.$value["Id"].'" checked> '.$value["BulkEmailType"]["displayValue"].'<br/>';
        }else{
            echo '<input type="checkbox" name="CurrentSubscription[]" value="'.$value["Id"].'"> '.$value["BulkEmailType"]["displayValue"].'<br/>';
        }
        } // Display channels already set for client
    foreach ($r2["rows"] as $value){
        foreach ($r["rows"] as $value1) {
            if ($value["Id"]==$value1["BulkEmailType"]["value"]){
                $exist=1;
            }
        }
     if (!$exist) {
         echo '<input type="checkbox" style="display:none" name="defaultsubscriptionschannels[]" value="'.$value["Id"].'" checked>';
         echo '<input type="checkbox" name="defaultsubscriptions[]" value="'.$value["Id"].'" checked> '.$value["Name"].'<br/>';
     } //if there is no such channel in basic subscription - echo some inputs
     else unset ($exist);
    } // Display Default Channels
    if ($r0["rows"]["0"]["DoNotUseEmail"]!=1) {
        echo ' <h2> OR Unsubscribe from all?</h2>
        <input type="checkbox" name="Unsibscribe_all" value="1"> Unsibscribe from all emails<br>';
    }
    echo '<input type="submit" value="Submit">
    </form>';
}//building form

Unsubscription channel request:

<?php
//$_POST['SubscriptionData']- array with all subscription preferances for current ContactID
//$_POST['CurrentSubscription'] - array with data to be subscribed
//$_POST['Defaultsubscriptions'] -array with default channels to add to subscriptions
//$_POST['defaultsubscriptionschannels'] - array with default channels
$contactId=$_GET['contactId'];
require_once( MODX_CORE_PATH . 'model/bpmintegration/bpm_bulk_subscriptionsFunctions.php');
BPMAuth();
if ($_POST['Subscribemeback']==1){
    $requestData1=ContactUnsubscribe($contactId,false);
    BPMQuery($requestData1,2);
    echo 'You were subscribed back';
}
if ($_POST['Unsibscribe_all']==1){
    $requestData1=ContactUnsubscribe($contactId,true);
    BPMQuery($requestData1,2);
    echo 'Unsubscribed from all';
    } // If Unsubscribed - post "Do no use email in BPM"
    else {
        echo '<h2>Subscription Channels were Updated</h2>';
        if (isset($_POST['CurrentSubscription'])){
            $filter=BuildIdFilter($_POST['CurrentSubscription']);
            $JsonSubscribe=BuildSubscribeJson($filter,true);// Json for Subscription Data
            BPMQuery($JsonSubscribe,2);
            $ToSetUnsubscribed=array_diff($_POST['SubscriptionData'],$_POST['CurrentSubscription']);//this is array to set unsubscribe status
            if (!empty($ToSetUnsubscribed)){
                 $filter=BuildIdFilter($ToSetUnsubscribed);
                 $JsonSubscribe=BuildSubscribeJson($filter,false);
                 BPMQuery($JsonSubscribe,2);
            }
        } 
        elseif(isset($_POST['SubscriptionData'])){
            $filter=BuildIdFilter($_POST['SubscriptionData']);
            $JsonSubscribe=BuildSubscribeJson($filter,false);
            BPMQuery($JsonSubscribe,2);//UpdateBPM
        }
        if (isset($_POST['defaultsubscriptionschannels'])){
            if (isset($_POST['defaultsubscriptions'])){
                $JsonSubscribe=JsonAddNewSubscriber($contactId,$_POST['defaultsubscriptions'],true);
                BPMQuery($JsonSubscribe,3);//UpdateBPM
                $ToAddUnsubscribed=array_diff($_POST['defaultsubscriptionschannels'],$_POST['defaultsubscriptions']);
                if (!empty($ToAddUnsubscribed)){
                    $JsonSubscribe=JsonAddNewSubscriber($contactId,$ToAddUnsubscribed,false);
                    BPMQuery($JsonSubscribe,3);//UpdateBPM
                    }
                }else{
                    $JsonSubscribe=JsonAddNewSubscriber($contactId,$_POST['defaultsubscriptionschannels'],false);
                    BPMQuery($JsonSubscribe,3);//UpdateBPM
                }
            }
        }// Defines array to add new subscription channels
?>

For additional assistance, see the video instruction at https://drive.google.com/file/d/1vJipUf0m04Mk_r3QLAakcwdXYtEon--J/view.

Like 2

Like

Share

0 comments
Show all comments