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

Bert_c1
Kilo Patron

Hi Praveen47,

 

It seems you can use a Client Script that runs 'onChange' for the incident table and [field_name].  The following script may work (I haven't tested yet).

 

 

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.getSysId());
	incr.addQuery('active', true);
	incr.query();
	if (incr.next()) {
		alert("You have  active child incidents, please close the child INC before closing parent INC");
	}
}

 

 

I made a guess at the choice value for "New".

 

And after a quick test, getting the sys_id value of the record open is not working in the above. 😞 Need to find another way for that.

Sanika Subhash
Tera Expert

Hi Praveen,

 

Certainly! You can achieve this functionality by using a client script on the parent incident form. Here's an example of how you can implement it:

1. Create a new client script for the parent incident table.
2. Set the `Type` field of the client script to `OnChange`.
3. In the `Condition` field, enter the following condition: `current.resolution == 'New'`.
4. Add the following code to the `Script` field:


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

var grChild = new GlideRecord('incident');
grChild.addQuery('parent', current.sys_id);
grChild.addQuery('active', true);
grChild.query();

if (grChild.hasNext()) {
g_form.addInfoMessage("You have active child incidents, please close the child INC before closing the parent INC");
}
}


This script will execute whenever the `Resolution` field on the parent incident form is changed and the new value is 'New'. It will then query for any active child incidents associated with the parent incident. If there are any active child incidents, it will display an information message on the form.

Make sure to replace `'incident'` with the correct table name if you are using a different table for child incidents.

Note: Remember to publish the client script and test it by creating or updating a parent incident and selecting the 'New' resolution to see the message when there are active child incidents.

 

If this is helpful to you then please mark it as helpful and correct.

 

Thanks,

Sanika

Hi @Sanika Subhash  ,

 

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.

Bert_c1
Kilo Patron

Hi Paveen47,

 

The following works in the above client script.

 

incr.addQuery('parent', g_form.getUniqueValue());