does onload() runs when the form is submitted/updated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2024 10:59 AM
Hi
I have doubt that onload client script executes only when the form is loaded for the first time or it also executes when the form is submitted/updated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 09:45 AM
Hi @shefali29
An `onLoad` client script is designed to execute when a form is initially loaded. This means that the script runs every time the form is opened for the first time, including when a user:
- Creates a new record (and thus a new form is loaded).
- Opens an existing record (and the form is loaded with that record's data).
The `onLoad` client script does not execute when the form is submitted or updated. When a form is submitted or updated, the data is processed on the server side, and unless the form is reloaded (such as when the form is saved and stays on the same page, or when the update redirects to the same form), the `onLoad` script will not run again.
If you need to run client-side code after a form is submitted or updated, you would typically use an `onChange` client script (which runs when a field value changes) or an `onSubmit` client script (which runs when the form is being submitted, but before the data is actually sent to the server). There are also `onCellEdit` client scripts that can be used for List views when inline editing is performed.
Remember that client scripts are intended for client-side operations, and any server-side logic that needs to occur after a form submission or update should be handled by Business Rules, Workflow, or other server-side scripting options in ServiceNow.
You can also refer servicenow documention below for client script types
https://developer.servicenow.com/dev.do#!/learn/learning-plans/vancouver/new_to_servicenow/app_store...
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 09:54 AM - edited 01-14-2024 09:54 AM
Hi @shefali29 ,
OnLoad client script will run when the form is opened first time, updated or submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 04:37 PM
Hi shefali,
I will try to explain in very simple way but you need to do little hard work. Go to client script on incident table and create one simple onload client script
Now when you open the new or any existing incident record ,onload client script will run and you can see the alert on the form. Now if there is opened incident form and you makes any changes on it and save it, onload client script will run again and you can see the alert. Now play around with the form it will be very clear.
If this has helped you please marked it as correct, as it will help the other users too. thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 08:12 PM
Hi @shefali29 ,
The `onLoad` client script in ServiceNow is designed to execute when a form is initially loaded. It does not trigger when the form is submitted or updated. If you need a script to run when a form is submitted or updated, you would typically use the `onSubmit` or `onChange` client scripts, respectively.
So, if you have specific requirements for scripts to execute during form submission or update, consider using the appropriate client script events (`onSubmit` for submission, `onChange` for updates) rather than relying solely on `onLoad`.
Thanks,
Danish