Onchange Client Script

Sujith Kumar2
Tera Expert

Requirement : When CI is choosen, associated location has to update in location field in Incident form.

My solution : Onchange Client Script as follows:

var prevLocation = g_form.getValue('location');
if (!newValue) {
g_form.clearValue('location', '');
g_form.setValue('location', prevLocation);
} else {
var loc1 = g_form.getReference('cmdb_ci', setLocation);
function setLocation(loc1) {
g_form.setValue('location', loc1.location);
}
}

 

Issue: when ci value is choosen, location field is autopopulating. As CI is not a mandatory field, when ci removed - location field is new set value. But requirement is when we clear CI field , location should be as previous Value.

Please suggest.
Thanks in advance.


SujithKumar2_0-1709805808833.png

 

1 ACCEPTED SOLUTION

Sujith Kumar2
Tera Expert

Tried with separate ui policy when ci is empty

and to set value written a client script.
Thanks vamshi krishna

View solution in original post

3 REPLIES 3

Sujith Kumar2
Tera Expert

Also Tried

g_form.clearValue('location');

But it hasnt worked. May be location is also a refeence field. 

vamsi krishna8
Tera Contributor

So correct my understanding 
when ci value is chosen, location field is auto populating.
As CI is not a mandatory field, when ci value is removed - location field is set to new value.
Your  requirement is when we clear CI field & not not chosen new ci value, location should not be new value& should be same as previous Value which was there before clearing CI value , correct
?

Sujith Kumar2
Tera Expert

Tried with separate ui policy when ci is empty

and to set value written a client script.
Thanks vamshi krishna