isFieldVisible() not working on portal.

abhaysingh98
Tera Contributor

Hi All,

 

I am working on a client script where I am getting data from script include but the issue is that when I tried to filter field based on visibility on form then isFieldVisible() is only working on form UI but on portal I am getting error as 'there is javascript error' and when I try to use isVisible() then its only working on portal not on form UI.

4 REPLIES 4

palanikumar
Mega Sage

Hi,

You can check whether the script is running on Service Portal or Form UI and run you condition accordingly

For Service Portal, the window object will be null. So you can add condition like below:

var ConditionValue = false
if(window === null){
    ConditionValue = (isFieldVisible("field_name"))?true:false; // Condition for UI Form
}
else{
    ConditionValue = (isVisible("field_name"))?true:false; // Condition for Portal
}

if(ConditionValue){
// Add your code here
}
Thank you,
Palani

Runjay Patel
Giga Sage

Hi @abhaysingh98 ,

 

The issue you're facing arises because the methods isFieldVisible() and isVisible() have different scopes and usage contexts.

 

 

  • isFieldVisible():

    • This method is specific to the form UI and checks whether a field is visible on the form.
    • It does not work in the Service Portal context.
  • isVisible():

    • This method is specific to the Service Portal and checks whether a widget or element is visible.
    • It does not work on the form UI.

 

You can use be script suggested by @palanikumar .

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

Anurag Tripathi
Mega Patron
Mega Patron

can you try 

g_form.isVisible('field')
-Anurag

Juhi Poddar
Kilo Patron

Hello @abhaysingh98 

The issue occurs because the methods isFieldVisible() and isVisible() are designed for different interfaces in ServiceNow:

  • isFieldVisible(): Specifically works on the form UI but does not function in the Service Portal.
  • isVisible(): Works on the Service Portal but is not supported in the form UI.

This difference arises due to the distinct underlying APIs used by the form UI and the Service Portal.

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar