HandleViewModelResumeRequest works only once

Hi everybody, I have a simple code:

{
	request: "crt.HandleViewModelResumeRequest",
	handler: async (request, next) => {
		await next?.handle(request);
		const cardState = await request.$context.CardState;
		if (cardState === 'add' || cardState === 'copy') {
			// prepare fields
			request.$context.UsrLanguage_d00q91z = {value: "6ebc31fa-ee6c-48e9-81bf-8003ac03b019", displayValue: "English (United States)"};
		}
	}
},

the thing is, that it correctly enters the code everytime, but fills UsrLanguage_d00q91z with the desired value only once - after the local cache was deleted (or page was refreshed). The next time code works, but on the opened page UsrLanguage_d00q91z is empty. Why?!

PS. Unfortunately I can't use for some reasons default values set for object fields.

Like 0

Like

1 comments

Hi Dmitry,

Currently, the only option is to wrap the value setting in setTimeout:

{
	request: "crt.HandleViewModelResumeRequest",
	handler: async (request, next) => {
		await next?.handle(request);
		const cardState = await request.$context.CardState;
		if (cardState === 'add' || cardState === 'copy') {
			// prepare fields
			setTimeout(() => {
				request.$context.UsrLanguage_d00q91z = {
					value: "6ebc31fa-ee6c-48e9-81bf-8003ac03b019",
					displayValue: "English (United States)"
				};
			}, 300);
		}
	}
},

The problem is already registered on the R&D team, and we hope to see the fix in future releases.

Show all comments