- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2020 08:42 PM
Hello all,
1. I am looking for a way to verify at least 1 file is attached to the RITM form , I dont need to care about what type of files or their names, attachment validation is after submission of the catalog item.
2. If attachment if not attached RITM state should populate as pending Info
3. Mail notification should be sent to user to attach the attestation before 15 days or else request should be cancelled.
4. If user doesn't attach the attachment request should go to cancelled state.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2020 09:24 PM
Hi,
I believe you will be having workflow attached to RITM; in the run script check if current record has any attachments; if not then set the RITM state using set value; as next activity send notification to user to attach the file; wait for 15 days; after 15days timer set the ritm state as cancelled
Script to check if attachment present or not; use if activity
answer = ifScript();
function ifScript(){
if(current.hasAttachments())
return 'yes';
else
return 'no';
}
the output of no activity will be email activity
you can use timer activity and give 15 days as the time
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2020 11:08 PM
Hi,
Please try to below code :-
Catalog Client Script
Name: Require CSV Attachment
UI Type: All
Type: onSubmit
Applies on Catalog Item view: True
Script: See below:
/*======== EXAMPLE CLIENT SCRIPT: REQUIRE CSV ATTACHMENT ON SUBMIT ========*/
function onSubmit() {
if (document && gel) { //If we're in the CMS view
var cat_id = gel('sysparm_item_guid').value; //Not idea, but there's no better way at present.
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item"); //unnecessary, but improves query efficiency
gr.addQuery("table_sys_id", cat_id);
gr.addQuery('file_name', 'ENDSWITH', '.csv'); //Optional: require a specific attachment type.
gr.query(); //synchronous for non-service portal CMS.
if (!gr.hasNext()) {
g_form.addErrorMessage("You must attach a file to submit.");
return false;
}
} else if (sp_form.getAttachments) { //If we're in a service portal page, and we can find the sp_form object with the getAttachments()
// method, which should be included via a JS Include on the service portal we're rendering this in
var i; //iterator for the below for-loop
var hasCorrectAttachments = false; //initialized to false, but will be set to true if the loop identifies a valid attachment
var scAttachments = sp_form.getAttachments(); //This function MUST be exposed via a non-global UI Script included in a JS Include
//constants for required attachment type and quantity.
var REQUIREDATTACHMENTCOUNT = 1; //optional: the number of required attachments
var REQUIREDATTACHMENTTYPE = 'csv'; //optional: the required attachment file extension (no 'dot') attached to the service portal's
// theme, for this to work in service portal.
if (scAttachments.length >= REQUIREDATTACHMENTCOUNT) { //If we have at least a sufficient number of attachments
for (i = 0; i < scAttachments.length; i++) { //Iterate over each returned attachment
if (scAttachments[i].file_extension.toLowerCase() === REQUIREDATTACHMENTTYPE.toLowerCase()) { //Make sure at least one attachment has the required file-type
hasCorrectAttachments = true; //If we have a correct file-type attachment, prevent the error
break; //and break out of the loop for efficiency
}
}
}
if (!hasCorrectAttachments) { //If there are not enough attachments, or if there is no attachment of the required type
g_form.addErrorMessage('Please attach at least ' + REQUIREDATTACHMENTCOUNT + ' ' + REQUIREDATTACHMENTTYPE + ' attachment(s)');
return false;
}
} else {
console.error(
'Unable to find either gel, document, or getSCAttachments method. \n' +
'If you are viewing this in the Service Portal, be sure to add the ClientCatalogUtils UI Script JS Include to the Service Portal\'s theme.' +
'If you are in the CMS, then an error has occurred and will require troubleshooting.'
);
return false;
}
}
https://snprotips.com/blog/2017/11/5/a-better-way-to-check-for-attachments-including-service-portal
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2020 12:33 AM
Hello Rams,
I believe the above code you mentioned works at the time of submission not after submission.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 12:00 PM
here i got code for sp_form from snpro tips , but still its giving "ReferenceError: sp_form is not defined" error