Script Include return value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2016 03:51 PM
Hi,
I have requirement if any one of the approval request for change is approved then doesn't show UI Action on form. I have written Script Include and checking all the approval requests for change and if any of state is approved return false otherwise return true but it's always returning True even one of the approval request is approved
Script Include:
UI Action:
I am checking this return value by System Logs. Is there anything i am missing here?
Thanks,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 02:47 AM
Hey, Hi , I have a similar sort of requirement, where I need to show Close UI action only to requester and Change Aprrovers, can you help me with the script include for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2016 06:47 PM
This script include is for UI page which will pop up some message and if they accept that message that will approve the approval request. I also have one OnSubmit client script if user trying to approve from approval list that will show pop up from this. That is why i used the client callable script include. My requirement is if any one of approval requests for change record is approved then don't show that pop up message. That i am trying to achieve from Script Include
Script Include:
var approveChange = Class.create();
approveChange.prototype = Object.extendsObject(AbstractAjaxProcessor, {
approve : function() {
//gs.log('inside include', 'test11');
var approvalID = this.getParameter('sysparm_approverID');
var grApprovel = new GlideRecord('sysapproval_approver');
if( grApprovel.get(approvalID)) {
grApprovel.state = "approved";
grApprovel.comments = "I have read the Change Approval Expectations Document and am aware that my approval signifies that I have followed the steps necessary for my approval--and I accept responsibility and accountability for the success or failure of this change";
grApprovel.update();
return true;
}
return false;
},
checkCABApproval : function(changeID)
{
gs.log('function called ='+changeID);
var changeid = changeID;
if(changeid == '')
{
changeid = this.getParameter('sysparm_changeid');
}
var approverGR = new GlideRecord('sysapproval_approver');
approverGR.addQuery('sys_id',changeid);
approverGR.query();
if(approverGR.next())
{
var approvalNo = approverGR.sysapproval;
gs.log('approval for= ' + approvalNo, 'test_1');
var approverGRNEW = new GlideRecord('sysapproval_approver');
approverGRNEW.addQuery('sysapproval',approvalNo);
approverGRNEW.query();
while(approverGRNEW.next())
{
var st = approverGRNEW.state;
gs.log('state= ' + st, 'test_state');
if(st == 'approved')
{
gs.log('answer is = false');
return false;
}
else
{
gs.log('answer is = true');
return true;
}
}
}
},
type: 'approveChange'
});
Thanks,
Chaitanya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2016 07:32 PM
You want to hide the UI action right?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2016 07:42 PM
Create a new script include as shown below
Name:CheckApproval
client callable:false
Script:
function CheckApproval(id){
var chg= new GlideRecord('sysapproval_approver');
chg.addQuery('sysapproval',id);
chg.addQuery('state','approved');
chg.query();
if(chg.hasNext()){
return false;
}
else{
return true;
}
}
In your UI action use this condition CheckApproval(current.getValue('sys_id'))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2016 10:04 AM
May be I didn't explained my requirement properly. I have requirement
Requirement:
if any manager approving change record that manager wants to see pop up with message (UI Page) with accept and decline buttons. If they accept the UI page that will approve the Change.
Development work:
I have created script include, UI page, and OnSubmit client script everything is working fine expect when user click ok accept for first request after user click on that button page is not refreshing. So i have added window.parent.location.reload(); to ui page and it is giving me message to reload dialogue window. Is there any way to refresh the ui page from client script
Script Include:
var approveChange = Class.create();
approveChange.prototype = Object.extendsObject(AbstractAjaxProcessor, {
approve : function() {
//gs.log('inside include', 'test11');
var approvalID = this.getParameter('sysparm_approverID');
var grApprovel = new GlideRecord('sysapproval_approver');
if( grApprovel.get(approvalID)) {
grApprovel.state = "approved";
grApprovel.comments = "I have read the Change Approval Expectations Document and am aware that my approval signifies that I have followed the steps necessary for my approval--and I accept responsibility and accountability for the success or failure of this change";
grApprovel.update();
return true;
}
return false;
},
checkCABApproval : function() {
var approverID = this.getParameter('sysparm_approverID');
var approverGR = new GlideRecord('sysapproval_approver');
approverGR.addQuery('sys_id',approverID);
approverGR.query();
if(approverGR.next()) {
var approvalNo = approverGR.document_id;
gs.log('approval for= ' + approvalNo, 'test_1');
var approverGRNEW = new GlideRecord('sysapproval_approver');
approverGRNEW.addQuery('document_id',approvalNo);
approverGRNEW.addQuery('state', 'approved');
approverGRNEW.query();
if (approverGRNEW.next()) {
gs.log('answer is = false');
return false;
}
gs.log('answer is true');
return true;
}
},
type: 'approveChange'
});
UI Page:
Client Script:
function approve() {
var approverID = document.getElementById('approval_id').value;
// alert(approverID);
// glide ajax code which will approve the record
var ga = new GlideAjax('approveChange');
ga.addParam('sysparm_name','approve');
ga.addParam('sysparm_approverID',approverID);
ga.getXMLWait();
GlideDialogWindow.get().destroy();
window.parent.location.reload();
}
function closeDialog() {
GlideDialogWindow.get().destroy();
window.parent.location.reload();
}
HTML:
<?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:evaluate var="jvar_approval_id" expression="RP.getWindowProperties().get('approval_sys_id')" />
<html>
<head>
<!--<script>https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script>jQuery.noConflict();</script>
-->
</head>
<input type="hidden" id ="approval_id" value="${jvar_approval_id}" />
<!--<input type="hidden" id ="incident_number" value="INC1604543" ></input> -->
<p> I have read the Change Approval Expectations Document and am aware that my approval signifies that I have followed the steps necessary for my approval--and I accept responsibility and accountability for the success or failure of this change </p>
<div id="buttonDiv">
<button type="button" onclick="approve()">Accept</button>
<button type="button" onclick="closeDialog()">Decline</button>
</div>
</html>
</j:jelly>
Client Script:
function onSubmit() {
//confirm Pop Up Window
if( g_form.getValue('state')=='approved'){
var ga = new GlideAjax('approveChange');
ga.addParam('sysparm_name','checkCABApproval');
ga.addParam('sysparm_approverID',g_form.getUniqueValue());
ga.getXMLWait();
var answer = ga.getAnswer().toString();
alert(answer);
if(answer == false || answer == 'false') {
g_form.setValue('state', 'approved');
//g_form.submit();
}
if(answer == true || answer == 'true') {
var gd = new GlideDialogWindow('confirmation_page');
gd.setTitle('Accept terms and conditions');
gd.setPreference('approval_sys_id', g_form.getUniqueValue());
gd.render();
return false;
}
}
Issue:
When ever i am trying to update from form state and i get message window and when i click on accept/decline i get that reload window box. I don't want that reload box to refresh the page. Is there any method which i can use to refresh the page from client script?
Thanks,
Chaitanya