Hi Community, 

 

I have written a business rule that, when a boolean field has been set to true in the mobile app, stores the current timestamp in another separate date/time field: 

 

Terrasoft.sdk.Model.addBusinessRule("Activity", {
    name: "SetTimestampOnCheckForTriggeredField",
    ruleType: Terrasoft.RuleTypes.Custom,
    triggeredByColumns: [
        "InnEndSiteVisitCheck", "InnEndTravelInCheck", "InnEndTravelOutCheck",
        "InnStartSiteVisitCheck", "InnStartTravelInCheck", "InnStartTravelOutCheck"
    ],
    events: [Terrasoft.BusinessRuleEvents.ValueChanged],
 
    executeFn: function(record, rule, column, customData, callbackConfig) {
        // Mapping of boolean fields to their corresponding date-time fields
        var fieldMapping = {
            "InnEndSiteVisitCheck": "InnEndSiteVisitTime",
            "InnEndTravelInCheck": "InnEndTravelInTime",
            "InnEndTravelOutCheck": "InnEndTravelOutTime",
            "InnStartSiteVisitCheck": "InnStartSiteVisitTime",
            "InnStartTravelInCheck": "InnStartTravelInTime",
            "InnStartTravelOutCheck": "InnStartTravelOutTime"
        };
 
        // Get the boolean value of the triggered field
        var isCheckTrue = record.get(column);
 
        // Check if the boolean field is true
        if (isCheckTrue && fieldMapping[column]) {
            // Set the corresponding date-time field to the current date/time
            var currentDateTime = new Date();
            record.set(fieldMapping[column], currentDateTime);
        }
 
        // Asynchronous callback to indicate the rule has been processed
        Ext.callback(callbackConfig.success, callbackConfig.scope, [true]);
    }
});

 

I now want to be able to show a warning message that gives an option to 'cancel' or 'confirm' when a user attempts to set one of these booleans to false. 

 

The box would need to be shown after an attempt to change the booleans value, halting this action until confirmed  - if the action is not prevented before confirmation and the 'cancel' option merely reverts the boolean to being true, the old timestamp would be lost with the new value being representative of the time of cancellation (which is not what I desire).

 

The following post presents a similar requirement: Pop-up with options in mobile application | Community Creatio

 

However, guidance given points to a push notification (which I can't envision helping as I require an option in the app that temporarily halts the setting of the boolean to false), or to use Terrasoft.MessageBox.showMessage, which from what I can tell can only produce a message box (no option to cancel or confirm). 

 

I have also thought about writing individual rules that set each field to be disabled once it has been checked:

 

// Disable the InnEndSiteVisitCheck field after it is checked
Terrasoft.sdk.Model.addBusinessRule("Activity", {
    name: "DisableInnEndSiteVisitCheck",
    ruleType: Terrasoft.RuleTypes.Activation,
    triggeredByColumns: ["InnEndSiteVisitCheck"],
    events: [Terrasoft.BusinessRuleEvents.Load, Terrasoft.BusinessRuleEvents.ValueChanged],
    conditionalColumns: [
        { name: "InnEndSiteVisitCheck", value: true }
    ],
    dependentColumnNames: ["InnEndSiteVisitCheck"]
});

 

However, this is not as flexible as I would want as users may set field values to true by mistake. Even then, the rule I have written does not seem to work as I get a server error when syncing in the mobile app after adding it - perhaps this is because two rules are initiated by the same event? 

Any help on this would be greatly appreciated, thanks in advance!

Like 1

Like

2 comments
Best reply

Hello,

 

Terrasoft.MessageBox also contains the showConfirmation method that can be called to show the confirmation box:

Also you can specify the callback function that will be called upon clicking the "confirm" button (using the yesCallback function inside the object that is passed as an argument into the showConfirmation method or "negative" button (the noCallback function should be created). So you can use it in your development.

Hello,

 

Terrasoft.MessageBox also contains the showConfirmation method that can be called to show the confirmation box:

Also you can specify the callback function that will be called upon clicking the "confirm" button (using the yesCallback function inside the object that is passed as an argument into the showConfirmation method or "negative" button (the noCallback function should be created). So you can use it in your development.

Hi Oleg,

 

Thanks for your reply, this has helped to develop a solution!

Show all comments

Hello,
I have a slightly urgent question on how to get Address from Account lookup
the code lookslike this
Terrasoft.sdk.Model.addBusinessRule("Activity", {

  name: "LatLongPreFilled",

  ruleType: Terrasoft.RuleTypes.Custom,

  triggeredByColumns: ["Usrcheck_in"],

  events: [

    Terrasoft.BusinessRuleEvents.ValueChanged,

    Terrasoft.BusinessRuleEvents.Save,

  ],

  executeFn: function (model, rule, column, customData, callbackConfig) {

    if (navigator.geolocation) {

      navigator.geolocation.getCurrentPosition(

        function (position) {

          model.set("Usrcheck_in_longitude", position.coords.longitude, true);

          model.set("Usrcheck_in_latitude", position.coords.latitude, true);


 

          var account = model.get("Account").get("Address");


 

          alert(account);

          Ext.callback(callbackConfig.success, callbackConfig.scope);

        },


 

        function (error) {

          alert("Geolocation failed: " + error.message);

          Ext.callback(callbackConfig.success, callbackConfig.scope);

        }

      );

    } else {

      alert("Geolocation is not supported by this browser.");

      Ext.callback(callbackConfig.success, callbackConfig.scope);

    }

  },

});


i use this: var account = model.get("Account").get("Address"); 
but when i test it, displayed on an alert it says "undefined", but this model.get("Account").get("Id"); or model.get("Account").get("Name"); works fine.
Can anyone help me out? 

Thank you.  

Like 1

Like

3 comments

Hello,

 

Please check if the Address column is present in the SyncColumns array of the Account entity in the ModelDataImportConfig array of the mobile application manifest. It seems that the column is not synced so you receive undefined in the debugger.

Oleg Drobina,


Hi Oleg,
thanks for the reply,

should i add manually on Mobile manifest file or via Mobile Application Wizard?
PS: i don't use debugger like console.log, i use javascript's alert function since i use iOS and i have no clue on how to debug mobile apps on a smartphone, especially iOS.

Yanuar Adinagoro Vishnu Saputro,

 

It can be either manually or you can add the Address column to the account edit page and the column should be added to the manifest automatically in this case.

Show all comments

Hi there,

 

I am creating a business rule to auto-populates the field with the current user contact for custom field Owner, but I am not able to find out what should be the action for this and also not able to see the current user option. Please see the screenshot below

Like 0

Like

1 comments

Not possible with rules on classic pages. Best option would be to set it as the default for that column in the object. Select the object and choose the Owner column and set Current User Contact for default value. 
Otherwise, you'd need to get current user and populate via code in the onEntityInitialized - make sure the page is in add mode.

Ryan

Show all comments

Dear colleagues,

 

Any idea how to apply bussiness rules to an editable detail grid schema? just by code?

 

Is very usefull can edit in the grid, but just when have no rules, no read only fields, no filters, no calculated fields and so on.

 

Any ideas?

 

Thanks

 

Regrads

Julio

Like 0

Like

1 comments
Best reply

If i'm not wrong i guess you mean to say you have a inline editable detail without any form page for the user to add details and you want to add some kind of business rules.
You can add them in the object level.


But if you have a form page for the detail,you can do it through code by using handlers.
https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…
 

If i'm not wrong i guess you mean to say you have a inline editable detail without any form page for the user to add details and you want to add some kind of business rules.
You can add them in the object level.


But if you have a form page for the detail,you can do it through code by using handlers.
https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…
 

Show all comments

Hello Community!

 

I'm trying to fill a field with the result of a simple calculation (e.g. field A - field B).

 

However, when I create the business rule and select "set field" as action, I can only provide a constant value and not a formula...am I missing something?

 

Here is a screenshot of the 

 

I know that I can use a business process to achieve this, but this would be much more simpler and elegant I think.

 

BR,

Robert

Like 0

Like

4 comments
Best reply

It's not yet available in Freedom UI --> Creatio Roadmap indicates for Q4 2023 https://academy.creatio.com/docs/release/creatio-roadmap?check_logged_i…

I forgot to add that I use version 8.0.10.4735

It's not yet available in Freedom UI --> Creatio Roadmap indicates for Q4 2023 https://academy.creatio.com/docs/release/creatio-roadmap?check_logged_i…

Damien Collot,

Thanks Damien, at least I know that I did overlook something.

Hi Damien,

I do not have access to the link to the roadmap.

I get this message:

"

Access denied

You are not authorized to access this page.

"

Is it restricted?

It is very interesting information.

Thanks,

Luis

Show all comments

Hey Community,



I'm stuck with problem trying to apply detail business rule on my edit grid. So the problem that business rule is looking to UsrParent.UsrStatus column. And i have the error that this column was deleted or renamed.

I've tried some solutions on Community but nothing is working for me. 

Here is my code:

		methods: {
			onActiveRowAction: function(buttonTag, primaryColumnValue) {
				this.mixins.ConfigurationGridUtilitiesV2.onActiveRowAction.call(this, buttonTag, primaryColumnValue);
			},
 
			generateActiveRowControlsConfig: function(id, columnsConfig, rowConfig) {
				//var gridDataColumns = getGridDataColumns();
				this.columnsConfig = columnsConfig;
				var gridLayoutItems = [];
				var currentColumnIndex = 0;
				this.Terrasoft.each(columnsConfig, function(columnConfig) {
					var cellConfig = this.getActiveRowCellConfig(columnConfig, currentColumnIndex);
       			 if (!cellConfig.hasOwnProperty("isNotFound")) {
            		gridLayoutItems.push(cellConfig);
        		}
					currentColumnIndex += cellConfig.layout.colSpan;
				}, this);
				this.applyBusinessRulesForActiveRow(id, gridLayoutItems);
				var viewGenerator = this.Ext.create(this.getRowViewGeneratorClassName());
				viewGenerator.viewModelClass = this;
				var gridLayoutConfig = viewGenerator.generateGridLayout({
					name: this.name,
					items: gridLayoutItems
				});
				rowConfig.push(gridLayoutConfig);
			},
 
				getGridDataColumns: function() {
                var baseGridDataColumns = this.callParent(arguments);
                var gridDataColumns = {
                    "UsrParent.UsrStatus": {path: "UsrParent.UsrStatus"},
                };
                return Ext.apply(baseGridDataColumns, gridDataColumns);
            }
 
},





thanks!

 

Like 0

Like

6 comments

Hi,

 

Do you add this business rule to the grid schema or to the detail edit page schema? Business rules added to the edit page should work properly without this error.

 

Alternatively try this approach with lookupListConfig in either grid schema and edit page schema of the detail (added to the schema attributes):

"UsrParent": {
                    "dataValueType": this.Terrasoft.DataValueType.LOOKUP,
                    "lookupListConfig": {
                        "columns": ["UsrStatus"]
                    }
                },

this should also get the value (and load itself) of the UsrStatus column.

Oleg Drobina,

Hi!



Thanks for ur answer, i already tried this one added in schema detail/page and still the same issue.

Also copied business-rules from page to detail schema.



Here is full code for Detail schema 

define("RdtSchema670160a3Detail", ["ConfigurationGrid", "ConfigurationGridGenerator",
	"ConfigurationGridUtilitiesV2"], function() {
	return {
		entitySchemaName: "RdtProductionRawProducts",
		attributes: {
			"IsEditable": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
				value: true
			},
 
 
			"RdtProduction": {
                    "dataValueType": this.Terrasoft.DataValueType.LOOKUP,
                    "lookupListConfig": {
                        "columns": ["RdtStatus"]
                    }
                }
		},
		mixins: {
			ConfigurationGridUtilitiesV2: "Terrasoft.ConfigurationGridUtilitiesV2"
		},
		businessRules: /**SCHEMA_BUSINESS_RULES*/{
			"RdtRawProduct": {
				"a51ae6d8-b23d-4245-a06f-6f81a6a20f0d": {
					"uId": "a51ae6d8-b23d-4245-a06f-6f81a6a20f0d",
					"enabled": true,
					"removed": false,
					"ruleType": 1,
					"baseAttributePatch": "RdtType",
					"comparisonType": 3,
					"autoClean": false,
					"autocomplete": false,
					"type": 0,
					"value": "0e937c72-3826-40c0-ac62-30d70746cea0",
					"dataValueType": 10
				},
				"7864a234-ef49-4a9c-ac19-9967fb5b255a": {
					"uId": "7864a234-ef49-4a9c-ac19-9967fb5b255a",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 3,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction",
								"attributePath": "RdtStatus"
							},
							"rightExpression": {
								"type": 0,
								"value": "22c74599-4c04-401e-8dfd-06fde8f8cb81",
								"dataValueType": 10
							}
						}
					]
				}
			},
			"RdtQuantity": {
				"00b698f4-7e53-4a6b-804f-3a2f40e7b015": {
					"uId": "00b698f4-7e53-4a6b-804f-3a2f40e7b015",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 3,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction",
								"attributePath": "RdtStatus"
							},
							"rightExpression": {
								"type": 0,
								"value": "22c74599-4c04-401e-8dfd-06fde8f8cb81",
								"dataValueType": 10
							}
						}
					]
				}
			},
			"RdtUnit": {
				"825f4f2a-f110-4554-9a83-575440727c00": {
					"uId": "825f4f2a-f110-4554-9a83-575440727c00",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 3,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction",
								"attributePath": "RdtStatus"
							},
							"rightExpression": {
								"type": 0,
								"value": "22c74599-4c04-401e-8dfd-06fde8f8cb81",
								"dataValueType": 10
							}
						}
					]
				}
			},
			"RdtAvailableStock": {
				"843f04c6-f4c7-426c-85f3-5560b2383db5": {
					"uId": "843f04c6-f4c7-426c-85f3-5560b2383db5",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 1,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtAvailableStock"
							}
						}
					]
				}
			},
			"RdtNotEnoughStock": {
				"7dccf940-c42c-4b5d-82ab-acff711c7893": {
					"uId": "7dccf940-c42c-4b5d-82ab-acff711c7893",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 1,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction"
							}
						}
					]
				}
			}
		}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			onActiveRowAction: function(buttonTag, primaryColumnValue) {
				this.mixins.ConfigurationGridUtilitiesV2.onActiveRowAction.call(this, buttonTag, primaryColumnValue);
			},
 
			generateActiveRowControlsConfig: function(id, columnsConfig, rowConfig) {
				this.columnsConfig = columnsConfig;
				var gridLayoutItems = [];
				var currentColumnIndex = 0;
				this.Terrasoft.each(columnsConfig, function(columnConfig) {
					var cellConfig = this.getActiveRowCellConfig(columnConfig, currentColumnIndex);
       			 if (!cellConfig.hasOwnProperty("isNotFound")) {
            		gridLayoutItems.push(cellConfig);
        		}
					currentColumnIndex += cellConfig.layout.colSpan;
				}, this);
				this.applyBusinessRulesForActiveRow(id, gridLayoutItems);
				var viewGenerator = this.Ext.create(this.getRowViewGeneratorClassName());
				viewGenerator.viewModelClass = this;
				var gridLayoutConfig = viewGenerator.generateGridLayout({
					name: this.name,
					items: gridLayoutItems
				});
				rowConfig.push(gridLayoutConfig);
			}
		},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "DataGrid",
				"values": {
					"className": "Terrasoft.ConfigurationGrid",
					"generator": "ConfigurationGridGenerator.generatePartial",
					"generateControlsConfig": {"bindTo": "generateActiveRowControlsConfig"},
					"changeRow": {"bindTo": "changeRow"},
					"unSelectRow": {"bindTo": "unSelectRow"},
					"onGridClick": {"bindTo": "onGridClick"},
					"activeRowActions": [
						{
							"className": "Terrasoft.Button",
							"style": this.Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
							"tag": "save",
							"markerValue": "save",
							"imageConfig": {"bindTo": "Resources.Images.SaveIcon"}
						},
						{
							"className": "Terrasoft.Button",
							"style": this.Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
							"tag": "cancel",
							"markerValue": "cancel",
							"imageConfig": {"bindTo": "Resources.Images.CancelIcon"}
						},
						{
							"className": "Terrasoft.Button",
							"style": this.Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
							"tag": "card",
							"markerValue": "card",
							"imageConfig": {"bindTo": "Resources.Images.CardIcon"}
						},
						{
							"className": "Terrasoft.Button",
							"style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
							"tag": "copy",
							"markerValue": "copy",
							"imageConfig": {"bindTo": "Resources.Images.CopyIcon"}
						},
						{
							"className": "Terrasoft.Button",
							"style": this.Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
							"tag": "remove",
							"markerValue": "remove",
							"imageConfig": {"bindTo": "Resources.Images.RemoveIcon"}
						}
					],
					"initActiveRowKeyMap": {"bindTo": "initActiveRowKeyMap"},
					"activeRowAction": {"bindTo": "onActiveRowAction"},
					"multiSelect": {"bindTo": "MultiSelect"}
				}
			}
		]/**SCHEMA_DIFF*/
	};
});

Maybe u have other ideas? 



Much thanks!

Oleksii

Oleksii Protsiuk,

 

Ok, and can you please point me to the business rule from your code that references the UsrParent.UsrStatus column (or is it RdtStatus in the code above)? And also please share the edit page code.

Oleg Drobina,

1. Business rule for RdtQuantity for example.

2. Yes, its RdtStatus.



3. 

define("RdtSchemafaf34ef3Page", [], function() {
	return {
		entitySchemaName: "RdtProductionRawProducts",
		attributes: {
					"RdtProduction": {
                    "dataValueType": this.Terrasoft.DataValueType.LOOKUP,
                    "lookupListConfig": {
                        "columns": ["RdtStatus"]
                    }
                }
		},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{
			"RdtRawProduct": {
				"a51ae6d8-b23d-4245-a06f-6f81a6a20f0d": {
					"uId": "a51ae6d8-b23d-4245-a06f-6f81a6a20f0d",
					"enabled": true,
					"removed": false,
					"ruleType": 1,
					"baseAttributePatch": "RdtType",
					"comparisonType": 3,
					"autoClean": false,
					"autocomplete": false,
					"type": 0,
					"value": "0e937c72-3826-40c0-ac62-30d70746cea0",
					"dataValueType": 10
				},
				"7864a234-ef49-4a9c-ac19-9967fb5b255a": {
					"uId": "7864a234-ef49-4a9c-ac19-9967fb5b255a",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 3,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction",
								"attributePath": "RdtStatus"
							},
							"rightExpression": {
								"type": 0,
								"value": "22c74599-4c04-401e-8dfd-06fde8f8cb81",
								"dataValueType": 10
							}
						}
					]
				}
			},
			"RdtQuantity": {
				"00b698f4-7e53-4a6b-804f-3a2f40e7b015": {
					"uId": "00b698f4-7e53-4a6b-804f-3a2f40e7b015",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 3,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction",
								"attributePath": "RdtStatus"
							},
							"rightExpression": {
								"type": 0,
								"value": "22c74599-4c04-401e-8dfd-06fde8f8cb81",
								"dataValueType": 10
							}
						}
					]
				}
			},
			"RdtUnit": {
				"825f4f2a-f110-4554-9a83-575440727c00": {
					"uId": "825f4f2a-f110-4554-9a83-575440727c00",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 3,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction",
								"attributePath": "RdtStatus"
							},
							"rightExpression": {
								"type": 0,
								"value": "22c74599-4c04-401e-8dfd-06fde8f8cb81",
								"dataValueType": 10
							}
						}
					]
				}
			},
			"RdtAvailableStock": {
				"843f04c6-f4c7-426c-85f3-5560b2383db5": {
					"uId": "843f04c6-f4c7-426c-85f3-5560b2383db5",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 1,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtAvailableStock"
							}
						}
					]
				}
			},
			"RdtNotEnoughStock": {
				"7dccf940-c42c-4b5d-82ab-acff711c7893": {
					"uId": "7dccf940-c42c-4b5d-82ab-acff711c7893",
					"enabled": true,
					"removed": false,
					"ruleType": 0,
					"property": 1,
					"logical": 0,
					"conditions": [
						{
							"comparisonType": 1,
							"leftExpression": {
								"type": 1,
								"attribute": "RdtProduction"
							}
						}
					]
				}
			}
		}/**SCHEMA_BUSINESS_RULES*/,
		methods: {},
		dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "insert",
				"name": "LOOKUPa8ab8309-ec3e-4f7b-b007-af2483101fee",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 0,
						"layoutName": "Header"
					},
					"bindTo": "RdtRawProduct",
					"enabled": false,
					"contentType": 5
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 0
			},
			{
				"operation": "insert",
				"name": "LOOKUPe030f444-90d1-4d98-b476-b4b576c4f122",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 12,
						"row": 0,
						"layoutName": "Header"
					},
					"bindTo": "RdtUnit",
					"enabled": false,
					"contentType": 5
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 1
			},
			{
				"operation": "insert",
				"name": "FLOAT07d52071-3119-4f71-a45f-3e8701a3e127",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 1,
						"layoutName": "Header"
					},
					"bindTo": "RdtQuantity",
					"enabled": false
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 2
			},
			{
				"operation": "insert",
				"name": "RdtAvailableStockbd49a463-5f7d-4a67-aaa6-f01f7cca4cd9",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 12,
						"row": 1,
						"layoutName": "Header"
					},
					"bindTo": "RdtAvailableStock",
					"enabled": false
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 3
			},
			{
				"operation": "insert",
				"name": "RdtNotEnoughStockb7a3c879-7054-4bf6-8434-adb226c77730",
				"values": {
					"layout": {
						"colSpan": 12,
						"rowSpan": 1,
						"column": 0,
						"row": 2,
						"layoutName": "Header"
					},
					"bindTo": "RdtNotEnoughStock",
					"enabled": false
				},
				"parentName": "Header",
				"propertyName": "items",
				"index": 4
			}
		]/**SCHEMA_DIFF*/
	};
});



 

The same problem with setting the value of the field using connected entity column on the different detail.

1. The field value is showing on field

2. After save the same error and the field is empty.





Is there any chance to fix this error ?



Thanks!

I'm also experiencing this issue, however looks like this thread has gone cold.... 

Show all comments

How can i hide / show a field based on the user role in freedom UI with business rules or with js code?

Thank you

Like 2

Like

7 comments
Best reply

You can do this with code on a Freedom UI page. 

1) Make sure you add "@creatio-devkit/common" to the page as sdk

2) First add an attribute to the viewModelConfig. I'll call the attribute "IsUserInRole since we'll set it to true/false if the user is in the role. 

viewModelConfig: /**SCHEMA_VIEW_MODEL_CONFIG*/{
    "attributes": {
        "IsUserInRole": {}
    }
}/**SCHEMA_VIEW_MODEL_CONFIG*/

3) Bind the attribute to the visible property of the control by adding the following to the control in the viewModelDiff

"visible": "$IsUserInRole"

4) Now when the view model is initialized, basically the Freedom UI equivalent of the onEntityInitialized on classic pages, do a query using the model to determine if the current user is in the role. We'll use that result to set the attribute:

{
    request: "crt.HandleViewModelInitRequest",
    handler: async (request, next) => {
        await next?.handle(request);
        // get current user
        const sysValuesService = new sdk.SysValuesService();        
        const sysValues = await sysValuesService.loadSysValues();
        const currentUserContact = sysValues.userContact;
 
        // create model query
        userRoleModel = await sdk.Model.create("SysUserInRole");
        const filter = new sdk.FilterGroup();
        await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SysRole.Name", "The Role Name Here");
        await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SysUser.Contact", currentUserContact.value);
 
        // workaround for filters, will be fixed in 8.1
        const newFilter = Object.assign({}, filter);
        newFilter.items = filter.items;
 
        const results = await userRoleModel.load({
            attributes: ["Id"],
            parameters: [{
                type: sdk.ModelParameterType.Filter,
                value: newFilter
            }]
        });
 
        // now set attribute
        request.$context.IsUserInRole = results.length > 0;
    }
}

I didn't test that code, but it should be pretty close. If anything you might need to play with the filter for the model query.

Ryan

Hello,

 

Unfortunately, there is no way to add visibility to the field based on user role via Section Wizard.

 

But we've registered it in our R&D team backlog for consideration and implementation in future application releases.

 

Thank you for helping us to improve our product. 

Bogdan,

but is it possible to calculate page parameter based on Operation permission? And then use this parameter in business rule?

You can do this with code on a Freedom UI page. 

1) Make sure you add "@creatio-devkit/common" to the page as sdk

2) First add an attribute to the viewModelConfig. I'll call the attribute "IsUserInRole since we'll set it to true/false if the user is in the role. 

viewModelConfig: /**SCHEMA_VIEW_MODEL_CONFIG*/{
    "attributes": {
        "IsUserInRole": {}
    }
}/**SCHEMA_VIEW_MODEL_CONFIG*/

3) Bind the attribute to the visible property of the control by adding the following to the control in the viewModelDiff

"visible": "$IsUserInRole"

4) Now when the view model is initialized, basically the Freedom UI equivalent of the onEntityInitialized on classic pages, do a query using the model to determine if the current user is in the role. We'll use that result to set the attribute:

{
    request: "crt.HandleViewModelInitRequest",
    handler: async (request, next) => {
        await next?.handle(request);
        // get current user
        const sysValuesService = new sdk.SysValuesService();        
        const sysValues = await sysValuesService.loadSysValues();
        const currentUserContact = sysValues.userContact;
 
        // create model query
        userRoleModel = await sdk.Model.create("SysUserInRole");
        const filter = new sdk.FilterGroup();
        await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SysRole.Name", "The Role Name Here");
        await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SysUser.Contact", currentUserContact.value);
 
        // workaround for filters, will be fixed in 8.1
        const newFilter = Object.assign({}, filter);
        newFilter.items = filter.items;
 
        const results = await userRoleModel.load({
            attributes: ["Id"],
            parameters: [{
                type: sdk.ModelParameterType.Filter,
                value: newFilter
            }]
        });
 
        // now set attribute
        request.$context.IsUserInRole = results.length > 0;
    }
}

I didn't test that code, but it should be pretty close. If anything you might need to play with the filter for the model query.

Ryan

Thank you. That helps a lot.

Ryan Farley,



I have tried a similar case, where on saving a record writing a validation to check whether it has unique "Code".

 

request: "crt.SaveRecordRequest",handler: async (request, next) => {
// Add any code to execute *before* the save here
 
var accountModel = await sdk.Model.create("Account");
 
const filter = new sdk.FilterGroup();
var codeValue = await request.$context.StringAttribute_enupz4g;
await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "SMCode", codeValue);
 
	const newFilter = Object.assign({}, filter);
	newFilter.items = filter.items;
 
	const accounts = await accountModel.load({
		attributes: ["Id"],
		parameters: [{
		type: sdk.ModelParameterType.PrimaryColumnValue,
		value: newFilter
		}]
	});
	if(accounts.length > 0){
		isSave = false;
		//Show warning Message
		request.$context.executeRequest({
		type: "crt.ShowDialogRequest",
		$context: request.$context,
		dialogConfig: {
		data: {
		message: "Code already already exists",
		actions: [{
			key: "OK",
			config: {
			color: "primary",
			caption: "OK"
			}
		}]
		}
		}
	});
	}
else{
return next.handle(request);
}
}



I followed your code to check any account has the similar code. Seems like, there is an issue in the filter it throws the below error.







Can you help me in adding the proper filter in this Freedom UI? Or provide a sample code to add filters to retrive data from an entity.



Regards,

Adharsh S

Adharsh,

Change this part: 

const accounts = await accountModel.load({
	attributes: ["Id"],
	parameters: [{
		type: sdk.ModelParameterType.PrimaryColumnValue,
		value: newFilter
	}]
});

To this: 

const accounts = await accountModel.load({
	attributes: ["Id"],
	parameters: [{
		type: sdk.ModelParameterType.Filter,
		value: newFilter
	}]
});

Note, the difference in type. You're specifying a filter, not providing a primary column value. 

Ryan

This is a very common requirement for all clients, this really should be added to the no code Page Designer. Similarly with Operation permissions to be used in visibility conditions.

Show all comments

Hi,

I'm trying to add business rules in the freedom UI but looks like they are way less advanced than the business rules in the Classic UI. 

Is that right or am I missing something?

I want to do the following: If Project is filled in THAN School.Semester = Project.Semester 

(school object has a lookup field Project), it was possible to add this to the classic UI but I can't find a way to get a value from another field, just constant.

Waiting for your answer and hope there is a way. otherwise, the freedom UI is great but this feature of business rules is used so many times by us and I would have to go back to the classic ui after all the work I've done.

Thanks in advance,

Chani

Like 1

Like

4 comments

You need Creatio 8.0.9 https://academy.creatio.com/docs/release/release-notes/809-atlas-releas…



"Business rules 

Filters for dropdown fields. It is now possible to filter available values of a dropdown field by selected value of another dropdown field in Freedom UI using business rules. For example, filter cities by selected country."



Single reason why we have not switched the contact/accounts sections to Customer 360 app yet.

Damien Collot,

I have 8.0.9 and can filter dropdown by other values but still can't set field value from connected objects like I can in Classic UI.

Damien Collot,

But it doesn't work in Mobile app yet. Waiting for next release :)

Damien Collot,

Any updates on this??

Thanks

Show all comments

Hi community!

I am trying to add some validation in Lead section by setting business rules.

I need to make one field mandatory at two specific Lead stages for specific Customer needs.

As I am unable to group conditions I created like 5 different business rules. It seems it works only if one of them is enabled. If I have like both of them enabled then validations don't apply.

 

some examples:

 

 

Like 0

Like

3 comments

Hello,

 

this is correct, usually you cannot set more than 1 rule for a specific field.

 

The thing is that the system needs one parameter to change a fileld specified in the rule, and once there are two or more rules, the system does not understand which one to use, as the result - only one can be applied.

 

The good news is that group conditions are being developed and this feature should be enabled in the nearest verstion of the system.

 

Regards,

Gleb.

Gleb,

Thanks Gleb, did you know in what release this feature will be implemented?

Julio Falcon (Cibernética),

 

This feature was implemented in version 8.0.3, Freedom UI.

Show all comments