Attachment to Form issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 02:49 AM - edited 01-06-2023 03:54 AM
Hi All/ @Ankur Bawiskar ,
I have created one custom form which will have some fields eg : 'Category' and 'Sub-Category' and 'custom attachment field' as per the requirement not used the attach icon. and Created one On-Change Client script(When category becomes 'software' need make the sub category field read-only and auto fill with some value) ------> Until here it is working as expected.
After selecting the category , While trying to add an attachment using custom attachment field it was redirected to another page to choose the file and routed back to the existing form after added the file.
But in the form the sub-category value is getting cleared. We don't have anything to clear this sub category field.
Kindly help me why this read only field is getting cleared???
Thanks in advance,,,,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 02:03 AM
is this happening for new record or existing record?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 04:03 AM
@Ankur Bawiskar For both new and existing records , it is behaving same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 02:40 AM
Hi Ankur,
Is there any way we can avoid the auto-save when we click the OOB file attachment button? Solutions like open in a new tab or abort the update.
Thank you
Harihara Sudhan M S

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 04:49 AM
It is likely that the value of the sub-category field is being cleared because the onChange client script is being triggered again when you navigate back to the form after adding the attachment. This could be happening because the form is being refreshed or because the field is being modified in some way that causes the onChange script to run again.
One way to fix this issue would be to add a check in the onChange script to ensure that the sub-category field is only made read-only and auto-filled with a value if the category field is set to 'software'. You could do this by adding an if statement at the beginning of the script that checks the value of the category field.
For example:
if (g_form.getValue('category') == 'software') { // make sub-category field read-only and auto-fill with a value }
This way, the onChange script will only run if the category field is set to 'software', and the sub-category field will not be modified if the category field is set to a different value.
Alternatively, you could try using a different type of client script, such as an onLoad script, that runs when the form is first loaded and sets the sub-category field to read-only and auto-fills it with a value if the category field is set to 'software'. This would ensure that the field is not modified when the form is refreshed or when other fields are modified.
Kindly mark the response as Correct or Helpful.
Cheers,
Anish