Unable to Set iFrame 'src' Dynamically from System Variable

Hi Creatio Community,
 

I’m trying to set the src of an iFrame dynamically using a system variable (SysSettings). While I can successfully retrieve the URL, I’m unable to bind it to the src property of usr.FrameComponent.

My Approach

I fetch the system setting using SysSettingsService.getByCode() inside crt.HandleViewModelResumeRequest:

 

handlers: /**SCHEMA_HANDLERS*/[
{
                request: "crt.HandleViewModelResumeRequest",
                handler: async (request, next) => {
                    await next?.handle(request);
 
                    try {
                        /* Ensure SysSettingsService is correctly initialized */
                        const sysSettingsService = new common.SysSettingsService();
                        var defaultSrc = await sysSettingsService.getByCode("SmartenIFrameSrc");
                        console.log("Src URL:", defaultSrc.value);
                      /* Set the fetched value into the ViewModel */
                        request.$context.SmartenIFrameSrc.value = defaultSrc;
                    } catch (error) {
                        console.error("Error retrieving SysSettings:", error);
                    }
 
                    return next?.handle(request);
                },
            },
] /**SCHEMA_HANDLERS*/

 

Then, I try binding it in the UI:

 

viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
...,
            {
        "operation": "insert",
        "name": "UsrSmartenIFrameSrc",
        "values": {
            /* The property that handles the text contained in the element. Bound to the "SmartenIFrameSrc" attribute. */
          "type": "crt.Label",
            "caption": "$SmartenIFrameSrc",
        },
    },
    {
				"operation": "insert",
				"name": "Label_mmxxxre",
				"values": {
					"layoutConfig": {
						"column": 1,
						"row": 1,
						"colSpan": 1,
						"rowSpan": 18
					},
					"type": "usr.FrameComponent",
					"src": "$SmartenIFrameSrc" ,
                  // "src": "$defaultSrc" ,
 
				},
				"parentName": "GridContainer_Sales",
				"propertyName": "items",
				"index": 0
			},
			...
    ]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
 
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
    ...
           {
                "operation": "merge",
                "path": ["attributes"],
                "values": {
                    "SmartenIFrameSrc": { "value": "" }  // Initialize with an empty value
                }
            },
            ...
            ]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,

 

Issue

  • The URL logs correctly in the console.
  • But the FrameComponent does not update the src dynamically.

What I Tried

  • Checking if SmartenIFrameSrc updates in the ViewModel (it does).
  • Using different binding methods like $context.SmartenIFrameSrc.
  • Setting a default static URL (which works, proving the issue is with dynamic binding).

Has anyone faced this issue before? How can I properly bind a system setting value to the src property of usr.FrameComponent?
 

Thanks in advance!

 

 

Like 0

Like

0 comments
Show all comments