diff --git a/Background Scripts/CreateIncident.js b/Background Scripts/CreateIncident.js new file mode 100644 index 0000000000..83a3227bbb --- /dev/null +++ b/Background Scripts/CreateIncident.js @@ -0,0 +1,7 @@ + +var gr = new GlideRecord('incident'); +gr.initialize(); +gr.short_description = 'New Incident'; +gr.description = 'This is a new incident created by a background script.'; +gr.insert(); +gs.log('New incident created with sys_id: ' + gr.sys_id); diff --git a/Background Scripts/Delete Closed Incident/DeleteIncident.js b/Background Scripts/Delete Closed Incident/DeleteIncident.js new file mode 100644 index 0000000000..f39e58b0c3 --- /dev/null +++ b/Background Scripts/Delete Closed Incident/DeleteIncident.js @@ -0,0 +1,8 @@ +var gr = new GlideRecord('incident'); +gr.addQuery('state', '7'); +gr.query(); +var count = 0; +while (gr.next()) { + gr.deleteRecord(); + count++; +} diff --git a/Background Scripts/Delete Closed Incident/readme.md b/Background Scripts/Delete Closed Incident/readme.md new file mode 100644 index 0000000000..74ee0fa4e5 --- /dev/null +++ b/Background Scripts/Delete Closed Incident/readme.md @@ -0,0 +1 @@ +Delete All those incident which are closed so this snippet is basically for that diff --git a/Background Scripts/Get Current Month/CurrentMonth.js b/Background Scripts/Get Current Month/CurrentMonth.js new file mode 100644 index 0000000000..fc3bbd42e3 --- /dev/null +++ b/Background Scripts/Get Current Month/CurrentMonth.js @@ -0,0 +1,9 @@ +var currentDate = new GlideDate(); +var monthNumber = currentDate.getMonth(); +var monthNames = [ + "Jan", "Feb", "Mar", "Apr", "May", "June", + "July", "Aug", "Sept", "OCT", "Nov", "Dec" +]; + +var monthName = monthNames[monthNumber - 1]; +gs.log(monthName); diff --git a/Background Scripts/Get Current Month/readme.md b/Background Scripts/Get Current Month/readme.md new file mode 100644 index 0000000000..6b69e96c63 --- /dev/null +++ b/Background Scripts/Get Current Month/readme.md @@ -0,0 +1 @@ +Code Snippets is just to get the current month name diff --git a/Background Scripts/GetAllActiveIncident b/Background Scripts/GetAllActiveIncident new file mode 100644 index 0000000000..6f3466e762 --- /dev/null +++ b/Background Scripts/GetAllActiveIncident @@ -0,0 +1,8 @@ +var op = new GlideRecord('incident'); +op.addActiveQuery(); +op.query(); +while(op.next()) +{ +gs.log('Incident Number :'+op.number); +gs.log('Incident Description : '+op.short_description); +} diff --git a/Background Scripts/Update Incident/UpdateIncident.js b/Background Scripts/Update Incident/UpdateIncident.js new file mode 100644 index 0000000000..a74e385615 --- /dev/null +++ b/Background Scripts/Update Incident/UpdateIncident.js @@ -0,0 +1,7 @@ +var gr = new GlideRecord('incident'); +gr.addQuery('state', '1'); +gr.query(); +while (gr.next()) { + gr.priority = '2'; + gr.update(); +} diff --git a/Background Scripts/UpdatePriorityBasedOnImpact.js b/Background Scripts/UpdatePriorityBasedOnImpact.js new file mode 100644 index 0000000000..a69e719c7c --- /dev/null +++ b/Background Scripts/UpdatePriorityBasedOnImpact.js @@ -0,0 +1,15 @@ + +var gr = new GlideRecord('incident'); +gr.addQuery('active', true); +gr.addQuery('impact', '2'); +gr.query(); +while (gr.next()) { + + if (gr.impact == '2') { + gr.priority = '1'; + } else { + gr.priority = '2'; + } + gr.update(); +} + diff --git a/Client Scripts/FlashEmptyField b/Client Scripts/FlashEmptyField new file mode 100644 index 0000000000..976dcf6f75 --- /dev/null +++ b/Client Scripts/FlashEmptyField @@ -0,0 +1,15 @@ +function onLoad() { + // Get the field element + var field = g_form.getControl('short_description'); + + // Check if the field is empty + if (g_form.getValue('short_description').trim() === '') { + // Apply CSS style to flash the field + field.style.backgroundColor = 'red'; + + // Set a timeout to reset the background color after a few seconds + setTimeout(function() { + field.style.backgroundColor = ''; + }, 2000); // Change '2000' to set the duration in milliseconds + } +} diff --git a/Client Scripts/PreventFutureDateSelection b/Client Scripts/PreventFutureDateSelection new file mode 100644 index 0000000000..8748c2a666 --- /dev/null +++ b/Client Scripts/PreventFutureDateSelection @@ -0,0 +1,13 @@ +function onChange(control, oldValue, newValue, isLoading) { + if (isLoading || newValue == '') { + return; + } + + var selectedDate = new GlideDate(newValue); + var currentDate = new GlideDate(); + + if (selectedDate > currentDate) { + g_form.clearValue('your_date_field'); // Replace 'your_date_field' with the actual field name + alert('Future dates are not allowed.'); + } +} diff --git a/GlideRecord/CheckNewRecord b/GlideRecord/CheckNewRecord new file mode 100644 index 0000000000..6e29644cf5 --- /dev/null +++ b/GlideRecord/CheckNewRecord @@ -0,0 +1,16 @@ +var gr = new GlideRecord('incident'); + + +if (gr.isNewRecord()) { + gs.log("This is a new incident record."); +} else { + gs.log("This is an existing incident record."); +} +gr.addQuery('active', true); +gr.query(); + +while (gr.next()) { + + gs.log('Incident Number: ' + gr.number); + gs.log('Short Description: ' + gr.short_description); +} diff --git a/Incident with priority as P1 b/Incident with priority as P1 new file mode 100644 index 0000000000..acd5f1b4c0 --- /dev/null +++ b/Incident with priority as P1 @@ -0,0 +1,11 @@ +// This script can be used in a Script Include or Business Rule +var incidentGR = new GlideRecord('incident'); +incidentGR.initialize(); +incidentGR.short_description = 'Critical Incident - Immediate Attention Required'; +incidentGR.description = 'This is a Priority 1 incident created via script.'; +incidentGR.priority = 1; // Priority 1 +incidentGR.impact = 1; // High impact +incidentGR.urgency = 1; // High urgency +incidentGR.caller_id = gs.getUserID(); // Sets the current user as the caller +incidentGR.category = 'network'; // Example category +incidentGR.insert(); diff --git a/UI Actions/OpenGooglePage b/UI Actions/OpenGooglePage new file mode 100644 index 0000000000..697480c249 --- /dev/null +++ b/UI Actions/OpenGooglePage @@ -0,0 +1,11 @@ +(function executeUIAction(current, parent) { + var url = "https://www.google.com"; + var openInNewTab = true; + + if (openInNewTab) { + var win = window.open(url, "_blank"); + win.focus(); + } else { + window.location.href = url; + } +})(current, current);