Clearing an HTML variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have an HTML variable that stores the sys_id of a record, and I have a client script that performs the clearing when there is a change in the field that modifies the HTML variable. The problem is that every time there is a change in the field that modifies the HTML variable, the previous sys_id record remains in the HTML variable, and this is causing an error. Has anyone else experienced this and how did they solve it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
TROUBLESHOOTING QUESTIONS FOR CLARIFICATION
- What is the exact name/sys_id of the HTML variable?
- What is the dependent field type (Reference, Choice, etc.)?
- Can you share the current client script code?
- What specific error message appears during processing?
- Does the issue occur on first change or only subsequent changes?
- What ServiceNow version/release is the instance running?
- Are there any other client scripts or UI policies on this catalog item?
- Is this a standard catalog item or part of a scoped application?
SUGGESTED SOLUTION APPROACHES TO TEST
**Approach 1: Standard setValue with Empty String**
g_form.setValue('html_variable_name', '');
**Approach 2: Clear with Null**
g_form.setValue('html_variable_name', null);
**Approach 3: Direct DOM Clearing**
var element = g_form.getControl('html_variable_name'); if (element) { element.value = ''; element.innerHTML = ''; }
**Approach 4: Combined Approach**
g_form.setValue('html_variable_name', ''); g_form.setDisplay('html_variable_name', false); g_form.setDisplay('html_variable_name', true);
Please provide the current client script code and answers to the troubleshooting questions for more specific solution recommendations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Post your client script, and maybe folks here can assist. (Post any script as text, pictures of code are pretty much useless.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I think you are clearing the HTML value at the form level whenever other field changes, try modifying the variable at the database level by using the GlideAjax Script Include whenever the field changes.
If my response helps, mark it as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
why are you using HTML variable just to store sysId?
what's your actual business requirement?
share screenshots and details
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
