Passing data from widget server script to html template

Austin27
Tera Contributor

Hello community. I'm having a hard time following various different posts on getting my datetime returned to the html client page. In the Service Portal Widget Editor Page in designer mode, I can show the datetime. But on the html page of the service portal I get undefined. I'm not sure what I'm overlooking or missing. I've tried also using the this.server.get parameter but I don't get a response back only the json string. I don't think I was using the this.server.get parameter correctly and was probably over complicating things that way. So below is what I have that allows me to see the datetime in the service portal widget editor, but need to pass it to the html template too. Thanks for the second set of eyes and any help would be appreciated! Thank you and have a good rest of your day. 

 

// SERVER SCRIPT
(function() {
    /* populate the 'data' object */
    /* e.g., data.table = $sp.getValue('table'); */
    data.sys_id = $sp.getParameter("sys_id");
	
    var widgetGr = new GlideRecord("sp_widget");
    widgetGr.addQuery("sys_id", data.sys_id);
    widgetGr.query();
    while (widgetGr.next()) {
        // Retrieve the sys_updated_on field value as a GlideDateTime object
        var modifiedTime = widgetGr.getValue("sys_updated_on").toString();
			  data.modifiedTime = modifiedTime;
        //var gdt = new GlideDateTime(sysUpdateOn);

        // Format the date using the desired format
        // Note: gdt.getDate() returns a GlideDate object, which has the getByFormat() method
        //var formattedDate = gdt.getDate().getByFormat("MMM dd, yyyy");

        // Store the formatted date in the data object
        //data.time = formattedDate;

    }
})();

 

//CLIENT SCRIPT
function($scope, $sce) {
    var c = this;
    alert(JSON.stringify(c.data.modifiedTime));
    // array of option names
    var optionNames = ['service_intro_text', 'features_text', 'designed_for_text', 'rates_text', 'getting_started_text', 'getting_assistance_text', 'learn_more_text'];

    // Function to update the trusted HTML for a given option
    function updateTrustedHtml(optionName) {
        $scope.$watch('c.options.' + optionName, function(newValue) {
            c[optionName + '_html'] = $sce.trustAsHtml(newValue);
        });
    }

    // Initialize and watch each option
    optionNames.forEach(function(optionName) {
        updateTrustedHtml(optionName);
    });
}

 

<!-- HTML CODE -->
<p ng-bind-html="c.data.modifiedTime"></p>