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 change field alignment of Integer type from right to left side on workspace

Raviteja Kunal1
Tera Expert

Hi

I want to change alignment of integer type field from right side to left side on workspace. I tried field styles and onload client script but did not work. How can I achieve this?

 

function onLoad() {
//Type appropriate comment here, and begin script below
var myField = 'estimated_usd'; // add correct name here
var ctrl = $('sys_display.' + g_form.getControl(myField).id);
var displayControl = g_form.getControl('estimated_spend_usd');
displayControl.style.background = 'red';
ctrl.style.textAlign = 'left';

4 REPLIES 4

Nihal Sarawgi1
Tera Contributor

@Raviteja Kunal1 Hey did you got any solution for the above question ? 

If YES please post the solution here ...

 

I am able to achieve it in a form view by updating the variable style to text-align:left, but it is not working in workspace. 

No we are not able to, even ServiceNow team confirmed this for Workspace.

Amit_Kirpane
Tera Contributor

Hi @Raviteja Kunal1 ,

 

Try the below onLoad client script, it's working for me!

 

function onLoad() {
    var myField = 'u_od'; //field value
    var ctrl = g_form.getDisplayBox(myField);

    if (!ctrl) {
        ctrl = g_form.getControl(myField);
    }
    console.log('Control:', ctrl);
   
    if (ctrl) {
        ctrl.style.textAlign = 'left';
    } else {
        console.error('Control not found for field:', myField);
    }
}

Hii,
this works great for native view but isnt reflected in workspace. is there any workaround available ?