Check if caller is...

Tomas Linde
Tera Expert

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. 

1 ACCEPTED SOLUTION

@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.

Screenshot 2023-04-20 at 11.30.08 PM.png

 

Hope this helps. 

View solution in original post

7 REPLIES 7

@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.

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();
       
    }
}

@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.

Screenshot 2023-04-20 at 11.30.08 PM.png

 

Hope this helps.