How to get a value of a choice field and populate the same choice label again in the same field

VIKAS MISHRA
Tera Contributor

I have tried below mentioned 2 line of code but its nit working. 

 

var cat = g_form.getValue('category');

g_form.setValue('subcategory', subCat);

 

Basically with the first line of code its getting the backend name of the choice value and with the backend name its unable to populate the label of the choice value in the same field.

 

Using on above code in onchnage client script

2 REPLIES 2

VISWANATH KAMAL
Tera Contributor

You mentioned same field then why you used 'subcategory'

reshmapatil
Tera Guru

Hi @VIKAS MISHRA ,

 

var cat = g_form.getValue('category'); // returns choice value

var cat = g_form.getDisplayValue('category'); // returns choice display name

 

In your code, on 1st line, you are getting category value and on the 2nd line you are setting to the subcategory that also with undefined variable 'subCat'.

 

If I am guessing correctly you are using OnChange Client Script. you can have newValue and oldValue of field on change of which script is executing.

You can write:

g_form.setValue('subcategory', newValue);

 

 

If you want to have dependent SubCategory choices when we select Category then follow below steps:

  1. Right-click the field label in the form and select Configure Dictionary.
  2. Click Advanced view in the lower left of the screen.
  3. In the Dependent field, enter the name of the field that this field will depend on.
  4. Click Update when done.
    In the example below, the "subcategory" field is made dependent on "category". The "category" value in a form will determine which options appear for the "subcategory" field.
     

    Regards,

    Reshma

    **Please mark my answer correct or helpful based on the impact**