How to force column value retrieval even if it's hidden from the DataTable in the list view

Hi there. 

The goal is to adjust visibility of row toolbar Item depending on the value of the field of corresponding record. I added necessary column (ClvSaleStatus) to the list in Freedom UI designer, so all the changes to viewConfigDiff, viewModelConfigDiff and modelConfigDiff look to be present. But nevertheless, If i hide that column manually in the list page then corresponding attribute has undefined value and toolbar item is not visible

viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
	{
		"operation": "merge",
		"name": "DataTable",
		"values": {
			"columns": [
				...
				{
					"id": "791d9bca-eac2-a585-0b1f-8ebacf4e2fa4",
					"code": "PDS_ClvSaleStatus",
					"path": "ClvSaleStatus",
					"caption": "#ResourceString(PDS_ClvSaleStatus)#",
					"dataValueType": 10,
					"referenceSchemaName": "ClvSaleStatus"
				}
			],
			"rowToolbarItems": [
				...
				{
					"type": "crt.MenuItem",
					"caption": "#ResourceString(ReserveObjectMenuItemCaption)#",
					"icon": "open-button-icon",
					"disabled": "$Items.PrimaryModelMode | crt.IsEqual : 'create'",
					"visible": "$Items.PDS_ClvSaleStatus | clv.IsObjectForSaleConverter",
					"clicked": {
						"request": "crt.ClvReserveObjectRequest",
						"params": {
							"itemsAttributeName": "Items",
							"recordId": "$Items.PDS_Id"
						}
					}
				}
			]
		}
	}
...
]/**SCHEMA_VIEW_CONFIG_DIFF*/
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
	...
	{
		"operation": "merge",
		"path": [
			"attributes",
			"Items",
			"viewModelConfig",
			"attributes"
		],
		"values": {
			...
			"PDS_ClvSaleStatus": {
				"modelConfig": {
					"path": "PDS.ClvSaleStatus"
				}
			}
		}
	},
]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/
modelConfigDiff: /**SCHEMA_MODEL_CONFIG_DIFF*/[
	{
		"operation": "merge",
		"path": [
			"dataSources",
			"PDS",
			"config"
		],
		"values": {
			"entitySchemaName": "ClvObject",
			"attributes": {
				...
				"ClvSaleStatus": {
					"path": "ClvSaleStatus"
				}
			}
		}
	}
]/**SCHEMA_MODEL_CONFIG_DIFF*/,
converters: /**SCHEMA_CONVERTERS*/{
	"clv.IsObjectForSaleConverter": function(value) {
		const result = value?.value == ClvJsConsts.ClvSaleStatus.ForSale;
		return result;
	}
}/**SCHEMA_CONVERTERS*/,
Like 0

Like

4 comments

Hi, here is an example of how to get the column value:

viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
			{
				"operation": "insert",
				"name": "DataGrid_3c1xo0k",
				"values": {
					----
					"columns": [
						------
						{
							"id": "a68e978a-790d-9af6-974e-c102ee0bd00e",
							"code": "DataGrid_3c1xo0kDS_Stage",
							"path": "Stage",
							"caption": "#ResourceString(DataGrid_3c1xo0kDS_Stage)#",
							"dataValueType": 10,
							"referenceSchemaName": "OpportunityStage"
						}
					],
					"rowToolbarItems": [
						{
							"type": "crt.MenuItem",
							"caption": "Test",
							"icon": "open-button-icon",
							"disabled": false,
							"visible": "$DataGrid_3c1xo0k.DataGrid_3c1xo0kDS_Stage | clv.IsObjectForSaleConverter",
							------
			},
-----
		]/**SCHEMA_VIEW_CONFIG_DIFF*/,
		viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
			{
				"operation": "merge",
				"path": [
					"attributes"
				],
				"values": {
					-----
					"DataGrid_3c1xo0k": {
						"isCollection": true,
						"modelConfig": {
							"path": "DataGrid_3c1xo0kDS"
						},
						"viewModelConfig": {
							"attributes": {
								"DataGrid_3c1xo0kDS_Title": {
									"modelConfig": {
										"path": "DataGrid_3c1xo0kDS.Title"
									}
								},
								"DataGrid_3c1xo0kDS_Stage": {
									"modelConfig": {
										"path": "DataGrid_3c1xo0kDS.Stage"
									}
								},
-----
					}
				}
			}
		]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
		modelConfigDiff: /**SCHEMA_MODEL_CONFIG_DIFF*/[
			----
		]/**SCHEMA_MODEL_CONFIG_DIFF*/,
		handlers: /**SCHEMA_HANDLERS*/[]/**SCHEMA_HANDLERS*/,
		converters: /**SCHEMA_CONVERTERS*/{
			"clv.IsObjectForSaleConverter": function(value) {
				const result = value?.value == "test";
				return result;
			}
		}

Dmytro Vovchenko,

Well I didn't see any difference to mine code except that you are probably making it for detail and thus inserting new collection attribute "DataGrid_3c1xo0k" while my code is for section and thus merges new attribute to some collection attribute called "Items" which is added in BaseGridSectionTemplate schema.

Anyway, I solved my task by jsut making "clv.IsObjectForSaleConverter" async and requesting column value from db if it's hidden from the list

converters: /**SCHEMA_CONVERTERS*/{
	"clv.IsObjectForSaleConverter": async function(value, scope) {
		let result = value?.value == ClvJsConsts.ClvSaleStatus.ForSale;
		if (!result && !value) {
			const currentRecId = await scope.PDS_Id;
			if(sdk.isGuid(currentRecId)) {
					  const dataModel = await sdk.Model.create("ClvObject");
 
					  const filters = new sdk.FilterGroup();
 
					  filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Id", currentRecId);
 
					  const records = await dataModel.load({
						  attributes: ["Id", "ClvSaleStatus"],
						  parameters: [{
							  type: sdk.ModelParameterType.Filter,
							  value: filters
						  }
				]
					  });
					  const firstRecord = records[0];
					  const recSaleStatusId = firstRecord?.ClvSaleStatus?.value;
					  result = recSaleStatusId == ClvJsConsts.ClvSaleStatus.ForSale;
			}
		}
		return result;
	}
}/**SCHEMA_CONVERTERS*/,

 

Dmytro Vovchenko,

Ok, I rewrote viewModelConfigDiff to exactly match yours

{
	"operation": "merge",
	"path": [
		"attributes",
	],
	"values": {
		"Items": {
			"viewModelConfig": {
				"attributes": {
 
					"PDS_ClvSaleStatus": {
						"modelConfig": {
							"path": "PDS.ClvSaleStatus"
						}
					},
 
				}
			}
		}
	}
},

And it didn't help. If I hide column from the list => I get value argument of converter clv.IsObjectForSaleConverter as undefined. 

 

I looked into data saved to profile when hiding column from the list and it appears that it also modifies  viewModelConfigDiff and contains next snippet.

"viewModelConfigDiff": [
 
	{
		"operation":"remove",
		"path":[
			"attributes",
			"Items",
			"viewModelConfig",
			"attributes"
		],
		"properties":[
			"PDS_ClvSaleStatus"
		]
	}
]

 

The main point I experimented with is how to apply a converter in this line:

"visible": "$DataGrid_3c1xo0k.DataGrid_3c1xo0kDS_Stage | clv.IsObjectForSaleConverter"

When it was filled incorrectly, I saw the same problem behavior that you described. The example I provided should tell you how it needs to be filled. Please check this part in your code.

Show all comments