Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to minimize the gap between two fields

JaganN971616731
Tera Contributor

Hello community,

 

I have a requirement that when the CAB required is checked the CAB date and CAB recommendation field should be visible. I have achieved the functionality using UI policy. However when the form load initially there is a gap(marked with red square) between two fields(CAB required and Outage required). Can you please suggest the code how to minimize the gap between two fields.

When unchecked:

JaganN971616731_0-1713509642752.png

When checked:

JaganN971616731_1-1713509676170.png

Code in UI policy:

function onCondition() {
    g_form.setVisible('cab_date_time', false);
    g_form.setVisible('cab_recommendation', false);
}

 

Thanks & Regards,

Jagan

 

3 REPLIES 3

Community Alums
Not applicable

Hi @JaganN971616731 ,

I tried your problem in my PDI and I created onChange client script on active field (checkbox field as you showed in example). Please refer code 

alert("Active = " + newValue);
    if (newValue == false || newValue == 'false') {
        g_form.setVisible('u_test', false);
        g_form.setVisible('activity_due', false);
    }else{
		g_form.setVisible('u_test', true);
        g_form.setVisible('activity_due', true);
	}

 

SarthakKashya2_0-1713510476934.png

 

Here's the Result 

SarthakKashya2_1-1713510495887.png

When I did active false

SarthakKashya2_2-1713510518131.png

Test and activity due field is removed 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

JaganN971616731
Tera Contributor

Hi @Community Alums 

 

When you make Active as false there is a gap between incident state and project time. How to minimize that gap?

 

Thanks and Regards 

Jagan

Community Alums
Not applicable

Hi @JaganN971616731 ,

Instead of setVisible you can use setDisplay method 

 

alert("Active = " + newValue);
    if (newValue == false || newValue == 'false') {
        g_form.setDisplay('u_test', false);
        g_form.setDisplay('activity_due', false);
		
    }else{
		g_form.setDisplay('u_test', true);
        g_form.setDisplay('activity_due', true);
	}

 

 

SarthakKashya2_0-1713511923231.png

 

You can see now the gap is gone

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak