ServiceNow HRSD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2025 05:32 AM
I have HR task in table( sn_hr_core )and hr_core_case i need to hide if assigned to one group in hr task table need to hide 2 feilds in hr core case please check the below screenshot I need to hide in preview and variable section as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2025 07:23 PM
Hello @jishnusaina,
sn_hr_core_case
) based on the assignment group of a related HR task (sn_hr_core
), you'll need to use a combination of a table-level script and field visibility controls in ServiceNow. This approach will hide the fields in the case form, preview section, and variable set, effectively making them invisible to users when the related task is assigned to the specific group. -
1. Identify the target fields:Determine the specific fields in the
sn_hr_core_case
table that need to be hidden. -
2. Create a table-level script:
- Create a script for the
sn_hr_core_case
table that runs on thebefore_insert
orafter_load
event. This script will evaluate theassigned_to
field of the related HR task and determine whether to hide the target fields. - Use the
g_form.hide_field()
method to hide the fields.
- Create a script for the
-
3. Implement field visibility:
- Use the
g_form.hide_field()
method in the script to hide the specified fields. This method effectively removes the fields from the form and prevents them from being displayed in the preview section or variable set.
- Use the
// This script will hide the "field1" and "field2" fields in HR Case (sn_hr_core_case)
// when the related HR Task (sn_hr_core) is assigned to the group "Group ABC"
if (current.assigned_to.getGroup().name == "Group ABC") {
g_form.hide_field("field1");
g_form.hide_field("field2");
}
- The
g_form.hide_field()
method is used to hide the specified field. - The script checks if the
assigned_to
field of the HR task is equal to a specific group (e.g., "Group ABC"). - If the condition is met, the script hides the target fields.
-
Event Selection:Choose the appropriate event (before_insert or after_load) based on the use case.
-
Script Execution:Ensure the script is executed correctly and that the logic for hiding the fields is accurate.
-
Preview Section and Variable Set:The script should hide the fields in both the main form and the preview or variable set areas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2025 07:07 AM
Hi Abbas,
Thanks for your response but need to hide in preview which is get from parent table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2025 06:56 PM
Hello @jishnusaina,
Please refer to the link below:
https://www.servicenow.com/community/itsm-forum/hide-the-specific-fields-in-preview-record/m-p/24241...
If it is helpful, please hit the thumbs-up button and accept this solution as the correct answer. By referring to it in the future, it will be helpful to others.
Thanks & Regards,
Abbas Shaik