closure codes and closure notes are mandatory

Adarsh15
Giga Contributor

Hi,

I have a requirement where the user are able to close the incident from the list view without the closure notes and closure codes.

I need to make sure they should fill the close notes and close codes before resolving or closing the ticket.

I have tried different methods including data policy but it was not working. Finally I wrote an onCell edit client script which is as follows,

if(newValue == 6 || newValue ==7){
alert("Closure notes and Configuration Item are mandatory");
saveAndClose = false;
}else{
saveAndClose = true;
}
callback(saveAndClose);

Problem with this is like after inserting the close codes and close notes from list view still it is showing that alert.

Can anyone help me with the above code , where I can check if the close code and close notes are empty.

 

Thanks in advance

1 ACCEPTED SOLUTION

Harshal Gawali
Giga Guru

Hi Adarsh,

I have tried Data policy in my PDI & it is working fine. what condition are you adding in data policy?

For reference, check below screenshot.

find_real_file.png

Regards,

Harshal.

View solution in original post

13 REPLIES 13

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Adarsh ,

 

Use below Client Script:-  

 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if (answer == 'false') {
alert("Closure notes and Configuration Item are mandatory");
saveAndClose = false;
callback(saveAndClose);
} else {
saveAndClose = true;
callback(saveAndClose);
}
}
if (newValue == 6 || newValue == 7) {
var ga = new GlideAjax('checkCIandCC');
ga.addParam('sysparm_name', 'getData');
ga.addParam('sysparm_sysid', sysIDs);
ga.getXML(callBack);

}

}  

 

find_real_file.png

Script Include:-  

 

var checkCIandCC = Class.create();
checkCIandCC.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getData: function() {
var sysID = this.getParameter('sysparm_sysid');
var gr = new GlideRecord("incident");
gr.addQuery("sys_id", sysID);
gr.query();
if (gr.next()) {
if (gr.cmdb_ci == '' || gr.close_code == '') {
return false;
} else return true;
}

 

},

type: 'checkCIandCC'
});  

 

 

find_real_file.png

 

Working and tested in my PDI.

 

Please mark my answer as helpful/correct if it resolves your query.

 

Regards,

Gunjan Kiratkar

Consultant - ServiceNow, Cloudaction

Rising Star 2022

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You can achieve this easily with Data policy

what's not working with data policy?

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi 

A data policy is already available but in inactive stage, if we make that active users are not able to create an incident.

 

Hi,

can you share that data policy configuration image?

you should give correct condition to make the fields mandatory only when State Changes to Closed or Resolved

OR

you can use before update BR on incident table and check if both the fields are empty and stop form submission and show error message

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Adarsh 

Any update to this?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader