Display Problem_id field state on incident form.

Sagar_pawar
Tera Contributor

Hello ALL,

on incident form there is problem_id field there.i want to populate state of problem_id on incident form.for populate value I wrote one script in UI Action.

 

function checkStateOfProblem() {

var data = g_form.getReference('problem_id', doAlert);


function doAlert(data) {
if (data.getValue('state') == 102 || 1 || 2 || -5) {
alert('you cannot cancel incident ticket because state is ' + data.getValue('state'));
alert((data.state).getDisplayValue());
alert(g_form.getDisplayValue('state'));
} else {
alert('you can cancel' + data.getValue('state'));

}
}

}

5 REPLIES 5

RaghavSh
Kilo Patron

@Sagar_pawar what is the question here? If you want the display value of state use:

 

alert(data.state.getDisplayValue());


Raghav
MVP 2023

Sagar Pagar
Tera Patron

Hi @Sagar_pawar,

As Raghav mentioend, you have to use the displayValue instead of getValue.

 

alert("add message here " + data.getDisplayValue("state"));

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Hello, @Sagar Pagar and @RaghavSh I tried both scripts as you mentioned but it's not working for me.

@Sagar_pawar if both are not working then go via server script instead of client side code in ui action:

current.problem_id.state.getDisplayValue();

Or

current.problem_id.getDisplayValue('state');

This code should be outside function, means the UI action should not be client true.


Raghav
MVP 2023