How to get the display value of the String field (Client Script)

d-aizawa
Kilo Sage

Hi.

I Created Client Script.

When the first 2 digits of the display value of the test field is ZZ, the process of setting the value of the main field to other is described.

But, it doesn't work.

Because getDisplayValue ('field_name'). Value can only use Reference Type fields.

Is there a g_form to get the displayed value of String Type(Setting Choice)?

Thank you!

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var string = g_form.getDisplayBox('test').value;
    if (string.indexOf('ZZ') !== 0) {
        g_form.setValue('main', 'other');
    } else if (string.indexOf('91') !== 0) {
        g_form.setValue('main', 'internal');
	}
}
1 ACCEPTED SOLUTION

I've created a field name "u_test" with label "New Choice" on an incident form.

find_real_file.png

find_real_file.png

Created a onChange script on Field "New Choice"

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var value = g_form.getValue('u_test');
    var text = g_form.getOption('u_test', value).text;
    alert("getOption:" + text);
}

Execution result when Choice 1 is selected.

find_real_file.png

View solution in original post

9 REPLIES 9

What is the type of field "test"? Is is a choice field, a string, or a reference?

Hi. 「test」field is String Type. But, I am adding choices in the drop-down list.

What is the name of the drop-down list?

Hi. It's "Dropdown with --None--".

I've created a field name "u_test" with label "New Choice" on an incident form.

find_real_file.png

find_real_file.png

Created a onChange script on Field "New Choice"

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var value = g_form.getValue('u_test');
    var text = g_form.getOption('u_test', value).text;
    alert("getOption:" + text);
}

Execution result when Choice 1 is selected.

find_real_file.png