How do I access Widget configuration properties from a .jsm file

Former Member
Former Member

Hello,

I have a Widget property named dashboardId defined like this:

I need to pass the dashboardId value to a .jsm file that I have in my widget.  Am I able to pass in this value via core_v2_widget.ExecuteFile?  Or, is there a way to access configuration directly from a .jsm file?

Thank you,

Chris

  • You can pass parameters through core_v2_widget.ExecuteFile() or use the same core_v2_widget.GetStringValue('dashboardId', 'default_value') call you'd use in Velocity.

    The APIs exposed to Velocity and Server-side Javascript are the same, just slightly different language-specific execution syntax.

  •  Hi  

    The direct way to access configuration is " core_v2_widget.GetStringValue('dashboardId', 'default_value') " but it works in the widget "Content" section(not jsm files).



    I suggest you getting the parameters from the "Content" section like this:

    " var dashboardId = core_v2_widget.GetStringValue('dashboardId', '');  " 





    then execute your jsm file with the parameters like this:

    var result = core_v2_widget.ExecuteFile("main.jsm", { Parameters:{dashboardId: dashboardId} }); "





    then get your parameters from the jsm file:

    " var dashboardId = core_v2_widget.GetExecutionParameterValue("dashboardId"); "




    Also, you can check the result via "core_v2_eventLog" (" core_v2_eventLog.Write("Your id is: "+dashboardId); "):
     




  • The direct way to access configuration is " core_v2_widget.GetStringValue('dashboardId', 'default_value') " but it works in the widget "Content" section(not jsm files).

    This is not true. core_v2_widget.GetStringValue('propertyId', 'default_value') will work equally well in the main script, manually executed JSM attachments as well as attachments executed via core_v2_widget.GetExecutedFileUrl-based callbacks. It is not *required* to use parameters on core_v2_widget.ExecuteFile() to pass configuration values.

  •  

    I wrote:

    The direct way to access configuration is " core_v2_widget.GetStringValue('dashboardId', 'default_value') " but it works in the widget "Content" section(not jsm files).


    because I catch several times the issue that jsm file didn't has access to the configuration values.

    Here is the case: I created a widget with the JSM file(this file got configuration values and worked fine). Later I imported the widget to another community added it on the page, set configuration but the widget stopped work. After debugging I found that jsm file doesn't get the configuration(I've got this intermittent failure several times).

  • Could you provide a minimal implementation widget that shows this issue? If this is reproducible, it is a bug that should be resolved.

    The context for executing a widget is preserved through execution stacks and callbacks, including both the original URLs contextual data (contextual content, URL name, layout details) as well as configuration. Local variables are also persisted with respect to execution context changes (see  Embedded Script Interoperability   ) through the execution stack but not through callbacks. This is the design and I have verified this behavior with the attached widget.

    <scriptedContentFragments>
    	<scriptedContentFragment name="Configuration Accessibility Test" version="11.0.0.0" description="" instanceIdentifier="9926a55c51b24cf79c89ccb7e6155e53" theme="" isCacheable="false" varyCacheByUser="false" showHeaderByDefault="true" cssClass="" lastModified="2021-04-01 17:59:37Z">
    		<contentScript language="Velocity"><![CDATA[$core_v2_widget.ExecuteFile('callback.jsm')
    <script type="text/javascript">
        jQuery(function() {
            jQuery.telligent.evolution.get({
                url: '$core_v2_encoding.JavascriptEncode($core_v2_widget.GetExecutedFileUrl('callback.jsm'))'
            }).then(function(response){
                alert(response);
            })
        })
    </script>]]></contentScript>
    		<headerScript language="Velocity" />
    		<configuration><![CDATA[<propertyGroup id="options" labelText="Options">
        <property id="property" dataType="string" labelText="Property" />
    </propertyGroup>]]></configuration>
    		<additionalCssScript language="Velocity" />
    		<files>
    			<file name="callback.jsm">cmV0dXJuIGNvcmVfdjJfd2lkZ2V0LkdldFN0cmluZ1ZhbHVlKCdwcm9wZXJ0eScsICcnKTs=</file>
    		</files>
    	</scriptedContentFragment>
    </scriptedContentFragments>