Making comments field mandatory in Service Portal

manibaig
Mega Guru

I want Comments field to be mandatory every time user Approves or Rejects a request. I tried using below link and was able to create comments box but it's not working properly, i can still Approve/Reject the ticket without entering any comments.. Kingston

 

https://community.servicenow.com/community?id=community_blog&sys_id=228da669dbd0dbc01dcaf3231f9619f3

find_real_file.png

1 ACCEPTED SOLUTION

Oh...Why do you have two action functions in client controller? You should remove one

 

c.action = function(state) {

if (c.data.comment == '' )//&& state == 'rejected'){
{
$window.alert('Comments cannot be empty')
return false; }
c.data.op = state;
c.data.state = state;
c.server.update(); } //H
var ESIGNATURE = {
"approved": "cbfe291147220100ba13a5554ee4904d",
"rejected": "580f711147220100ba13a5554ee4904b"
};

spUtil.recordWatch($scope, "sysapproval_approver", "state=requested^sys_id="+ c.data.sys_id);

c.action = function(state) {
if(c.data.esignature.e_sig_required) {
var requestParams = {
username: c.data.esignature.username,
userSysId: c.data.esignature.userSysId
};
spUIActionsExecuter.executeFormAction(ESIGNATURE[state], "sysapproval_approver" , c.data.sys_id, [] , "", requestParams).then(function(response) {
});
} else {
c.data.op = state;
c.data.state = state;
c.server.update();
}
}
}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

9 REPLIES 9

Oh...Why do you have two action functions in client controller? You should remove one

 

c.action = function(state) {

if (c.data.comment == '' )//&& state == 'rejected'){
{
$window.alert('Comments cannot be empty')
return false; }
c.data.op = state;
c.data.state = state;
c.server.update(); } //H
var ESIGNATURE = {
"approved": "cbfe291147220100ba13a5554ee4904d",
"rejected": "580f711147220100ba13a5554ee4904b"
};

spUtil.recordWatch($scope, "sysapproval_approver", "state=requested^sys_id="+ c.data.sys_id);

c.action = function(state) {
if(c.data.esignature.e_sig_required) {
var requestParams = {
username: c.data.esignature.username,
userSysId: c.data.esignature.userSysId
};
spUIActionsExecuter.executeFormAction(ESIGNATURE[state], "sysapproval_approver" , c.data.sys_id, [] , "", requestParams).then(function(response) {
});
} else {
c.data.op = state;
c.data.state = state;
c.server.update();
}
}
}


Please mark this response as correct or helpful if it assisted you with your question.

Oh man, how could i miss that..Thank you for the help. 

is there a way to change this 

find_real_file.png

No. You can only pass one parameter to window.alert, and thats the message. You can't pass title.

 

But there could be other methods to show the popup where you can pass title as well.

 


Please mark this response as correct or helpful if it assisted you with your question.

Can you share your final script if this worked for you? Thanks a lot in advance.

sorry for late reply. Here is the final Client script code

function ($scope, spUIActionsExecuter, spUtil, $window, spModal) {
var c = this;
var ESIGNATURE = {
"approved": "cbfe291147220100ba13a5554ee4904d",
"rejected": "580f711147220100ba13a5554ee4904b"
};

spUtil.recordWatch($scope, "sysapproval_approver", "state=requested^sys_id="+ c.data.sys_id);
c.action = function(state) {
if (c.data.comment =='' || c.data.comment==undefined)//&& state == 'rejected'){
{
$window.alert('Please enter your Comments, Thanks!')
return false; }
c.data.op = state;
c.data.state = state;
c.server.update();
//reloading window after ui action location.reload(); //here
}