Issue with Work in Progress status in Change management

manapt
Kilo Contributor

If I click on Request Approval button in change request which is already having a Change task with work in progress status, the active becomes false automaticaly and adds two updates Closed by and Closed at in the history of that change task. But the status of the change task remains Work in Progress.

We have not done any configuration to close change task when the state is Work in Progress. I dont know why is this doing it. Can anybody help?

7 REPLIES 7

antonymirza
Tera Expert

No, this is not a bug in ServiceNow!

First of all, it doesn't make a sense to display 'Request Approval' UI Action if Change Task in a Change Request is already 'Work In Progress'. And, even if it is visible, there you must go through this UI Action script carefully. I believe you'll find the answer there itself.

If you feel some difficulty then I would suggest you to share UI Action script or screenshot here with us so that we can assist you accordingly.


manapt
Kilo Contributor

onclick: requestApproval();
condition: current.approval=='not requested' && !current.risk.nil() && !current.isNewRecord()
script:



function requestApproval() {

var readyForApproval = true;
readyForApproval = requestApproval2();

if (readyForApproval) {
readyForApproval = checkExpedite();
}

if (readyForApproval) {
g_form.setMandatory('start_date', true);
g_form.setMandatory('end_date', true);
g_form.setMandatory('assigned_to', true);
g_form.setValue('approval', 'requested');
var approval = g_form.getValue('approval');
var task = g_form.getUniqueValue();
var surveyInstance = getSurveyInstance(task);
if ((approval != 'not requested' && surveyInstance != '' && (getSureveyResponses(surveyInstance) == 'High') || (approval != 'not requested' && getSureveyResponses(surveyInstance) == 'Substantial'))) {
g_form.setDisplay('u_tab_date', true);
g_form.setMandatory('u_tab_date', true);
} else {
g_form.setMandatory('u_tab_date', false);
g_form.setDisplay('u_tab_date', false);
}

gsftSubmit(null, g_form.getFormElement(), 'request.approval');}

}


//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined') {
serverResolve();
}

function serverResolve(){
current.approval = 'requested';
//Create the html contents of the information message
var link = '<a href="change_request.do?sys_id=' + current.sys_id + '" class="breadcrumb" >' + current.number + '</a>';
var message = 'Change Request ' + link + ' Approval has been requested.';
//Add the information message
gs.addInfoMessage(message);
current.update();
}

function getSureveyResponses(surveyInstance){
var response = '';
var gr = new GlideRecord('survey_response');
gr.addQuery('instance', surveyInstance);
gr.addQuery('question', 'dcaaacc09cd22400108585734d502a67');
gr.query();
while(gr.next()){
response = gr.response;
}
return response;
}

function countAssets(form_instance) {
var asset_count = 0;
var gr = new GlideRecord('u_m2m_asset_owner_change_req');
gr.addQuery('u_change_request', form_instance);
gr.query();
while(gr.next()){
asset_count++;
}
return(asset_count);
}

function getSurveyInstance(task){
var survey_instance ;
var gr = new GlideRecord('task_assessment');
gr.addQuery('task', task); //Sys id of the task
gr.query();
while (gr.next()){
survey_instance = gr.instance;
}
return survey_instance;
}

function requestApproval2 (){
var state = true;
var form_instance = g_form.getUniqueValue();
if(countAssets(form_instance) != 0) {
return true;
} else {
alert("You must add at least one IT Asset prior to requesting approval");
return false;
}
return state;
}

function checkExpedite() {
var result = false;
var change_rec = g_form.getUniqueValue();
var ndt = g_form.getValue('opened_at');
var gdt = g_form.getValue('start_date');
var date = getTime(ndt,gdt);
var exp = g_form.getValue('u_expedited_change');
if (exp=='true') {
return true;
} else {
result=checkDates(date,change_rec);
if (result){
g_form.setValue('u_expedited_change', true);
var reason = g_form.getValue('u_expedite_reasons');
var explain = g_form.getValue('u_expedited_explanation');
if (reason == '' || explain == '') {
alert("You must provide Reason and Explanation for expediting this change prior to requesting approval");
return false;
} else {

return true;
}
}
return true;
}
}


function getTime(start,end){
var ga = new GlideAjax('CheckTimeAjax');
ga.addParam('sysparm_name','checkDiff');
ga.addParam('sysparm_start',start);
ga.addParam('sysparm_end',end);
ga.getXMLWait();
return ga.getAnswer();
}


function checkDates(time, gr_sysid){
var expedite = false;
var chg = new GlideRecord('change_request');
chg.addQuery('sys_id', gr_sysid);
chg.query();
if (chg.next()){
var days = 0;
if(chg.risk == 2){
//if risk is high check for 5 days
days = 432000000; //five days
}else if(chg.risk == 6){
//if risk is Medium check for 3 days
days= 259200000; //three days
}else if(chg.risk == 4){
//if risk is Low check for 1 day
days= 86400000; //one day
}
if(time < days){
expedite = true; //if we are within acceptable time then expedite
}
return expedite;
}
}


ccajohnson
Kilo Sage

Make sure that your onClick is not defined in any other UI Action. I have seen UI Actions that were disabled that have the same onClick defined in them that get triggered unexpectedly.

Without knowing what else may be triggered by a given UI Action, you may also want to check the Action name field and see if there are other UI Actions that have the same Action name.

In either case, you want to make sure that both the onClick and Action name fields are unique so that another UI Action is not triggered by mistake.