
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
NOTE: MY POSTINGS REFLECT MY OWN VIEWS AND DO NOT NECESSARILY REPRESENT THE VIEWS OF MY EMPLOYER, ACCENTURE.
DIFFICULTY LEVEL: Beginner
Assumes has good beginner level of knowledge and/or familiarity with ServiceNow and some familiarity with JavaScript.
So here are a couple of techniques I found in the out-of-the-box code base, and thought I would bring them into the light of day. Did you know that you can constrain what fields are displayed on a form with a System Property, a Display Rule, and a g_scratchpad variable?
Lab — Limit Field and Section Display
1. Create a new system property
a. Navigate to the System Properties list view by typing the following into the navigation field: sys_properties.list
b. Click the New button. The new System Property form will be displayed.
c. Fill in the form with the following:
- Name: incident.show.subcategory
- Description: Turn off Subcategory
- Choices: true/false
- Type: true | false
- Value: true
d. Right-click on the form header to display the context menu, and click Save.
e. At the bottom of the form in Related Links click on the New button. The new Category form will appear.
f. Fill in the form with the following:
- Name: Incident
- Leave everything else as default
Your form should look like this:
g. Click the Submit button to save.
2. Create a new Property Module For Incidents
a. Navigate to the Incidents application
b. Click on the Edit Application button for Incidents.
c. The Incident Application Menu will be displayed.
d. Scroll down and on the Modules List View click the New button. This will display the new Module form.
e. Fill in the form with the following:
i. Title: Properties
ii. Application Menu: Incident (should already be filled in)
iii. Order: 5000 or something way down.
iv. Hint: Incident Properties
v. Visibility tab:
- Roles: Admin
- Active: Checked
vi. Link Type tab:
- Link Type: URL (from arguments)
- Arguments: system_properties_ui.do?sysparm_title=Incident&sysparm_category=Incident
Your form should look like this:
f. Click the Submit button to save. The Properties module should immediately appear in the Incident Application Menu Modules list view.
g. Refresh the browser to get the new Properties module to show.
h. Navigate to All > Incident > Administration and Click on the new Properties link and see that the new property is displayed and defaulted to checked.
3. Create a Display Business Rule
- Navigate to System Definition -> Business Rules
- Click the New button to create a new Business Rule. A blank Business Rule form will be displayed.
- Fill out the form with the following:
- Name: Show Subcategory
- Table: Incident
- Order: 5000 or some such down toward the bottom
- When to run:
- When: display
- Advanced:
- Script:
function onDisplay(current, g_scratchpad) {
g_scratchpad.showSubCategory = gs.getProperty('incident.show.subcategory', true);
}
Your form should look like this:
d. Click the Submit button to save.
4. Create a Client Script to react to the g_scratchpad variable
- Navigate to System Definition -> Client Scripts. The client scripts list view will be displayed.
- Click the new button. A blank client script form will be displayed.
- Fill in the form with the following:
- Name: Show Subcategory
- Table: Incident
- UI Type: Desktop
- Type: onLoad
- Active: checked
- Global: checked
- Description: Show or hide the Subcategory field based on a g_scratchpad variable.
- Script:
function onLoad() {
g_form.setVisible('subcategory', g_scratchpad.showSubCategory == 'true');
// for grins let's turn off the Task SLAs section (tab) at the bottom of the form to show it can be done!
if (g_scratchpad.showSubCategory == 'false') {
g_form.hideRelatedList('task_sla');
}
}
Your form should look like this:
d. Click the Submit button to save.
Now we are ready to test our new functionality!!!!
5. Test
- Our initial test will be to take the default of the property: true. And make sure that normal functionality is there.
- Navigate to Incident -> Open, and open an existing incident. The Subcategory field should be present and the Task SLAs tab at the bottom of the form should be there.
Scroll down and check that the Task SLAs tab is present.
c. Now Navigate to Incident -> Properties, and uncheck the Turn off Subcategory check box.
d. Click the Save button.
e. Navigate back to Incident -> Open, and open and existing incident. The Subcategory field should be missing, and the Task SLAs tab will be gone as well!
and...gone!
Conclusion
So, now you see how using the combination of a System Property, a Display Business Rule, a g_scratchpad variable and a Client Script can be used to control what is displayed on a form. Cool huh?!
Enjoy!
Steven Bell.
If you find this article helps you, don't forget to log in and mark it as "Helpful"!
Originally published on: 9-14-2015 07:03 AM
I updated the code and brought the article into alignment with my new formatting standard.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.