Catalog client scripts and record deletion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 08:47 AM
Greetings,
I have a catalog client script that performs validation on a record producer onSubmit.
I am running into a bit of a problem when I attempt to delete a user record from within the catalog client script.
I found the following Servicenow document that discusses limited use of some GlideRecord functionality inside client side scripts, such as client scripts
However, the code isn't working and I am beginning to believe that the documentation is incorrect and record deletions cannot be performed in client scripts for regular ITIL users.
Below is a snapshot of my catalog client script:
If I can't perform a delete from a catalog client script, does anyone have any recommendations on how I can accomplish my goal of deleting a user record as an ITIL user when validating a record producer?
Thanks much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2016 09:43 AM
Hi Ivan,
Yes, because I get the correct pop-up text for that condition.
Solo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 05:25 PM
Use the script without callback function. That should do the trick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2016 09:42 AM
I did try it without the callback initially and it didn't work. It was original like so:
function onSubmit() {
//Type appropriate comment here, and begin script below
un = g_form.getValue('secondary_account');
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', un);
gr.query();
if (gr.next()) {
if (!gr.uniqueid_euuid_) {
alert("Account '" + un + "' already exists, however, the UUID is empty.\n\nTherefore, this stud account will be deleted and the new account will be provisioned.");
gr.deleteRecord();
return true;
}
else {
alert("Nothing will be done. Account '" + un + "' already exists and the UUID is: " + gr.uniqueid_euuid_);
return false;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2016 07:48 PM
As a rule of thumb, business logic should not be implemented client side.
You should do this on the workflow for this item, or in a After Business Rule.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2016 04:26 PM
I changed the code so that a script include is called from the catalog client script and I still can't get a record deleted as an ITIL user:
Script Include:
var OITUserDelete = Class.create();
OITUserDelete.prototype = Object.extendsObject(AbstractAjaxProcessor, {
removeUserRecord: function() {
var argParam1 = this.getParameter('sysparm_param1');
var rec = new GlideRecord('sys_user');
if (rec.get(argParam1)) {
return rec.deleteRecord();
}
},
type: 'OITUserDelete'
});
Catalog Client Script:
function onSubmit() {
//Type appropriate comment here, and begin script below
un = g_form.getValue('secondary_account');
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', un);
gr.query();
if (gr.next()) {
if (!gr.uniqueid_euuid_) {
alert("Account '" + un + "' already exists, however, the UUID is empty.\n\nTherefore, this stud account will be deleted and the new account will be provisioned.");
var ga = new GlideAjax('OITUserDelete');
ga.addParam('sysparm_name','removeUserRecord');
ga.addParam('sysparm_param1',un);
ga.getXML(callBackFunction);
}
else {
alert("Nothing will be done. Account '" + un + "' already exists and the UUID is: " + gr.uniqueid_euuid_);
return false;
}
}
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == true) {
return;
}
}
}
I just don't get why the record isn't being deleted. The client callable check box is checked in the script include. What am I missing now?