Make comments field mandatory when attachment is attached to Incident record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:13 AM
Hi Everyone,
I have requirement on Incident form
If any new attachment is attached to incident form need to make additional comments field mandatory in platform level.
Can any one help me on this requirement. Thanks in advance..
Thanks,
Prasad G.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:42 AM
Hi @GaddamP ,
I think an onSubmit client script could be helpful, you have to check in the Attachment [sys_attachment] table if no record is related to the incident, then make the field mandatory and display an alert or message, this is an example:
function onSubmit() {
var id = g_form.getUniqueValue();
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", g_form.getTableName());
gr.addQuery("table_sys_id", id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
g_form.setMandatory('comments', true);
return false;
}
}
NOTE: Using Glide Record in client script is a bad practice, so I recommend including the AJAX method and a script included.
I hope it's helpful to you.
Regards,
- Cesar Salas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:44 AM
To make the "Additional Comments" field mandatory when a new attachment is added to the Incident form, follow these simple steps:
Create a Client Script on the Incident form.
Set the script type to onChange and choose the attachments field.
In the script, check if a new attachment is added, and if yes, make the "Additional Comments" field mandatory.