Make fields mandatory when SLA breached on incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:15 AM
Hello All ,
I have one field 'sla breached reason' field on incident field. this has to visible and mandatory when "SLA breached and Incident state changes to resolved"
If sla not breached this field doesn't want to show.
kindly help me the code for this?(client scrpt+script include only)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:22 AM
Hi,
you can use Display business rule on incident table and check if the SLA is breached for this incident and store it as flag in g_scratchpad variable
then use onLoad client script to hide it
BR:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("task_sla");
gr.addQuery("task", current.getUniqueValue());
gr.addEncodedQuery("has_breached=true");
gr.query();
g_scratchpad.isBreached = gr.hasNext();
})(current, previous);
Client Script:
function onLoad(){
// hide it
g_form.setDisplay('u_sla_breached_reason', false);
// show and make mandatory if breached
if(g_scratchpad.isBreached.toString() == 'true'){
g_form.setDisplay('u_sla_breached_reason', true);
g_form.setMandatory('u_sla_breached_reason', true);
}
}
OR
You can use onLoad client script + GlideAjax as well
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 11:31 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2023 03:17 PM
Thank you so much. This worked awesome!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:24 AM
Hi you can write client script and Script include like this
Script Include:
checkSLA: function()
{
var getRecordSysID = this.getParameter("sysparm_id");
var sla = new GlideRecord('task_sla')
sla.addQuery('task', getRecordSysID);
sla.addQuery('has_breached', 'true');
sla.query();
while(sla.Next()){
return true;
}
},
Client Script:
var getState = g_form.getValue('state');
if(getState == 6)
{
var ga = new GlideAjax('SLADetails'); // SI name
ga.addParam('sysparm_name', 'checkSLA'); //SI function
ga.addParam('sysparm_id', newValue);
ga.getXML(callBack);
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("answer" + answer);
if(answer == true)
{
g_form.setVisible('sla breached reason'', true);
g_form.setMandatory('sla breached reason'', true);
}
}
else
{
g_form.setVisible('sla breached reason'', false);
g_form.setMandatory('sla breached reason'', false);
}
}
Harish