Set Value and Clear Value not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 12:46 AM
Hello ServiceNow Experts.
We are having choice variable on the catalog item, whenever I select a choice value from the choice variable, it should set a value on single line text based on our selection, if this value is not matched with the selected choice then it should clear the single line variable.
To achieve this, I have written on change client script, but some times the value is not populating and some times it's not clearing the value, please provide your inputs.
I have attached my script screen shot, please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 01:39 AM
Thank you for answering my queries patiently.
The Single line text Earning code is not setting value at the first instance, but if select another choice value and come back again and selects the choice as "Bus & Govt Aviation Sales" the value is setting, can you please help me how can we avoid such scenario.
The clear value part if working as expected.
I have attached the code and item screen shots for your reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 02:09 AM
@krishnareddy again you have missed to place the brace correctly below the 8th line can you please paste the exact code that i gave here and try.
function onChange(control, oldValue, newValue, isLoading){ if (isLoading || newValue == "") { return; } var Bonus= g_form. getValue ("bonus_category") ; alert(bonus); if(Bonus =="Bus & Govt Aviation Sales") { g_form.setValue("earning_code",39); } if(Bonus !="Bus & Govt Aviation Sales") { g_form. clearValue ('earning_code") ; } }