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

Sandeep Rajput
Tera Patron
Tera Patron

@Tomas Linde Could you please post both the scripts here, I will update them and provide a corrected version.

Yeah, thanks for you help.

Hi,

If the requirement is only for the caller 'Joe employee' then you just need one onSubmit client script:

AnilLande_0-1682010838639.png

 

 

function onSubmit() {
 var joeId = '681ccaf9c0a8016400b98a06818d57c7';
	if(g_form.getValue('caller_id')==joeId){
		alert("You cannot submit an incident for Joe Employee");
		return false;
	}   
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thanks for the help, but this story has to be done with a GlideAjax and in a more complex way ,like I do in my captures,
When testing, your version does not meet the criteria.