onSubmit catalog client script using gr.addEncodedQuery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 03:06 PM
Hello, I am a new to ServiceNow and I need some assistance with creating an onSubmit catalog client script. The requirement is that the catalog item should prevent users from requesting the same item more than ten times within ten business days. However, I have encountered some errors where "gr.addEncodedQuery" is not allowed in my script. I would appreciate any help in resolving these issues. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 03:55 PM
Hey @MayrelCerero,
You are using client-side GlideRecord API and it should be 'setEncodedQuery' instead. The 'addEncodedQuery' is server-side GlideRecord API (yup, I know it's weird). Refer to the documentation for more details - https://docs.servicenow.com/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_referenc...
Give this a go, cheers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 05:28 PM
Hi @MayrelCerero as per best practice, it is not recommended to use gliderecord query in client script, you can move your validations to client callable script include and return yes/no to onSubmit client script to abort the submission. This improves performance.
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 06:52 PM
You must not use GlideRecord query in client script, although its supported but not recommended due to performance implications.
Instead you can use GlideAjax method in fetching data from server side. Now the challenge comes for onsubmit that sync ajax calls are not supported in catalog client scripts, so you need to do some adjustments, refer to code below:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 09:35 PM
It's not recommended to run GlideRecord query on client side scripts. You should move your server-side logic to a Client Callable Script Include and call your Script Include from your On-Submit Client Script. Refer below post for reference :
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.