Service portal widget - cached version

Colleen
Tera Expert

I have built a ServiceNow widget (cvs_adm_assign_report_form) to implement a form  Form fields are implemented as inline HTML and embedded widgets.  I have added a new radio button field as inline HTML and another field as an embedded widget.  Both fields are contained in a fieldset with an ng-if condition.

        <fieldset ng-if="c.isAccountAdmin">
            <div class="form_group">
                <label>Show courses</label>
                <div>
                    <label class="radio-inline">
                        <input type="radio" name="course_query_filter" value="teacher" ng-model="c.courseFilter" /><span>Enrolled as Teacher</span>
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="course_query_filter" value="account" ng-model="c.courseFilter" /><span>In My Sub-Accounts</span>
                    </label>
                </div>
            </div>
            <div class="form_group" ng-show="c.courseFilter=='account'">
                <label>Sub-Account</label>
                <widget id="cvs_adm_acct_picker" options='{"root_filter":"account_list"}'></widget>
            </div>
        </fieldset>

The issue is that the the new fields are NOT displayed even if the ng-if condition is true until the page is refreshed.  I am not seeing any errors in the browser console log.

 

I know that we can append a version number to a JavaScript reference in a UI macro to force the browser to ignore the cached script version. How can we do something similar with an angularjs widget in service portal?

1 ACCEPTED SOLUTION

Colleen
Tera Expert

@Tushar  

It now looks like the cause is an error in my code rather than a caching issue.  Thanks for your help.

View solution in original post

4 REPLIES 4

Tushar
Kilo Sage
Kilo Sage

Hi @Colleen ,

 

Can you try be appending a version number to the widget's JavaScript reference.

 

For eg -

<script src="//services.servicenow.com/cvs_adm_assign_report_form.js"></script>

to:

<script src="//services.servicenow.com/cvs_adm_assign_report_form.js?v=1.0.0"></script>

The v=1.0.0 part is the version number.

This will tell the browser to ignore the cached version of the JavaScript code and load the new version.

 

also use the AngularJS $cacheFactory service to clear the cache for a specific widget.

For eg -

angular.module('myApp').service('$cacheFactory', function($cacheFactory) {
  var cache = $cacheFactory.get('cvs_adm_assign_report_form');
  cache.removeAll();
});

This will force the browser to re-evaluate the ng-if condition and display the new fields.

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

 

Hi Tuhar

 

Where do I find the <script> reference so that I can append the version number? I am not seeing anywhere in the service portal page editor or page designer where I can edit the underlying page code.

 

Colleen

I am now doubtful that it is a caching issue, as I am having the same problem when I use the browser in private / incognito mode.

Colleen
Tera Expert

@Tushar  

It now looks like the cause is an error in my code rather than a caching issue.  Thanks for your help.