getElement() not working

Tapish Sharma1
Kilo Sage

Hi Everyone,

I am trying the below client script but it is not working. The field type is currency-

function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('u_hard_savings')<0){
var element = g_form.getElement('u_hard_savings');
element.style.backgroundColor='red';
}

}

 

Any hints would be helpful, thanks 

1 ACCEPTED SOLUTION

@Tapish Sharma Seems like getControl(), getElement(). getDisplayBox() won't work with Currency field.

Tried with Field Style but condition in Value field only works on a list and not on the form. It's either always red or none.

Is this for ServicePortal or for UI?

View solution in original post

9 REPLIES 9

@Hitoshi Ozawa 

Hi hitoshi, 

It doesnt work even if i remove the if condition. As mentioned above my field type is "currency". can you try for that once 

@Tapish Sharma Seems like getControl(), getElement(). getDisplayBox() won't work with Currency field.

Tried with Field Style but condition in Value field only works on a list and not on the form. It's either always red or none.

Is this for ServicePortal or for UI?

Hi Hitoshi, 

thank you so much , it is for ui form . So I guess it is not possible then

@Tapish Sharma Should contact Now Support. This seems like a bug because .getControl() should work on all but the reference field which requires .getDisplayBox() instead.

 

Strongly don't suggest this but it is possible using DOM manipulation. This may not work after versioning up. I've tested the following in San Diego. Replace "<form name>".

        if (parseInt(g_form.getValue('u_hard_savings').split(';')[1]) < 0) {
            var element = gel('<form name>.u_hard_savings.display');
            element.style.backgroundColor = 'red';
        }

Execution results:

find_real_file.png

find_real_file.png

BTW, I've also found that getValue() on currency will prefix with the currency mark so it won't be a number.

e.g.

USD;10.0

So the if condition will be as follows:

if (parseInt(g_form.getValue('u_hard_savings').split(';')[1]) < 0) {