Skip to content

Commit 1bd225c

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents a66dd26 + f8d0c75 commit 1bd225c

File tree

18 files changed

+270
-0
lines changed

18 files changed

+270
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* The following is a client callable script include. This can be used with the onChange Client script to be able to gather the data on the server side
3+
*/
4+
5+
var ReferenceQualifierAjaxHelper = Class.create();
6+
ReferenceQualifierAjaxHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
7+
getUserInformation : function() {
8+
var userID = this.getParameter('sysparm_user');
9+
var userRec = new GlideRecord('sys_user');
10+
11+
if(userRec.get(userID)) {
12+
var results = {
13+
"email" : userRec.getValue('email'),
14+
"department" : userRec.getValue('department'),
15+
"title" : userRec.getValue('title'),
16+
"phone" : userRec.getValue('phone')
17+
};
18+
19+
return JSON.stringify(results)
20+
}
21+
22+
},
23+
24+
type: 'ReferenceQualifierAjaxHelper'
25+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Overview
2+
This onchange catalog client script and script inlcude work together autopopulate the user fields that might show up on a catalog item. In the
3+
global scope you will have to create the client callable script include to be able to use the Ajax call that is in the on change client script.
4+
In this example we use the OOB Requested For field that already auto populates the user that is logged in then we go to the server to get that
5+
users information. The fields that are brough back are the ones that are in the code but you can modify to bring back more or less fields if needed.
6+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* In order for this to work make sure to have an onChange catalog client script on a variable that is type Requested For. This variable
3+
* already autopopulates the logged in user with its OOB functionality. In the updateUserFields function you can add any other user fields
4+
* that you might need.
5+
*/
6+
7+
function onChange(control, oldValue, newValue, isLoading) {
8+
//This variable will store the sys_id of the user that populates in your requested for variable
9+
var userID = newValue;
10+
11+
var ga = new GlideAjax(ReferenceQualifierAjaxHelper);
12+
ga.addParam('sysparm_name', 'getUserInformation');
13+
ga.addParam('sysparm_user', userID);
14+
ga.getXMLAnswer(updateUserFields);
15+
16+
function updateUserFields(response) {
17+
var returnedData = JSON.parse(response);
18+
g_form.setValue("email", returnedData.email);
19+
g_form.setValue("department", returnedData.department);
20+
g_form.setValue("title", returnedData.title);
21+
g_form.setValue("phone", returnedData.phone);
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This project adds pre-validation for hardware availability in ServiceNow Catalog Items. Before submitting a request, the system checks if the requested hardware is available in inventory and blocks submission if stock is insufficient. we can easy to extend other validations (budget, licenses, etc.).Improves user experience by validating before approval.Prevents unnecessary approvals and fulfillment.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var HardwareValidationUtils = Class.create();
2+
HardwareValidationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
validateHardware: function() {
5+
var hardware = this.getParameter('sysparm_hardware');
6+
var qty = parseInt(this.getParameter('sysparm_quantity'), 10);
7+
8+
if (!hardware || isNaN(qty)) {
9+
return 'Invalid input!';
10+
}
11+
12+
var gr = new GlideRecord('u_hardware_inventory');
13+
if (gr.get(hardware)) {
14+
var availableQty = parseInt(gr.getValue('available_quantity'), 10);
15+
if (availableQty >= qty) {
16+
return 'OK';
17+
} else {
18+
return 'Not enough stock available!';
19+
}
20+
}
21+
return 'Hardware not found!';
22+
},
23+
24+
type: 'HardwareValidationUtils'
25+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function onSubmit() {
2+
3+
4+
var hardware = g_form.getValue('hardware_name');
5+
var qty = g_form.getValue('quantity');
6+
7+
8+
var ga = new GlideAjax('HardwareValidationUtils');
9+
ga.addParam('sysparm_name', 'validateHardware');
10+
ga.addParam('sysparm_hardware', hardware);
11+
ga.addParam('sysparm_quantity', qty);
12+
13+
14+
ga.getXMLAnswer(function(response) {
15+
16+
17+
if (response !== 'OK') {
18+
alert(response);
19+
20+
g_form.addErrorMessage(response); // Optional inline error
21+
g_form.setSubmit(false); // Prevent submission in Service Portal
22+
} else {
23+
24+
g_form.setSubmit(true); // Allow submission
25+
}
26+
});
27+
28+
return false;
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function onLoad ()
2+
{
3+
var aPriority = g_form.getValue('priority');
4+
var label = g_form.getLable('number');
5+
label.style.backgroundColor = "lightblue";
6+
if(aPriority==1)
7+
{
8+
label.style.color = "red";
9+
}
10+
else if (aPriority==2)
11+
{
12+
label.style.color = "yellow";
13+
}
14+
else
15+
{
16+
label.style.color = "blue";
17+
}
18+
}
19+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Write Client Script
2+
Change Incident Number Lable color based on priority
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Overview
2+
3+
4+
This code snippet UI Action will allow you to have a printer friendly version of whatever record you might are trying to print.
5+
This UI action uses the GlideNavigation API which you can find here [GlideNavigation API](https://developer.servicenow.com/dev.do#!/reference/api/zurich/client/c_GlideNavigationV3API#r_GNV3-openPopup_S_S_S_B)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
printView()
2+
3+
function printView() {
4+
5+
var table = g_form.getTableName();
6+
var recordID = g_form.getUniqueValue();
7+
var view = {{Insert the view you want to print here}}; //You can pass in an empty string and it will still work
8+
var windowName = {{Insert the name you want your window to display}}; //You can pass in an empty string and it will still work
9+
var features = 'resizeable,scrollbar'; //You can pass in an empty string and it will still work
10+
var urlString = '/' + table + ".do?sys_id=" + recordID + "&sysparm_view=" + view + "&sysparm_media=print";
11+
var noStack = true; //Flag that indicates whether to append sysparm_stack=no to the URL
12+
13+
g_navigation.openPopup(urlString, windowName, features, noStack);
14+
15+
}

0 commit comments

Comments
 (0)