attachment validation using UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
Hello Experts,
I have an existing UI Action which sets some alerts and mandatory field validations on click on the button. In addition to the existing behaviour, I need the UI action to validate if attachments are attached to the record while submit.
I have created a script include to check it attachments are associated to the record and have update the UI Action as below.
On Submit, if the attachment is not available, the alert shows and the record does not get submitted.
However, it is not doing the all the other validations as mentioned in the UI Action scripts and also doesnot submit the record if attachment is found.
Can you please guide me with the correct script to achieve the attachment validations, and also keeping the other existing script validations unimpacted
Script Include -
UI Action -
Action Name - u_submit
Client - checked
onClick - validateOpenToSubmit()
Script -
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
your GlideAjax is Asynchronous so it doesn't wait for result
use getXMLWait() for synchronous call
function validateOpenToSubmit() {
var checklistID = g_form.getUniqueValue();
var testingAttach = g_form.getValue('u_testing_evidence_available');
var ccl_co = g_form.getValue('u_owner_comments');
var st = g_form.getValue('state');
// Attachment check only if u_testing_evidence_available is 0
if (testingAttach == '0') {
var attachmentID = new GlideAjax("SysAttachmentUtil");
attachmentID.addParam("sysparm_name", "attachmentValidation");
attachmentID.addParam("sysparm_id", checklistID);
var answer = attachmentID.getXMLWait(); // Synchronous: waits for response
if (answer == 'no associated attachment') {
alert("Please attach the testing plan before submitting the task");
return false;
}
}
// Other validations
if (st == 32 && ccl_co == '') {
alert("Please provide justification in Owner comments field before submitting the task");
g_form.setMandatory('u_owner_comments', true);
return false;
}
// Submit if all pass
g_form.setValue('state', 34);
gsftSubmit(null, g_form.getFormElement(), 'u_submit');
g_form.setValue('state', 0);
}
if (typeof window == 'undefined') {
runServerOpenToSubmit();
}
function runServerOpenToSubmit() {
new global.StateFlow().processFlow(current, 'sys_id', 'manual');
action.setRedirectURL('/change_request.do?sys_id=' + current.parent.sys_id);
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
24m ago
Hi @Ankur Bawiskar ,
I updated the UI action script to use the get XMLWait, as provided by you. It doesnot show the alert message and also proceeds with submitting the record.
Please advice on the way forward to correct the script.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
Hi @Somujit1
