Set Additional Comments when INC state is resolved.

Naveen87
Tera Guru

Hey Developers,

 

I want to set a string under Additional comments on Incident form when Contact type  = Event & state is resolved.

I tried below script but no luck

Please suggest.

 

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Naveen87
Tera Guru

This worked.

Thank you  - Anurag Tripathi for ur time on this.

 
 
 

find_real_file.png

View solution in original post

7 REPLIES 7

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Really don't see any issue with the script and BR in general,

Can you just try to change the order and see.

 

Also you can try to change the condition incident state <changes to> Resolved.

 

PS. since this is a event type incident, i would like to add that if the transaction that makes the incident state to resolved, uses setWorkflow(false) anywhere, then BR doesnt run, and also comments/ work notes  don't get updated.

So test this manually changing the incident state field.

-Anurag

 

-Anurag

Hi,

 

I changed the condition , state-->changes to --> resolved & order of BR.

Its working manually.

So we have made Additional comments mandatory when state changes to resolved.

Manually when we fill it , INC is getting resolved but not via Clear Alert as there are mandatory fields on Form.

So trying to set a fixed string value to field when Contact type is Event.

Not sure whats wrong here.

 

Can u suggest a client script?

 

Something like this, This vague. As i'm not good in this part.

 

var type = g_form.getValue('contact_type');

if(type=='Event')
{
g_form.setValue('comment', 'Auto Resolved');
}

 

forget everything, forget script and how to do it. 

Just tell me this.

When contact type is event, how are the incidents resolved? Is there an agent that goes in the form and resolves it? is there an auto resolve script or workflow or something like that?

-Anurag

They Trigger an Event to create an Incident & on same Alert they send Clear Event to resolve the Incident.

 

 

find_real_file.png

 

There is a BR which does it I believe.

 

find_real_file.png

(function executeRule(current, previous)
{
	//If we have a bound CI, retrieve the assignment Group and support Group from the current CI and store on the Task
	if(current.cmdb_ci!=''&& current.assignment_group.nil())
		{
		var cmdb = new GlideRecord("cmdb_ci");
		cmdb.addQuery('sys_id',current.cmdb_ci);
		cmdb.query();
		if(cmdb.next())
			{
			if(cmdb.assignment_group!='')
				{
				
				current.assignment_group=cmdb.assignment_group;
				current.u_support_group=cmdb.support_group;
			}
			else
				{
				
				
				//Case when bound CI doesn't have an assignment group, check the node CI for an Assignment Group
				var alertNode = current.u_alert.node + "";
				var count;
				var count1;
				var count2;
				if(alertNode!=''){
					//gs.log("Checking if alert node value is not blank- " +alertNode);
					var cmdb1 = new GlideRecord("cmdb_ci");
					cmdb1.addQuery("name",alertNode);
					cmdb1.addQuery("sys_class_name",'!=',"cmdb_ci_ip_address");
					cmdb1.query();
					count = cmdb1.getRowCount();
					//gs.log("Row count for name value is- " +count);
					while (cmdb1.next()) {
						if (cmdb1.assignment_group!='') {
							//gs.log("Found a record with Node name");
							current.work_notes = "Respective CI assignment group is empty, Node CI -"+ current.u_alert_node+ " Node Name of CI updating Assignment group with this Node CI assignment group";
							current.assignment_group=cmdb1.assignment_group;
							current.u_support_group=cmdb1.support_group;
						}
					}
					if (count == 0) {
						cmdb1 = new GlideRecord("cmdb_ci");
						cmdb1.addQuery("ip_address",alertNode);
						cmdb1.addQuery("sys_class_name",'!=',"cmdb_ci_ip_address");
						cmdb1.query();
						count1 = cmdb1.getRowCount();
						//gs.log("Row count for IP_Address value is- " +count1);
						while (cmdb1.next()) {
							if (cmdb1.assignment_group!='') {
								//gs.log("Found a record with IP address");
								current.work_notes = "Respective CI assignment group is empty, Node CI -"+ current.u_alert_node+ " IP address of CI updating Assignment group with this Node CI assignment group";
								current.assignment_group=cmdb1.assignment_group;
								current.u_support_group=cmdb1.support_group;
							}
						}
						if (count1 == 0) {
							cmdb1 = new GlideRecord("cmdb_ci");
							cmdb1.addQuery("fqdn","CONTAINS",alertNode);
							cmdb1.query();
							count2 = cmdb1.getRowCount();
							//gs.log("Row count for FQDN value is- " +count2);
							while (cmdb1.next()) {
								if (cmdb1.assignment_group!='') {
									//gs.log("Found a record with FQDN");
									current.work_notes = "Respective CI assignment group is empty, Node CI -"+ current.u_alert_node+ " FQDN of CI updating Assignment group with this Node CI assignment group";
									current.assignment_group=cmdb1.assignment_group;
									current.u_support_group=cmdb1.support_group;
								}
							}
						}
					}
				}
			}
		}
	}
	
	//var domain=current.sys_domain;
//	var theater;
	var usedEventType;
	var category;
	var subcategory;
	var support_group;
	var assignGroup;
	var createInc;
	var forceAssign;
	var eventType;
	var corNode;
	var corType;
	var eventTypeName;
	
/* 	var grEvent= new GlideRecord('domain');
	grEvent.addQuery('sys_id',domain);
	grEvent.query();
	if(grEvent.next());
		{
		usedEventType= grEvent.u_use_event_type_table;
		theater= grEvent.u_theatre;
		
	} */
	
	

		var type=current.u_alert.type;
	    gs.log("Type is " + type);
		var grEventLookup1= new GlideRecord('u_event_type_lookup');
		grEventLookup1.addQuery('u_event_type',type);
		//grEventLookup1.addQuery('u_domain',domain);
		grEventLookup1.addQuery('u_active',true);
		grEventLookup1.query();
		if(grEventLookup1.next()){
			//gs.log("CAtegory is " + grEventLookup1.u_category);
			category=grEventLookup1.u_category;
			subcategory=grEventLookup1.u_sub_category;
			support_group=grEventLookup1.u_support_group;
			assignGroup=grEventLookup1.u_assignment_group;
			createInc=grEventLookup1.u_create_incident;
			forceAssign=grEventLookup1.u_force_assignment;
			corNode=grEventLookup1.u_correlate_at_node_field;
			corType=grEventLookup1.u_correlate_at_type_field;
		}

			if(corNode==true&&corType==false){
				
				current.description = 'This Incident was generated from one or more Events that are related at the Node Level.   To get more details on all of the events view the related Alert and from the Alert view the related events.\n'+current.description;
			}
			else if(corType==true&&corNode==false){
				
				current.description = 'This Incident was generated from one or more Events that are related at the Type Level.   To get more details on all of the events view the related Alert and from the Alert view the related events.\n'+current.description;
			}
			
			
			if(createInc==true){
				
				if(current.category==''){
					current.category=category;
					
				}
				if(current.subcategory==''){
					current.subcategory=subcategory;
				}
				if(current.assignment_group==''){
					current.assignment_group=assignGroup;
				}
				if(forceAssign==true){
					current.assignment_group=assignGroup;
					current.u_support_group=support_group;
				}
			}
			
			if(current.category==''||current.subcategory==''||current.assignment_group==''){
				
				var gr_emEvent= new GlideRecord('em_event_type');  // Default record check
				gr_emEvent.addQuery('name','Default');
				gr_emEvent.query();
				if(gr_emEvent.next()){
					var eventId=gr_emEvent.sys_id;
					var grEventLookup4= new GlideRecord('u_event_type_lookup');
					grEventLookup4.addQuery('u_event_type',eventId);
					//grEventLookup4.addQuery('u_domain',domain);
					grEventLookup4.query();
					if(grEventLookup4.next()){
						if(current.category==''){
							current.category=grEventLookup4.u_category;
						}
						if(current.subcategory==''){
							current.subcategory=grEventLookup4.u_sub_category;
						}
						if(current.assignment_group==''){
							current.assignment_group=grEventLookup4.u_assignment_group;
						}
						
					}
					
				}
				
			}
			
			
		
		
		
		//If we don't have a bound CI, Bind to CI_Not_Found
		if(current.cmdb_ci.nil())
			{
			
			var gr = new GlideRecord("cmdb_ci");
			gr.addQuery("name","CI_Not_Found");
			gr.query();
			if(gr.next())
				{
				
				current.cmdb_ci = gr.sys_id;
				if(current.assignment_group.nil())
					{
					current.assignment_group=gr.assignment_group;
					current.u_support_group=gr.support_group;
				}
				current.work_notes = "ERROR - The Configuration item for this Alert condition is not found in the CMDB. CI_Not_Found has been assigned as the Configuration item.";
			}
		}
		
		//If Assignment Group is still blank after all of the above, take the value from the CI_NOT_FOUND record
		if(current.assignment_group.nil())
			{
			
			var gr_cmdb= new GlideRecord("cmdb_ci");
			gr_cmdb.addQuery("name","CI_Not_Found");
			//gr_cmdb.addQuery('sys_domain',current.sys_domain);
			gr_cmdb.query();
			if(gr_cmdb.next())
				{
				
				current.assignment_group=gr_cmdb.assignment_group;
				current.u_support_group=gr_cmdb.support_group;
			}
		}
	//gs.log("Automation BeforeAlert query");
 		var grAlert= new GlideRecord('em_alert');
 		grAlert.addQuery('sys_id',current.u_alert);
		grAlert.query();
		if(grAlert.next()){
		var rba= grAlert.u_rba;
 			if(rba!=''&&current.u_alert.cmdb_ci!=''&&(current.u_alert.state=='Open' || current.u_alert.state=='Reopen'))
 			{
				//gs.log("Automation assignment group");
 				var group=current.assignment_group;
				
 				//New logic to store assignment group value in custom field on Alert table
 				//Below If is to retain the original u_alert_assignment_group value for system that use reopen
				
 				if(gs.nil(grAlert.u_alert_assignment_group))
 					{
 						grAlert.u_alert_assignment_group = group;
 				        grAlert.update();
 					}
				
				
 				var dataCollection= new GlideRecord('u_custom_data_collection');
 				dataCollection.initialize();
 				//dataCollection.sys_domain=domain;
 				dataCollection.u_category='Reassign incident';
 				dataCollection.u_component1=current.u_alert.number;
 				dataCollection.u_assignment_group=group;
 				var a=dataCollection.insert();
				//gs.log("Automation Custom collection");
 				current.assignment_group='1ffee5e6db4383403216f3e31d96194f';
				current.assigned_to="1fe896b5db4344d425db309e7c961930";
				//gs.log("Automation New assignment");
 			}
 		}
		
		
	})(current, previous);