- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 04:32 AM
Hi,
I want to popup an alert when an incident is opened and if any of the sla attached of that incident has crossed 50%. PFB CS and script include for the same. Not sure where i am going wrong as it is not working.
Incident number field -'number'
Incident no field on incident_sla table - 'inc_number'
Client script (onload)
SCRIPT INCLUDE (client callable)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 05:02 AM
Your Script Include is not actually Client callable as the instantiation needs to include an extension of the Ajax processor. When you have an existing script, then check the box, it doesn't always add the bits it needs. You'll also need to retrieve the parameter using the same name as the client script
var CheckSLAStatus = Class.create();
CheckSLAStatus.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSLAStatus: function() {
var incidentSysId = this.getParameter('number');
var slaStatusArray = [];
var slaGR = new GlideRecord('incident_sla');
slaGR.addQuery('inc_number', incidentSysId);
slaGR.query();
while (slaGR.next()) {
var slaName = slaGR.sla.getDisplayValue();
var percentage = (slaGR.total_time.getDisplayValue() / slaGR.due.getDisplayValue()) * 100;
slaStatusArray.push({
slaName: slaName,
percentage: percentage
});
}
return JSON.stringify(slaStatusArray);
},
type: 'CheckSLAStatus'
});
If you are still not getting expected results, add some gs.info lines to the Script Include to confirm the value passed in from the client, any records retrieved by the GlideRecord, and the values pushed to the array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 06:55 PM
@Sarabjeet1 By looking into your script i have found below issues:
Parameter Mismatch: In the client script, you are passing the parameter as 'number', but in the Script Include, you are trying to access 'incidentSysId'. This mismatch will result in the Script Include not receiving the correct value.
Incorrect Field Names: In the incident_sla table, you are using 'inc_number', but the correct field that references the Incident is task. The task field stores the sys_id of the associated task (Incident, Change, etc.).
Division of Date/Time Fields: You are trying to divide two date/time fields (total_time and due). These fields are GlideDateTime objects, and you cannot directly divide them. You need to convert these to numeric values (e.g., using .getNumericValue()) for calculation.
Please review again your code, hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 03:19 AM
You Can Write On Load Client Script given below:
and script include given below :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 03:57 AM
and Given Below is Script Include for same :