ServiceNow HRSD

jishnusaina
Tera Contributor

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.

 

jishnusaina_0-1749299511114.png

 

3 REPLIES 3

Abbas_5
Tera Sage
Tera Sage

Hello @jishnusaina,

 

To hide fields in an HR case (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. 
Steps:
  1. 1. Identify the target fields:
    Determine the specific fields in the sn_hr_core_case table that need to be hidden.
  2. 2. Create a table-level script:
    • Create a script for the sn_hr_core_case table that runs on the before_insert or after_load event. This script will evaluate the assigned_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.
  3. 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. 
       
Example (simplified script):
// 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");}
Explanation:
  • 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.
     
Key Considerations:
  • 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.
     
By implementing this approach, you can dynamically control the visibility of fields in HR cases based on the assignment group of the related HR task, ensuring that sensitive information is hidden when necessary.
 
If this is helpful, please hit the thumbs up button and accept the correct solution by referring to this solution in future it will be helpful to them.
 
Thanks & Regards,
Abbas Shaik

Hi Abbas,

 

Thanks for your response but need to hide in preview which is get from parent table  

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