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

Shakeel Shaik
Giga Sage
Giga Sage

Hi @d-aizawa 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var vString = g_form.getDisplayValue('test').toString();
    if (vString.indexOf('ZZ') != 0) {
        g_form.setValue('main', 'other');
    } else if (vString.indexOf('91') != 0) {
        g_form.setValue('main', 'internal');
	}
}

 

Please check and Let us know.

 

Thanks 🙂

Thanks,
Shakeel Shaik 🙂

Thank you answering my question ! But, getDisplayVaue gets the record ID (number) of Incident. Is there any other good way?

Hitoshi Ozawa
Giga Sage
Giga Sage

Need to do the following to get display of choice field named "test".

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

Thank you answering my question ! The following error is output. onChange script error: TypeError: Cannot read properties of null (reading 'text') function () { [native code] }