UI Page into Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 03:40 AM
Hi All,
We have a UI Page that displays depending on the choice of a variable on a Service Request. The Page displays a Knowledge Article. Below is the code-
HTML PART
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<table width="100%">
<tr>
<td>
<j:set var="jvar_user_id" value="${sysparm_user}" />
<g:dialog_button onclick="toKnowledge()" type="button" class="diabutt">View Article</g:dialog_button>
<input type="hidden" id="kb_article" name="kb_article" value="${article.number}"/>
</td>
</tr>
<tr>
<td>
<div style="margin-top: 10px;">
<!-- Pull in 'ui_checkbox' UI Macro for accept checkbox -->
<g:ui_checkbox id="accept_terms" name="accept_terms" value="false"/>
<label for="load_demo">I accept these terms and conditions.</label>
</div>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr id="dialog_buttons">
<td colspan="2" align="right">
<g:evaluate var="sysparm_id">
var splitresult = RP.getReferringURL().split("=");
var sysparm_id = splitresult[1];
</g:evaluate>
<g:evaluate var="jvar_cancel_url"
expression= "RP.getWindowProperties().get('cancel_url')" />
<input type="hidden" id="cancel_url" value="${jvar_cancel_url}" />
<!-- Pull in 'dialog_buttons_ok_cancel' UI Macro for submit/cancel buttons -->
<g:dialog_buttons_ok_cancel ok="return termsOK()" cancel="termsCancel()" ok_type="button" cancel_type="button"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
Client Script
function termsCancel(){
//Redirect gets called if the 'Cancel' dialog button is clicked
if($('cancel_url').value != 'null'){
window.location = $('cancel_url').value;
GlideDialogWindow.get().destroy();
}
else{
GlideDialogWindow.get().destroy();
//window.location = 'home.do'; //Redirect to default homepage
//window.location = 'sc_cat_item/sys_id=071bcd95db9c53842a862aea4b961954.do';
//action.setRedirectURL(current);
}
}
function termsOK(){
//Gets called if the 'OK' dialog button is clicked
//Make sure terms have been accepted
var terms = gel('accept_terms').value;
if(terms != 'true'){
//If terms are false stop submission
alert('Please accept the terms and conditions to continue your order.');
return false;
}
//If accept checkbox is true do this...
GlideDialogWindow.get().destroy(); //Close the dialog window
//g_form.setValue('myvar', true); //Optionally set the value of a variable or field indicating acceptance
}
function toKnowledge(){
var myarticle = document.getElementById('articleslist');
var myValue = "";
// var myValue = myarticle.options[myarticle.selectedIndex].value;
var url = new GlideURL('kb_view.do');
url.addParam('sys_kb_id','e7f31c4bdb19df480f3115784b96199f');
var w = getTopWindow();
w.popupOpenFocus(url.getURL(), 'kb_view', 300, 300, '_self', false, false);
}
We are calling this page from a onChange script in the request.
Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ag = g_form.getValue('Need_for_Business');
if(ag == 'No'){
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(300,300); //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
}
}
This was working fine till the introduction of Service Portal in the system. I know from wiki that UI Pages would not work in portal and we have to use widgets, but I have no clue how to do that! MoreOver an Angular Novice! If anyone can help how I can convert this into workable pieces of code for Portal that will be a very big help! Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 02:40 AM
I managed to create a widget with the following code-
HTML
<div class="panel panel-danger">
<div class="panel-heading">
<div class="panel-title">Terms and Conditions</div>
</div>
<div class="panel-body">
<div>
<button class="btn btn-primary" ng-click="c.openModal()">${View Article}</button>
</div>
<div>
<input type="checkbox" name="agree" value="agree" ng-model="c.data.agree" placeholder>
<span style="color:blue">I accept these Terms and Conditions</span>
</div>
<div class="panel-footer text-right">
<button class="btn btn-secondary" ng-click="c.closeModal()">${Cancel}</button>
<button class="btn btn-primary" ng-click="c.closeModal()">
${Ok}
</button>
Client Script
function($uibModal, $scope) {
var c = this;
c.openModal = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope
});
}
c.closeModal = function() {
c.modalInstance.close();
}
}
This is how the widget looks currently-
On click of 'View Article' I need to open a knowledge article on a seperate page. Clicking on Cancel should close the box, And user needs to check I accept and click OK to close the dialogue box, other wise gets a message, Please accept the Terms.
Any help on how can I relate the behaviours?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 07:05 AM
Hi Anurag,
For clicking on "View Article" , Knowledge article to open :
<button name="View Article" type="submit" ng-href="?id=kb_view&sys_id=e7f31c4bdb19df480f3115784b96199f">
Please do click helpful if it answers your question.
Regards,
Swathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 08:30 AM
Hi Swathi,
Thank you for your help. One last thing, when the Dialoguebox comes, user needs to check the checkbox(I accept) and then click OK to remain in the same page. Without checking, if clicked on OK,should get a error message and box should not close. If clicked on Cancel, it should close the request. How can I include this here?
Also previously I was calling the UI page from the following onChange client script on the item, on Change of a variable-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ag = g_form.getValue('Business_Reason');
if(ag == 'No'){
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(300,300); //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
}
}
The Test page for the widget i created is named Knowledge_popup. Will replacing the name inside GlideDialogueWindow work? Or something else is required to bring that widget in the item?
Thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 06:56 AM
Hi Anurag,
I have created the widget , in this way :
Widget code :
HTML Template :
<div class="panel panel-primary b">
<div class="panel-heading">
<h4 class="panel-title">
<i class="fa fa-info-circle m-r-sm"></i>User Information
</h4>
</div>
<div class="panel-body">
<form class="form-horizontal" role="form">
<div class="form-group" >
<div class="col-sm-12">
<span style="color:red;">*</span><label class="control-label" >Phone Number</label>
<select id="ph_num" name="ph_num" class="form-control ng-pristine ng-untouched ng-valid ng-not-empty" ng-model="c.selectedNumber" ng-options="x for x in data.choices" ng-change="myChange(c.selectedNumber)"><option value="">-- Select an option--</option></select>
</div>
</div>
<div class="form-group" >
<div class="col-sm-12">
<span style="color:red;">*</span><label class="control-label" >Data Plan Needed</label>
<select id="data_plan" name="data_plan" class="form-control ng-pristine ng-untouched ng-valid ng-not-empty" ng-model="c.selectedData" ng-options="y for y in data.choices" ng-change="myChange(c.selectedData)"><option value="">-- Select an option--</option></select>
</div>
</div>
</form>
</div>
<div class="panel-footer clearfix">
<input class="pull-right btn btn-primary" type="reset" value="${Reset}" ng-click="reset()">
<input class="pull-left btn btn-primary" type="viewarticle" value="${View Article}" ng-click="onView()">
</div>
</div>
Client Script :
function($scope, $window, spUtil,spModal) {
var c = this;
$scope.myChange = function(something){
$scope.data.func ='submit';
c.confirmed = "asking";
spModal.confirm($scope.data.msg).then(function(confirmed) {
c.confirmed = confirmed; // true or false
})
if(c.confirmed) {
//Replace new line with breaks
c.data.textchange =c.selectedNumber;
if(something == "No"){
//Write your code here
}
}
}
$scope.onView = function() {
//Write view article code here
}
$scope.reset = function() {
c.selectedNumber = "";
c.selectedData = "";
$scope.data.func ='reset';
c.server.update().then(function(response) {
spUtil.update($scope);
})
}
}
Server Script :
(function() {
var user = gs.getUser();
var user_id = gs.getUserID();
var session = gs.getSession();
data.language = session.getLanguage();
data.choices = ['Yes','No'];
data.msg = gs.getMessage('I accept these terms and conditions');
//Start
if(input.func == "reset"){
//Write any code you want to perform at reset
}
//End
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 11:04 AM
View Article | |
| |
var splitresult = RP.getReferringURL().split("="); var sysparm_id = splitresult[1]; |