How to show/hide fields on parent/child incident

mkader
Kilo Guru

Hello,

I need to hide certain fields on a parent incident only and am having lots of trouble doing this. I also need to change choice list on certain fields based on incident type selection (this is also only on the parent incident). 

Thanks!

1 ACCEPTED SOLUTION

Noah Drew
ServiceNow Employee
ServiceNow Employee

Hi @mkader !

In regards to hiding the fields, I would use a UI Policy for simplicity.

To do so:

1. Go to System UI > UI Policies

2. Set the Table to "Incident [incident]"

3. Change the Conditions to [   Parent   |   is empty   ]

4. Save the record

5. In the UI Policy Actions related list, add the fields you want to hide and make sure to set the Visible dropdown to "false"

 

Now with the UI Policy in place, we can further expand into hiding the Choice Lists.

1. Go to the Script tab in the UI Policy we created

2. Check "Run Scripts"

3. In the Execute If True box change the code to suit your business needs. As an example, this code will remove the first choice of the Impact field:

 

function onCondition() {

g_form.removeOption('impact', '1');

}

 

Hope that helps!

If it did, please mark as Helpful and consider setting the reply as the Correct Answer to the question, thanks!

View solution in original post

13 REPLIES 13

" but I got an error that said you cannot use server side scripts in a client script."

That's why we actually use the g_scratchpad, to do the query server side within Business Rule, and passing the result through g_scrathcpad to the Client Script.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

@Mark Roethof ,

I'm still having some trouble with this. So I set my current Client Script to Inactive and create a new one. I copied what I had within the onChange() client Scrient Scipt and moved it to the onLoad():

function onLoad() {

    if (g_scratchpad.inc_parent == true) {

        var incType = g_form.getValue('u_inc_type');
   
	//modify choice list for Resolution based off of Incident Type
	if(incType == "Information") {
		g_form.clearOptions('u_selection');
		g_form.addOption('u_selection', '', '-- None --', '0');
		g_form.addOption('u_selection', 'No Information Provided', 'No Information Provided');
		g_form.addOption('u_selection', 'Information Missing', 'Information Missing');
	} else if(incType == "Response") {
		g_form.clearOptions('u_selection');
		g_form.addOption('u_selection', '', '-- None --', '0');
		g_form.addOption('u_selection', 'Response needed', 'Response needed');
		g_form.addOption('u_selection', 'Add to Incident', 'Add to Incident');
	} 
   }
}

 

I also tried to use the exact same business rule that you provided:

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('incident');
	gr.addQuery('parent', current.getUniqueValue());
	gr.setLimit(1);
	gr._query();

	g_scratchpad.inc_parent = false;
	if(gr.hasNext()) {
		g_scratchpad.inc_parent = true;
	}

})(current, previous);

 

To test if this was functioning, I tried to create a new incident, and my choice list was now no longer working. I also tried to modify a Parent and Child Incident and the same thing was happening. It was bringing back the entire list of options. I used the onChange() method because when an option from the Incident Type field is selected, the following fields choice list needs to be updated with the proper choices. 

Mark Roethof
Tera Patron
Tera Patron

For example, I quickly setup below display Business Rule (= tested), which passes a g_scratchpad.inc_parent. This will be true or false.

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('incident');
	gr.addQuery('parent', current.getUniqueValue());
	gr.setLimit(1);
	gr._query();

	g_scratchpad.inc_parent = false;
	if(gr.hasNext()) {
		g_scratchpad.inc_parent = true;
	}

})(current, previous);

You can simply use the g_scratchpad.inc_parent now within a onLoad Client Script.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Noah Drew
ServiceNow Employee
ServiceNow Employee

Hi @mkader !

In regards to hiding the fields, I would use a UI Policy for simplicity.

To do so:

1. Go to System UI > UI Policies

2. Set the Table to "Incident [incident]"

3. Change the Conditions to [   Parent   |   is empty   ]

4. Save the record

5. In the UI Policy Actions related list, add the fields you want to hide and make sure to set the Visible dropdown to "false"

 

Now with the UI Policy in place, we can further expand into hiding the Choice Lists.

1. Go to the Script tab in the UI Policy we created

2. Check "Run Scripts"

3. In the Execute If True box change the code to suit your business needs. As an example, this code will remove the first choice of the Impact field:

 

function onCondition() {

g_form.removeOption('impact', '1');

}

 

Hope that helps!

If it did, please mark as Helpful and consider setting the reply as the Correct Answer to the question, thanks!

Thanks for your response!

I have several UI Policies setup, I will add some more fields that hide the child incident. If you see my reply to Mark Roethof above, I have a client script that clears the options and adds a list. My problem is doing this only for the Parent Incident and not the Child.