From a7b7262bc8a2241cfac0699c3432212b18f37537 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:36:56 +0530 Subject: [PATCH 01/14] Create Readme.md --- .../Business Rules/Smart Attachment Size Limiter/Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md new file mode 100644 index 0000000000..502c913352 --- /dev/null +++ b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md @@ -0,0 +1,7 @@ +Smart Attachment Size Limiter +This Business Rule limits attachment sizes uploaded to ServiceNow records by enforcing a maximum size configured via the system property com.glide.attachment.max_size (in bytes). If the attachment exceeds the configured limit, the upload is blocked with an error message shown to the user. You can create or modify this system property to change the max size and update the property name in the script accordingly. + +Scoped Application Note: +If deploying in a scoped application, configure Cross-Scope Access under System Applications > Application Cross-Scope Access to allow your app permission to access the sys_attachment table and related resources, avoiding security restrictions. + +This approach keeps your instance performant by managing attachment size transparently without hardcoded limits. From fc57af84360c26cb8690147e8c39272f0940d09e Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:39:50 +0530 Subject: [PATCH 02/14] Create Smart Attachment Size Limiter.js --- .../Smart Attachment Size Limiter.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js new file mode 100644 index 0000000000..644e7b7b22 --- /dev/null +++ b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js @@ -0,0 +1,14 @@ +(function executeRule(current, previous /*null when async*/ ) { + if (current.table_name == 'incident') { //here multiple tables can be looped I am just using incident table + var maxSize = gs.getProperty('com.glide.attachment.max_size'); + maxSize = parseInt(maxSize, 10); + if (current.size_bytes > maxSize) { + var maxSizeMB = (maxSize / (1024 * 1024)).toFixed(2); + var attachmentSizeMB = (current.size_bytes / (1024 * 1024)).toFixed(2); + // Prevent insert by setting error message + gs.addErrorMessage("Attachment '" + current.file_name + "' size (" + attachmentSizeMB + " MB) exceeds the max allowed size of " + maxSizeMB + " MB. Please reduce the file size."); + // Cancel the insert operation + current.setAbortAction(true); + } + } +})(current, previous); From 9149ae9683e71f189966245d42c2c88daef2b327 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:44:14 +0530 Subject: [PATCH 03/14] Delete Server-Side Components/Business Rules/Smart Attachment Size Limiter directory --- .../Smart Attachment Size Limiter/Readme.md | 7 ------- .../Smart Attachment Size Limiter.js | 14 -------------- 2 files changed, 21 deletions(-) delete mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md delete mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md deleted file mode 100644 index 502c913352..0000000000 --- a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md +++ /dev/null @@ -1,7 +0,0 @@ -Smart Attachment Size Limiter -This Business Rule limits attachment sizes uploaded to ServiceNow records by enforcing a maximum size configured via the system property com.glide.attachment.max_size (in bytes). If the attachment exceeds the configured limit, the upload is blocked with an error message shown to the user. You can create or modify this system property to change the max size and update the property name in the script accordingly. - -Scoped Application Note: -If deploying in a scoped application, configure Cross-Scope Access under System Applications > Application Cross-Scope Access to allow your app permission to access the sys_attachment table and related resources, avoiding security restrictions. - -This approach keeps your instance performant by managing attachment size transparently without hardcoded limits. diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js deleted file mode 100644 index 644e7b7b22..0000000000 --- a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js +++ /dev/null @@ -1,14 +0,0 @@ -(function executeRule(current, previous /*null when async*/ ) { - if (current.table_name == 'incident') { //here multiple tables can be looped I am just using incident table - var maxSize = gs.getProperty('com.glide.attachment.max_size'); - maxSize = parseInt(maxSize, 10); - if (current.size_bytes > maxSize) { - var maxSizeMB = (maxSize / (1024 * 1024)).toFixed(2); - var attachmentSizeMB = (current.size_bytes / (1024 * 1024)).toFixed(2); - // Prevent insert by setting error message - gs.addErrorMessage("Attachment '" + current.file_name + "' size (" + attachmentSizeMB + " MB) exceeds the max allowed size of " + maxSizeMB + " MB. Please reduce the file size."); - // Cancel the insert operation - current.setAbortAction(true); - } - } -})(current, previous); From a9c13f78de536b3cf8c36689b1a94455fd477f35 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 00:19:19 +0530 Subject: [PATCH 04/14] Add UserLocationUtils for retrieving user location --- .../UserLocationUtils.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js diff --git a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js new file mode 100644 index 0000000000..5435dbd06b --- /dev/null +++ b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js @@ -0,0 +1,22 @@ +var UserLocationUtils = Class.create(); +UserLocationUtils.prototype = { + initialize: function() { + + }, + getUserLocationCoords: function() { + var user = gs.getUser(); + var loc = user.getRecord().location; + if (loc) { + var locGR = new GlideRecord('cmn_location'); + if (locGR.get(loc)) + return { + latitude: parseFloat(locGR.latitude), + longitude: parseFloat(locGR.longitude), + name: locGR.name.toString() + }; + } + return null; + }, + + type: 'UserLocationUtils' +}; From 9fa52c785a7dd952040aac26754978e3858b7faa Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 00:23:24 +0530 Subject: [PATCH 05/14] Add Readme for User Location Validator solution This document explains the User Location Validator solution, detailing how it restricts form submissions based on user location. --- .../Dynamic Location Validation Approach/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md diff --git a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md new file mode 100644 index 0000000000..de0a46863e --- /dev/null +++ b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md @@ -0,0 +1,4 @@ +User Location Validator +This solution ensures only users within their assigned business location can submit ServiceNow forms. The Script Include (Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches location coordinates from the user’s profile. The Client Script (Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) compares these with the actual browser location, blocking submission if the user is outside the allowed area. Update office location in the user record to adjust the validation. + +If using a scoped application, ensure cross-scope access is allowed for Script Include calls. From c15fe8922b995f0a82113252bf3bcdb8ce6e3383 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 00:24:33 +0530 Subject: [PATCH 06/14] Add README for User Location Validator solution This document explains the User Location Validator solution, which restricts ServiceNow form submissions based on user location. It details the functionality of the Script Include and Client Script involved in the validation process. --- .../Dynamic Location Validation Approach/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md diff --git a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md new file mode 100644 index 0000000000..de0a46863e --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md @@ -0,0 +1,4 @@ +User Location Validator +This solution ensures only users within their assigned business location can submit ServiceNow forms. The Script Include (Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches location coordinates from the user’s profile. The Client Script (Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) compares these with the actual browser location, blocking submission if the user is outside the allowed area. Update office location in the user record to adjust the validation. + +If using a scoped application, ensure cross-scope access is allowed for Script Include calls. From ce7e10f165ee6dd757f75696523f0603094386ac Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 00:25:20 +0530 Subject: [PATCH 07/14] Implement user location validation on form submission --- .../User Location Validator.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js diff --git a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js new file mode 100644 index 0000000000..2526f580a2 --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js @@ -0,0 +1,39 @@ +function onSubmit() { + var ga = new GlideAjax('UserLocationUtils'); + ga.addParam('sysparm_name', 'getUserLocationCoords'); + ga.getXMLAnswer(function(response) { + var locData = JSON.parse(response); + if (!locData) { + g_form.addErrorMessage("No assigned location found for your profile."); + return false; + } + + navigator.geolocation.getCurrentPosition(function(position) { + var userLat = position.coords.latitude; + var userLng = position.coords.longitude; + var allowedLat = locData.latitude; + var allowedLng = locData.longitude; + var locName = locData.name; + + var R = 6371; + var dLat = (userLat - allowedLat) * Math.PI / 180; + var dLng = (userLng - allowedLng) * Math.PI / 180; + var a = Math.sin(dLat / 2) ** 2 + + Math.cos(allowedLat * Math.PI / 180) * + Math.cos(userLat * Math.PI / 180) * + Math.sin(dLng / 2) ** 2; + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + var distance = R * c; + + if (distance > 10) { // 10 km tolerance + alert("You are " + distance.toFixed(2) + " km away from your registered office: " + locName); + g_form.addErrorMessage("Location validation failed."); + return false; + } else { + g_form.addInfoMessage("Location validated successfully within range of " + locName); + return true; + } + }); + }); + return false; // Wait for async location validation +} From 8dd63ec53992830b83fcbebb230e7f6f1db4cdb3 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:37:09 +0530 Subject: [PATCH 08/14] Refactor location validation using Haversine formula --- .../User Location Validator.js | 83 +++++++++++-------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js index 2526f580a2..44095b7110 100644 --- a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js +++ b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js @@ -1,39 +1,52 @@ function onSubmit() { - var ga = new GlideAjax('UserLocationUtils'); - ga.addParam('sysparm_name', 'getUserLocationCoords'); - ga.getXMLAnswer(function(response) { - var locData = JSON.parse(response); - if (!locData) { - g_form.addErrorMessage("No assigned location found for your profile."); - return false; + // Check if the browser supports geolocation + if ("geolocation" in navigator) { + // Request current user position + navigator.geolocation.getCurrentPosition(function(position) { + var currentLatitude = position.coords.latitude; // Current user latitude + var currentLongitude = position.coords.longitude; // Current user longitude + + // Allowed business location coordinates fetched from server + var allowedLatitude = locData.latitude; + var allowedLongitude = locData.longitude; + var locationName = locData.name; + + // Earth's radius in kilometers - constant used in distance calculation formula + var earthRadiusKm = 6371; + + // Convert degree differences to radians + var deltaLatitude = (currentLatitude - allowedLatitude) * Math.PI / 180; + var deltaLongitude = (currentLongitude - allowedLongitude) * Math.PI / 180; + + // Haversine formula components + var a = Math.sin(deltaLatitude / 2) * Math.sin(deltaLatitude / 2) + + Math.cos(allowedLatitude * Math.PI / 180) * + Math.cos(currentLatitude * Math.PI / 180) * + Math.sin(deltaLongitude / 2) * Math.sin(deltaLongitude / 2); + + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + // Calculate distance in kilometers between current and allowed locations + var distanceKm = earthRadiusKm * c; + + // Check if user's current distance exceeds tolerance (e.g., 10 km) + if (distanceKm > 10) { + alert("You are " + distanceKm.toFixed(2) + " km away from your registered location: " + locationName); + g_form.addErrorMessage("Location validation failed: Submission outside the allowed radius."); + return false; // Cancel form submission + } else { + g_form.addInfoMessage("Location validated successfully within range of " + locationName); + return true; // Allow form submission } + }, function(error) { + alert("Geolocation error: " + error.message); + return false; // Stop submission if geolocation fails + }); - navigator.geolocation.getCurrentPosition(function(position) { - var userLat = position.coords.latitude; - var userLng = position.coords.longitude; - var allowedLat = locData.latitude; - var allowedLng = locData.longitude; - var locName = locData.name; - - var R = 6371; - var dLat = (userLat - allowedLat) * Math.PI / 180; - var dLng = (userLng - allowedLng) * Math.PI / 180; - var a = Math.sin(dLat / 2) ** 2 + - Math.cos(allowedLat * Math.PI / 180) * - Math.cos(userLat * Math.PI / 180) * - Math.sin(dLng / 2) ** 2; - var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - var distance = R * c; - - if (distance > 10) { // 10 km tolerance - alert("You are " + distance.toFixed(2) + " km away from your registered office: " + locName); - g_form.addErrorMessage("Location validation failed."); - return false; - } else { - g_form.addInfoMessage("Location validated successfully within range of " + locName); - return true; - } - }); - }); - return false; // Wait for async location validation + // Prevent form submission while waiting for async geolocation result + return false; + } else { + g_form.addErrorMessage("Geolocation is not supported by your browser."); + return false; // Block if geolocation API unsupported + } } From 6b4d248d9f7aa860d72b31fc9ec70c01e4ef81aa Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:48:55 +0530 Subject: [PATCH 09/14] Revise README for User Location Validator Updated the README to clarify the User Location Validator functionality, including details on how it works, sample output, and usage notes. --- .../Readme.md | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md index de0a46863e..1aa0be3f69 100644 --- a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md +++ b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md @@ -1,4 +1,19 @@ -User Location Validator -This solution ensures only users within their assigned business location can submit ServiceNow forms. The Script Include (Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches location coordinates from the user’s profile. The Client Script (Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) compares these with the actual browser location, blocking submission if the user is outside the allowed area. Update office location in the user record to adjust the validation. +**User Location Validator** +This script restricts form submissions based on the physical location of the user. The current location is obtained using the browser’s geolocation API (latitude and longitude), and is then compared against the user's assigned business location stored in ServiceNow. -If using a scoped application, ensure cross-scope access is allowed for Script Include calls. +**How It Works** +- The **server-side Script Include**(Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches the assigned business location’s latitude, longitude, and name for the logged-in user. +- The **client-side script**(Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) uses the browser API to obtain the current latitude and longitude of the user at form submission. +- It calculates the distance between these two points using the **Haversine formula**, which accounts for the spherical shape of the Earth. +- The key constant `earthRadiusKm = 6371` defines the Earth's radius in kilometers and is essential for accurate distance calculation. +- If the user’s current location is outside the predefined radius (default 10 km), the form submission is blocked with an error message showing the distance and allowed location. +- If the user is within range, a confirmation info message is displayed and the submission proceeds. + +**Sample Output** +- **Success:** "Location validated successfully within range of Headquarters." +- **Failure:** "You are 15.23 km away from your registered location: Headquarters." + +**Usage Notes** +- Requires user consent for geolocation access in the browser. +- The script uses descriptive variable names for clarity and maintainability. +- Suitable for scenarios requiring geo-fencing compliance or location-based workflow restrictions. From 62b4b523b6dd9fc838b6a2d210990728cb5d7022 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:50:57 +0530 Subject: [PATCH 10/14] Revise Readme for User Location Validator script Updated the readme to clarify the functionality and usage of the User Location Validator script, including details on how it works and sample output. --- .../Readme.md | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md index de0a46863e..1aa0be3f69 100644 --- a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md +++ b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md @@ -1,4 +1,19 @@ -User Location Validator -This solution ensures only users within their assigned business location can submit ServiceNow forms. The Script Include (Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches location coordinates from the user’s profile. The Client Script (Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) compares these with the actual browser location, blocking submission if the user is outside the allowed area. Update office location in the user record to adjust the validation. +**User Location Validator** +This script restricts form submissions based on the physical location of the user. The current location is obtained using the browser’s geolocation API (latitude and longitude), and is then compared against the user's assigned business location stored in ServiceNow. -If using a scoped application, ensure cross-scope access is allowed for Script Include calls. +**How It Works** +- The **server-side Script Include**(Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches the assigned business location’s latitude, longitude, and name for the logged-in user. +- The **client-side script**(Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) uses the browser API to obtain the current latitude and longitude of the user at form submission. +- It calculates the distance between these two points using the **Haversine formula**, which accounts for the spherical shape of the Earth. +- The key constant `earthRadiusKm = 6371` defines the Earth's radius in kilometers and is essential for accurate distance calculation. +- If the user’s current location is outside the predefined radius (default 10 km), the form submission is blocked with an error message showing the distance and allowed location. +- If the user is within range, a confirmation info message is displayed and the submission proceeds. + +**Sample Output** +- **Success:** "Location validated successfully within range of Headquarters." +- **Failure:** "You are 15.23 km away from your registered location: Headquarters." + +**Usage Notes** +- Requires user consent for geolocation access in the browser. +- The script uses descriptive variable names for clarity and maintainability. +- Suitable for scenarios requiring geo-fencing compliance or location-based workflow restrictions. From ee37572c194c46d934ae55e9f2ee9fcf1bd097a4 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 23:48:51 +0530 Subject: [PATCH 11/14] Implement UserLocationUtils for location retrieval --- .../UserLocationUtils.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Dynamic Location Validation Approach/UserLocationUtils.js diff --git a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/UserLocationUtils.js b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/UserLocationUtils.js new file mode 100644 index 0000000000..5435dbd06b --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/UserLocationUtils.js @@ -0,0 +1,22 @@ +var UserLocationUtils = Class.create(); +UserLocationUtils.prototype = { + initialize: function() { + + }, + getUserLocationCoords: function() { + var user = gs.getUser(); + var loc = user.getRecord().location; + if (loc) { + var locGR = new GlideRecord('cmn_location'); + if (locGR.get(loc)) + return { + latitude: parseFloat(locGR.latitude), + longitude: parseFloat(locGR.longitude), + name: locGR.name.toString() + }; + } + return null; + }, + + type: 'UserLocationUtils' +}; From 88e9457c76fd3620e82ecd8f6514d2f2d8b45a1d Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 23:52:54 +0530 Subject: [PATCH 12/14] Update Readme with corrected script references --- .../Dynamic Location Validation Approach/Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md index 1aa0be3f69..68602d0bb4 100644 --- a/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md +++ b/Client-Side Components/Client Scripts/Dynamic Location Validation Approach/Readme.md @@ -2,8 +2,8 @@ This script restricts form submissions based on the physical location of the user. The current location is obtained using the browser’s geolocation API (latitude and longitude), and is then compared against the user's assigned business location stored in ServiceNow. **How It Works** -- The **server-side Script Include**(Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches the assigned business location’s latitude, longitude, and name for the logged-in user. -- The **client-side script**(Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) uses the browser API to obtain the current latitude and longitude of the user at form submission. +- The **server-side Script Include**(UserLocationUtils.js) fetches the assigned business location’s latitude, longitude, and name for the logged-in user. +- The **client-side script**(User Location Validator.js) uses the browser API to obtain the current latitude and longitude of the user at form submission. - It calculates the distance between these two points using the **Haversine formula**, which accounts for the spherical shape of the Earth. - The key constant `earthRadiusKm = 6371` defines the Earth's radius in kilometers and is essential for accurate distance calculation. - If the user’s current location is outside the predefined radius (default 10 km), the form submission is blocked with an error message showing the distance and allowed location. From 943b7e7532333fefa066d221e6641b52c956ec38 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 23:57:36 +0530 Subject: [PATCH 13/14] Delete Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md --- .../Readme.md | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md diff --git a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md deleted file mode 100644 index 1aa0be3f69..0000000000 --- a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/Readme.md +++ /dev/null @@ -1,19 +0,0 @@ -**User Location Validator** -This script restricts form submissions based on the physical location of the user. The current location is obtained using the browser’s geolocation API (latitude and longitude), and is then compared against the user's assigned business location stored in ServiceNow. - -**How It Works** -- The **server-side Script Include**(Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js) fetches the assigned business location’s latitude, longitude, and name for the logged-in user. -- The **client-side script**(Client-Side Components/Client Scripts/Dynamic Location Validation Approach/User Location Validator.js) uses the browser API to obtain the current latitude and longitude of the user at form submission. -- It calculates the distance between these two points using the **Haversine formula**, which accounts for the spherical shape of the Earth. -- The key constant `earthRadiusKm = 6371` defines the Earth's radius in kilometers and is essential for accurate distance calculation. -- If the user’s current location is outside the predefined radius (default 10 km), the form submission is blocked with an error message showing the distance and allowed location. -- If the user is within range, a confirmation info message is displayed and the submission proceeds. - -**Sample Output** -- **Success:** "Location validated successfully within range of Headquarters." -- **Failure:** "You are 15.23 km away from your registered location: Headquarters." - -**Usage Notes** -- Requires user consent for geolocation access in the browser. -- The script uses descriptive variable names for clarity and maintainability. -- Suitable for scenarios requiring geo-fencing compliance or location-based workflow restrictions. From 7f1ddbc0c6c2c3e75bde3b1515748218ff43dea8 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Thu, 16 Oct 2025 23:57:41 +0530 Subject: [PATCH 14/14] Delete Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js --- .../UserLocationUtils.js | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js diff --git a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js b/Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js deleted file mode 100644 index 5435dbd06b..0000000000 --- a/Server-Side Components/Script Includes/Dynamic Location Validation Approach/UserLocationUtils.js +++ /dev/null @@ -1,22 +0,0 @@ -var UserLocationUtils = Class.create(); -UserLocationUtils.prototype = { - initialize: function() { - - }, - getUserLocationCoords: function() { - var user = gs.getUser(); - var loc = user.getRecord().location; - if (loc) { - var locGR = new GlideRecord('cmn_location'); - if (locGR.get(loc)) - return { - latitude: parseFloat(locGR.latitude), - longitude: parseFloat(locGR.longitude), - name: locGR.name.toString() - }; - } - return null; - }, - - type: 'UserLocationUtils' -};