Clearing an HTML variable

Ariomar de Deus
Tera Contributor

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?

4 REPLIES 4

KingC
Giga Contributor

TROUBLESHOOTING QUESTIONS FOR CLARIFICATION

  1. What is the exact name/sys_id of the HTML variable?
  2. What is the dependent field type (Reference, Choice, etc.)?
  3. Can you share the current client script code?
  4. What specific error message appears during processing?
  5. Does the issue occur on first change or only subsequent changes?
  6. What ServiceNow version/release is the instance running?
  7. Are there any other client scripts or UI policies on this catalog item?
  8. 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.

Bert_c1
Kilo Patron

Post your client script, and maybe folks here can assist. (Post any script as text, pictures of code are pretty much useless.)

Dinesh Chilaka
Tera Guru

@Ariomar de Deus ,

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.

Ankur Bawiskar
Tera Patron

@Ariomar de Deus 

why are you using HTML variable just to store sysId?

what's your actual business requirement?

share screenshots and details

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader