- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 09:19 AM
Hello
I am a junior developer and I have this story with this client script and half include script, I am stuck since it does not execute me correctly and it meets the specifications of the story, I hope you can help me, regards.
As a Process User (itil)
I want that when an incident is submitted, the system checks if the caller is "Joe Employee". If that is the case, an alert must inform that "You cannot submit an incident for Joe Employee" and prohibit incident submission. This should work for new and existing incident
SO THAT Joe Employee is cannot submit incidents
I know this is complete when I cannot have an incident with Joe Employee as the caller.
Portal is not in scope.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 11:03 AM - edited 04-20-2023 11:04 AM
@Tomas Linde Here is your solution
onSubmit Client Script:
function onSubmit() {
var sysId = g_form.getValue('caller_id');
var gaIsJoeEmployee = new GlideAjax('global.IncidentFunction');
gaIsJoeEmployee.addParam('sysparm_name', 'isEmployee');
gaIsJoeEmployee.addParam('sysparm_name_sysid', sysId);
gaIsJoeEmployee.getXMLWait();
var answer = gaIsJoeEmployee.getAnswer();
if (answer == 'true') {
g_form.clearMessages();
g_form.showFieldMsg('caller_id', 'You cannot submit an incident for Joe Employee', 'error');
return false;
} else {
g_form.clearMessages();
}
}
Here is the code for Script Include.
var IncidentFunction = Class.create();
IncidentFunction.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isEmployee: function() {
//var userIsEmployee = this.getParameter('sys_param_name');
var userSysId = this.getParameter('sysparm_name_sysid');
var grName = new GlideRecord('sys_user');
gs.info('I wss here');
grName.addQuery('name', 'Joe Employee');
grName.addQuery('sys_id', userSysId);
grName.query();
var answer = 'false';
if (grName.next()) {
answer = 'true';
}
return answer;
},
type: "IncidentFunction"
});
Here is how the end result looks.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 10:20 AM
@Tomas Linde By script, I meant to say the client and script include scripts in textual form not in image form. This way I will be able to edit them quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 10:24 AM
var IncidentFunction = Class.create();
IncidentFunction.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isEmployee: function() {
var userIsEmployee = this.getParameter('sys_param_name');
var userSysId = this.getParameter('sys_param_name_sysid');
var grName = new GlideRecord('sys_user');
grName.addQuery('name', 'Joe Employee');
grName.addQuery('sys_id', 'userSysId');
grName.query();
if (grName.get()) {
var answer = true;
}
return answer;
},
type: "IncidentFunction"
});
function onSubmit() {
var sysId = g_form.getValue('isEmployee');
var gaIsJoeEmployee = new GlideAjax('global.IncidentFunction');
gaIsJoeEmployee.addParam('sys_param_name', 'getName');
gaIsJoeEmployee.addParam('sys_param_name_sysid', 'sysId');
gaIsJoeEmployee.getXMLWait();
if (answer == true) {
g_form.clearMessages();
g_form.showFieldMsg('caller_id', 'You cannot submit an incident for Joe Employee', 'error');
return false;
} else {
g_form.clearMessages();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 11:03 AM - edited 04-20-2023 11:04 AM
@Tomas Linde Here is your solution
onSubmit Client Script:
function onSubmit() {
var sysId = g_form.getValue('caller_id');
var gaIsJoeEmployee = new GlideAjax('global.IncidentFunction');
gaIsJoeEmployee.addParam('sysparm_name', 'isEmployee');
gaIsJoeEmployee.addParam('sysparm_name_sysid', sysId);
gaIsJoeEmployee.getXMLWait();
var answer = gaIsJoeEmployee.getAnswer();
if (answer == 'true') {
g_form.clearMessages();
g_form.showFieldMsg('caller_id', 'You cannot submit an incident for Joe Employee', 'error');
return false;
} else {
g_form.clearMessages();
}
}
Here is the code for Script Include.
var IncidentFunction = Class.create();
IncidentFunction.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isEmployee: function() {
//var userIsEmployee = this.getParameter('sys_param_name');
var userSysId = this.getParameter('sysparm_name_sysid');
var grName = new GlideRecord('sys_user');
gs.info('I wss here');
grName.addQuery('name', 'Joe Employee');
grName.addQuery('sys_id', userSysId);
grName.query();
var answer = 'false';
if (grName.next()) {
answer = 'true';
}
return answer;
},
type: "IncidentFunction"
});
Here is how the end result looks.
Hope this helps.