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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Can you share what you've tried so far? You are mentioning having lots of trouble doing this, so guess you tried some things already?

I would imagine that you first have to define if it's a parent incident. You could do this with a display business rule performing a GlideRecord query to define if it's a parent or not, and pass a value like true/false to scratchpad.
Then with a onLoad Client Script, if the scratchpad is true, hide some fields.

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

Hey Mark,

Thanks for your response. Yes I have tried a few solutions. I am still new to ServiceNow and am having some trouble correlating business rules with client scripts.

I have a client script that sets a choice list based off of selection on the Incident Type field. This is currently working (for all incidents):

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

   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 then tried to create a Business Rule that is set to run on "Display":

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

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

if(grIncident.next()) {
   gs.addInfoMessage('PARENT!');
}

})(current, previous);

The Business Rule right now only displays the infoMessage for testing purposes. I'm lost at this point. I am not familiar with the scratchpad and how it works. How can I call the scratchpad in the client script? I tried another solution earlier that I deleted (can't remember what I did), but I got an error that said you cannot use server side scripts in a client script.

thanks!

 

Ah oke, when using the Business Rule I provided, in onLoad Client Script, you would have g_scratchpad.inc_parent available.

So you could start your onLoad Client Script with:

if(g_scratchpad.inc_parent == true) {
  <your code to hide fields / hide choices >
}

Or maybe g_scratchpad.inc_parent == "true" <-- so with quotes around true.

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

Read about Display Business Rules and scratchpad in this Docs page:
https://docs.servicenow.com/bundle/newyork-application-development/page/script/business-rules/concep...

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