Create Case or Incident via UI Action based on Conditions

morrix3
Giga Expert

Hello:

The following is what I need to accomplish:

Table: [Interaction]

Application: ITSM Workspace & Customer Service

Within the Agent Workspace Interaction there are a few UI Actions:

Create Incident - App: ITSM Workspace & Create Case - App: Customer Service

I need to deactivate these 2 and create a new one Called: Create Ticket.  This new UI Action should either create an Incident or a Case based on the Field: Account, if the account is such, generate an incident if it's this other then generate a Case.

I am puzzled about how to start this if I need to code everything in one UI Action? Or if I should create 2 UI Actions with the same name (Create Ticket) and then SHOW or HIDE based on the Account?

Please help; I would greatly appreciate any help with the Code that I would need for the UI Action or the conditions.

 

Thanks

 

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Morrix,

I recommend creating two UI actions based on the condition. Please refer below link to get started.

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/workspace/task/config...

 

- Pradeep Sharma

View solution in original post

10 REPLIES 10

You are very welcome Morrix. Would you mind marking my response as correct if I am able to resolve your issue.

 

Hi Pradeep:

I marked it. I have one more question, what if the field I need to set the condition against is a user reference field and instead of using the company as the condition for the UI Action I need the Role of the person on that field, which is called Contact.

 

Would something like current.contact == gs.hasRole('snc_external')  work?

Thanks.

Hi Morrix - You need to validate this via GlideRecord call to the sys_user_has_role by passing contact user to check if he has the right roles or not. This could be done via Script include where you can handle all the logic and return true or false output. Once you have the script you can then call the Script Include from UI action condition

Hi:

Any chance you have a script like that? or point me out where to find it? I have not been able to make it work and I am not an expert coding yet, i defend myself but this is kicking my butt.

I started like this but i dont think is working

var RoleChecker = Class.create();
RoleChecker.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

	verifyExternalRole: function(){
		var gr = newGlideRecord('sys_user_has_role');
		gr.addQuery('user', user_id);
		gr.addQuery('role','940ba702933002009c8579b4f47ffbe2'); //sys_id of snc_external
		
		gr.query();
		return gr.next();
		
	},
	_verifyInternalRole: function(){
		var gr = newGlideRecord('sys_user_has_role');
		gr.addQuery('user', user_id);
		gr.addQuery('role','7fcaa702933002009c8579b4f47ffbde'); //sys_id of snc_internal
		
		gr.query();
		return gr.next();
		
	},
    type: 'RoleChecker'
});

 

Condition: new RoleChecker()._verifyInternalRole(current.contact)

condition: new RoleChecker().verifyExternalRole(current.contact)

Sure. Below please find the updated Script Include Code.

Ui Action condition : new RoleChecker()._verifyInternalRole(current.contact)

Script Include:

var RoleChecker = Class.create();
RoleChecker.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

	verifyExternalRole: function(contact){
		var gr = newGlideRecord('sys_user_has_role');
		gr.addQuery('user', contact);
		gr.addQuery('role','940ba702933002009c8579b4f47ffbe2'); //sys_id of snc_external
		
		gr.query();
		return gr.next();
		
	},
	
    type: 'RoleChecker'
});