Make Attachment mandatory in WS form
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi ,
Make the attachment mandatory in the UI action button , when the button click , check attachment if there is no attachment then make attachment mandatory to submit that form.
7 REPLIES 7
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
screenshot please of what you created
Regards,
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
HI @armanoj ,
Do you want this validation to apply to all UI Actions that save or update the form,
or only for a specific UI Action?
Also, could you please share what you have implemented so far?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
specific UI Action
declarative action :
function onClick() {
g_form.setMandatory('comments', true);
if (!g_form.getValue('comments')) {
g_form.addErrorMessage('Comments are mandatory');
return;
}
var attachments = g_form.getAttachments();
if (!attachments || attachments.length === 0) {
g_form.addErrorMessage('Attachment is mandatory before approval.');
return;
}
var status = g_form.getValue('u_sub_state');
// g_form.setValue('state', '3');
if (status == 'awaiting_yy_approval') {
g_form.setValue('u_sub_state', 'awaiting_xx_approval');
} else if (status == 'awaiting_zz_approval') {
g_form.setValue('u_sub_state', 'approved');
} else if (status == 'awaiting_mm_approval') {
g_form.setValue('u_sub_state', 'awaiting_dd_approval');
}
// Save and refresh workspace
g_form.save().then(function() {
g_form.reload(); // Refresh workspace
});
}
