Clear Variables on Form when "Add to Cart" is clicked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:37 AM - edited 10-31-2023 11:22 PM
Hi All,
We have a requirement to clear some variables on the form when all the variables were filled and clicked on "Add to Cart". So that those values should be filled again before adding the form to cart again. Is there any way to achieve this using any scripts?
Thanks,
Surya. P

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 09:27 AM
Hi,
This would need more of DOM manipulation. You can check for links that has solution
1. To clear all
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 09:34 AM
Hi @Jaspal Singh,
Thanks for the reply. I had already tried both the solutions and it is throwing a "Java Error Console" error on the portal. And when I tried to Inspect it, it is showing that getElementById is not readable. And also I read that document.getElementById is not recommended by ServiceNow since it is an DOM Manipulation. Is there any other way to achieve this solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 11:23 PM
Is this possible to clear values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 11:31 PM
Hi @Surya_Prakash
Did you tried g_form.clearValue(fieldNameHere) in UI Action's script?
Ex : g_form.clearValue('amount');
Please mark this helpful and accept the solution, if it worked for you.
Thanks
Fazal