dialog window in client script - alternative for service portal needed

LG2
Mega Expert

Hi,

we have a client script which opens a new window for some terms and conditions acknowledgement which is not working for the Service Portal.

Ihave found other references which relate to a widget but the ts&cs only need to appear under certain circumstances (which is controlled by a - working - UI script).

here is our script (which runs on all UIs) - can anyone suggest what we need to change please so that it will run on all UIs?

thanks in advance!

 

function onChange(control, oldValue, newValue, isLoading) {
   if( newValue == 'agree'){
      var dialog = new GlideDialogWindow('terms_and_conditions_dialog'); //Render the dialog containing the UI Page 'terms_and_conditions_dialog'
   dialog.setTitle('Terms and Conditions'); //Set the dialog title
   dialog.setSize(600,600); //Set the dialog size
   dialog.removeCloseDecoration(); //Remove the dialog close icon
   dialog.setPreference('cancel_url', 'catalog_home.do?sysparm_view=catalog_default'); //Set optional cancel redirect URL
   dialog.render(); //Open the dialog
   }
}

1 ACCEPTED SOLUTION

LG2
Mega Expert

In the end we put the ts&cs into a macro with label variable and embedded them into a widget for the Service Portal with a variable width specified for the display. Not perfect, but the ts&cs are at least visible now.

View solution in original post

11 REPLIES 11

Shreeharsh Basa
Tera Expert

Not sure whether it will work on change client script, but it worked for me in the SP widget client controller. But you can give it a try.

 

function(spModal) {
  var c = this;
  // more control, passing options
    c.onConfirmEx = function() {
        c.confirmed = "asking";
        var warn = '<i class="fa fa-warning" aria-hidden="true"></i>';
        spModal.open({
            title: 'Delete this Thing?',
            message: warn + ' Are you <b>sure</b> you want to do that?'
        }).then(function(confirmed) {
            c.confirmed = confirmed;
        })
    }
}

woodyfairley
Tera Guru

If I had a terms and conditions dialog required for a service portal widget, I think I would add a field to the table containing the catalog items of type translated html or translated text, then add the terms and conditions as a value for the appropriate record. Then the field value can be assigned to a variable in the client script for display with the spModal class using the sample code for this method, the cute code that offers terms and conditions for apple (opens in new window):

https://developer.servicenow.com/app.do#!/api_doc?v=london&id=SPM-open_O 

The sample code actually incorporates the text of the terms and conditions into the script, which is one approach, which seems much easier than my recommendation for assigning the text to a field, but then if the t & c are unique to different catalog items or different users, then the best approach might be to construct a table to contain the various t & c as records which can then be referenced in the client script. In my case, I am storing the standard language defining a specific service level agreement (SLA) and then when the customer adds a service to the shopping cart, the text of the sla is captured (along with other relevant information including payment codes) for use in a MS Word document template which will be signed by the customer and the provider. The sample code is here:

//HTML template
<button ng-click="c.onAgree()" class="btn btn-default">
    Agree
  </button>
  <div ng-show="c.agree">
    You answered {{c.agree}}
  </div>

//Client script
function(spModal) {
  var c = this;
  c.onAgree = function() {
        // ask the user for a string
        // note embedded html in message
        var h = '<h4>Apple likes people to agree to lots of stuff</h4>'
        // Line feeds added to the following lines for presentation formatting.
        var m = 'Your use of Apple software or hardware products is based 
on the software license and other terms and conditions in effect for the 
product at the time of purchase. Your agreement to these terms is required 
to install or use the product. '
        spModal.open({
            title: 'Do you agree?',
            message: h + m,
            buttons: [
                {label:'✘ ${No}', cancel: true},
                {label:'✔ ${Yes}', primary: true}
            ]
        }).then(function() {
            c.agree = 'yes';
        }, function() {
            c.agree = 'no';
        })
    }
}

Thanks - it turns out there is another twist becuase the ts&cs are displayed (currently) from a UI page, so we really are back to the drawing board with this one, and may end up going for a macro variable to display the ts&cs rather than a pop up window.

Joy of joys.   thanks for all your feedback though - it actually helped with another bit of the portal whcih needed a confirmation dialog.

LG2
Mega Expert

In the end we put the ts&cs into a macro with label variable and embedded them into a widget for the Service Portal with a variable width specified for the display. Not perfect, but the ts&cs are at least visible now.

woodyfairley
Tera Guru

Are you willing to share some code with the community? I am glad you found your own solution, and I am implementing a similar behavior in our portal, sharing your solution will help me and the other developers.

Kind Regards,

Woody