Custom Angular component issue: recordId becomes undefined on second open

Hi Creatio Community!
I’m currently working on a custom Angular component (Freedom UI) and ran into an issue I hope someone has already dealt with. I created a custom table component that loads data from a web service — the structure is quite complex with nested records, so I chose to use a service instead of standard object bindings.

I'm receiving the current record ID like this:

@Input()
@CrtInput()
public recordId!: { value: string; displayValue: string };

This is how I set recordId into component

{
	"operation": "insert",
	"name": "CustomTable",
	"values": {
		"recordId": "$UsrContractConditionsGroupDS_UsrContract_c00dfo4",
		"type": "usr.Table"
	},
	"parentName": "ListOfTarrifGroupByPeriod_ExpansionPanel",
	"propertyName": "items",
	"index": 0
},

When I open the page for the first time, everything works fine — the recordId arrives as expected. 

But when I back to section and open this record again, the component throws an error because recordId is undefined, and my table is empty.

I’m calling the service directly in ngOnInit().

Could you please advise on the correct way to store the record ID in the component so that it doesn’t get lost when opening the page a second time?

 

Like 0

Like

1 comments

Hello Artem,

 

You can store record ID in the custom attribute and populate its value when the page is opening in the request crt.HandleViewModelInitRequest.

 

viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
	{
		"operation": "merge",
		"path": [
			"attributes"
		],
		"values": {
			"RecordId": {}
			...
		}
	}
	...
]
handlers: [
	{
		request: "crt.HandleViewModelInitRequest",
		handler: async (request, next) => {
			await next?.handle(request);
			request.$context.RecordId = request.$context.Id;
		}
	}
]

Then you can use this custom attribute in your component

 

{
	"operation": "insert",
	"name": "CustomTable",
	"values": {
		"recordId": "$RecordId",
		"type": "usr.Table"
	},
	"parentName": "ListOfTarrifGroupByPeriod_ExpansionPanel",
	"propertyName": "items",
	"index": 0
},
Show all comments