Need to populate Field message with Child incident count in Parent incident in field message

praveen47
Tera Contributor

Hi Developers, 

 

I have a requirement like, 

 

I created one new field in INC form called "Resolution" field type is choice. It contains 'New' and 'Existing' choices. This field i am displaying only in parent incidents. When user select 'New' in parent incident, If that parent incident have child incidents still active need to dispaly field message as " You have  active child incidents, please close the child INC before closing parent INC" -- This message i need to show. If all the child incidents are inactive it did not show any message. Can any one help on the script part.

 

Example: If we have 4 child incidents for parent record, Info Message should be "You have 4 active child incidents, please close the child INC's before closing parent INC"

 

Thanks,

Praveen.

10 REPLIES 10

Hi @Bert_c1 , 

 

Thanks for your reply

I need to populate Number of active child incidents in the info message. 

 

For example: You have 4 active child incidents, please close the child INC's before closing the parent INC

 

I need this functionlaity in Info Message. Could you please help me on that.

 

Thanks, 

Praveen.

Hi,

 

You will get count of child incident by using getRowCount and print this in info message as below:

 

var activeChildIncidentsCount = grChild.getRowCount();

var message = "You have " + activeChildIncidentsCount + " active child incident";

g_form.addInfoMessage(message);

 

 

 

Thanks,

Sanika

You can add a line as follows:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   // Return if 'new' is selected
   if(newValue == 'new')		// 'new' is the choice value for "New"
	   return;
   
   // now check for active child incidents
	var incr = new GlideRecord('incident');
	incr.addQuery('parent', g_form.getUniqueValue());
	incr.addQuery('active', true);
	incr.query();
	ver noRecords = incr.getRowCount();
	if (incr.next()) {
		alert("You have " + noRecords + " active child incidents, please close the child INC before closing parent INC");
	}
}

 

I hope this helps.

@praveen47 I got the above to work after changing the line reference to getRowCount() to 

 

var noRecords = incr.rows.length;

praveen47
Tera Contributor

Hi @Ankur Bawiskar , 

 

Can you please help me on this.

 

Thanks, 

Praveen