How to get a value of a choice field and populate the same choice label again in the same field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 03:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 04:18 AM
You mentioned same field then why you used 'subcategory'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 05:22 AM
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:
- Right-click the field label in the form and select Configure Dictionary.
- Click Advanced view in the lower left of the screen.
- In the Dependent field, enter the name of the field that this field will depend on.
- 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**