Script Include is being blocked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 05:32 AM
Hello everyone, so I created a Script Include to check if a user is assigned on the fields primary_contact or u_authorised_approvers in customer_account table. This is how it looks like -
And then I created a Client Script - this script is designed to handle edits in a customer_contact table by confirming user deactivation actions and checking if the user is assigned in specific roles.
Here's the complete script
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = false;
// Type appropriate comment here, and begin script below
if ((newValue == false || newValue == 'false') && g_user.hasRole('sn_customerservice_manager')) {
var confirmation = confirm('Are you sure you want to deactivate this user? This action cannot be undone.');
if (confirmation) {
saveAndClose = true;
}
}
// Check if the user is assigned as primary_contact or in u_authorised_approvers
var userIdToCheck = g_user.sys_id; // Assuming you want to check the current user's sys_id
// Create a new GlideAjax object
var ga = new GlideAjax('UserAccountChecker');
ga.addParam('sysparm_name', 'isUserAssigned');
ga.addParam('sysparm_user_id', userIdToCheck); // Pass the user sys_id
// Call the Script Include
ga.getXMLAnswer(function(response) {
var isAssigned = response === 'true';
if (isAssigned) {
alert('This user is assigned as primary_contact or in u_authorised_approvers.');
// Optionally, you could prevent further actions here
} else {
// Proceed with the original logic
callback(saveAndClose);
}
});
// Return false to avoid calling callback immediately
return false;
}
Now, whenever I tried to change the active field from true to false in customer_contact table, I am getting the confirmation message which is expected but not the alert message and I am getting the below message stating that my Script Include is being blocked.
I tried to create an ACL as show below but it didn't help resolving the issue.
P.S. I just deactivated it for the meantime, but it was active when I was testing it.
Please help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 05:35 AM
@tindiz Instead of creating the ACL in Global scope, you should instead create it in the Customer Service Scope. Once created the ACL related issue will not appear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 05:41 AM
Since your Client Script is in a different scope than the Script Include, you need to add the application scope to the GlideAjax call
var ga = new GlideAjax('global.UserAccountChecker');
Your Script Include is marked Client callable, but this must have been checked after the script was populated, so the first line does not include extended object
var UserAccountChecker = Class.create();
UserAccountChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserAssigned: function() {
...
},
type: 'UserAccountChecker'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 06:14 AM
Hello, I followed your advice, I fixed my scripts and this is how it look like now -
SCRIPT INCLUDE:
And then I updated my Client Script:
But when I tested it, I am still getting the confirmation message which is expected, no longer getting the Script Include blocked message but the alert message is still not coming up. I am not sure which part is not making it work as expected.
Here's the complete Client Script:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = false;
// Type appropriate comment here, and begin script below
if ((newValue == false || newValue == 'false') && g_user.hasRole('sn_customerservice_manager')) {
var confirmation = confirm('Are you sure you want to deactivate this user? This action cannot be undone.');
if (confirmation) {
saveAndClose = true;
}
}
// Check if the user is assigned as primary_contact or in u_authorised_approvers
var userIdToCheck = g_user.sys_id; // Assuming you want to check the current user's sys_id
// Create a new GlideAjax object
var ga = new GlideAjax('global.UserAccountChecker');
ga.addParam('sysparm_name', 'isUserAssigned');
ga.addParam('sysparm_user_id', userIdToCheck); // Pass the user sys_id
// Call the Script Include
ga.getXMLAnswer(function(response) {
var isAssigned = response === 'true';
if (isAssigned) {
alert('This user is assigned as primary_contact or in u_authorised_approvers.');
// Optionally, you could prevent further actions here
} else {
// Proceed with the original logic
callback(saveAndClose);
}
});
// Return false to avoid calling callback immediately
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 06:32 AM
In the Script Include you need to get the parameter like this, not in an argument in the function declaration
var userId = this.getParameter('sysparm_user_id');
For more troubleshooting, add some gs.info lines to the Script Include to confirm it is running and see how far it is getting.
You should also review this excellent guide on GlideAjax