hide a section on change request form

sharley
Tera Contributor
I am trying to hide a section i created on change_request form when the change type is not chosen as "A" and make it visible only when change type is chosen as "A".
 
Client script:
function onLoad(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
var type = g_form.getValue(type);
if (type = 'A'){
    g_form.setSectionDisplay("A", true);
}
else {
    g_form.setSectionDisplay("A", false);
}
      return;
   }
   //Type appropriate comment here, and begin script below
   
}
2 REPLIES 2

Chaitanya ILCR
Mega Patron
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
        g_form.setSectionDisplay("A", newValue == 'A');
g_form.setSectionDisplay("a", newValue == 'A')
    
}

Hi @sharley ,

Try this 

Is the name of the section is correct ? Or backend name of the value "A" correct?

To know the section name 

Follow this

 

The backend name for a ServiceNow form section is its label converted to lowercase, with the first space becoming an underscore and subsequent spaces/special characters removed (e.g., "Caller Details" becomes caller_details). You find these by using the g_form.getSectionNames() API in a client script for dynamic retrieval or by configuring the Form Layout to see the names. 

 

 

RaghavSh
Mega Patron

@sharley You don't need return in this case. Your script is correct, you probably need to check the backend value of type "A" and UI section name should be correct.

 

Refer: https://www.servicenow.com/community/developer-forum/get-form-section-name/m-p/1971485  explanation for section names


Raghav
MVP 2023
LinkedIn