Client Script: User Assignment Checker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 06:13 AM - edited ‎09-29-2024 06:16 AM
I have a Client Script here where a confirmation message pops-up before proceeding with the user deactivation.
Now, how can I add the following requirement on the script?
If the user being deactivated is the assigned user on the "primary_contact" or "u_authorised_approvers" field on "customer_account" table then an alert message should show up asking to get the assigned user replaced on the mentioned fields first before proceeding with the deactivation.
They cannot proceed with deactivating it unless the user assigned to these fields are replaced.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 07:28 AM
Yes I also did that, here's my Script Include -
And called that Script Include in my Client Script but still did not work as expected. Please help.
---
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 08:33 AM - edited ‎09-29-2024 08:35 AM
Hello @tindiz I have tried to achieve the similar requirement using sys_user table where I have checked if the user we are trying to deactivate is a manager for any other user. You can modify the same thing based on your requirement in the addencodedQuery section mentioned in script include.
Here is what client script looks like:
Code in client script:
The Script include is called which looks like this:
 
Code in script include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 07:53 AM
Hi @tindiz
1. You need to make sure that your script include is client callable. You can do this by checking the 'Client callable' checkbox on the script include record. This will make sure the script include extends the AbstractAjaxProcessor class.
var UserAssignmentChecker = Class.create();
UserAssignmentChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// ....
type: 'UserAssignmentChecker'
});
2. I also think that you should add the 'OR' condition on one line in the query (but I could be wrong about this). See the code below.
var UserAssignmentChecker = Class.create();
UserAssignmentChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {
intialize: function () {},
hasAssignments: function (userId) {
gr = new GlideRecord("customer_account");
gr.addQuery("primary_contact", userId).addOrCondition("u_authrorised_approvers", userId);
gr.query();
return gr.hasNext();
},
type: 'UserAssignmentChecker'
});
Everything else looks fine at first sight. You could maybe do a 'console.log(response)' for some debugging.
Let me know if this works.
Kind regards,
Brian