- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 06:47 PM
Hi all,
Created a Record Producer within an Application Scope from App Engine Studio. We are struggling to make attachment mandatory.
Requirement: If "id_required_for_every_employer" is "Yes", then set Attachment Mandatory/prevent request submission | Field type: Option - Yes/No
Release version: Utah
Script Include:
Name:CheckAttachPRecodProducer | Client callable: true | Application: Fow Application | Accessible: This App scrope
var CheckAttachPRecodProducer = Class.create();
CheckAttachPRecodProducer.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
CheckAttachments: function() {
var pForm = this.getParameter('sysparm_p_form');
var pForm = new GlideRecord("sys_attachment");
pForm.addQuery('table_name', "x_appl_di_tile_form");
pForm.addQuery('table_sys_id', dataCheck);
pForm.query();
if (gr.next()) {
return 'yes';
} else {
return 'no';
}
},
type: 'CheckAttachPRecodProducer'
});
Catalog Client Scripts:
Applies: Catalog Item | UI Type: All | Type: onChanage | CatalogItem: Fow Request | VariableName: id_required_for_every_employer
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == "Yes")
var pAttach = new GlideAjax('CheckAttachPRecodProducer');
pAttach.addParam('sysparm_name', 'CheckAttachments');
pAttach.addParam('sysparm_p_attach', g_form.getValue("p_attach"));
pAttach.getXML(clientCallback);
}
function clientCallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'yes') {
return true;
} else if (answer == 'no') {
alert("You must attach document before submitting the form.");
return false;
}
}
need your help a bit desperately. Please, and thank you!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 07:07 PM - edited 09-28-2023 07:13 PM
Follow the procedure below, it will be reusable for all catalogs to make a attachment mandatory
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743672
Once you set up UI script and added to Portal. you could follow below client script
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 07:07 PM - edited 09-28-2023 07:13 PM
Follow the procedure below, it will be reusable for all catalogs to make a attachment mandatory
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743672
Once you set up UI script and added to Portal. you could follow below client script
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 08:50 PM - edited 09-28-2023 08:53 PM
@Harish KM tried following the doc but still not getting the expected result. Not sure what went wrong ....
UI Scrip
ScripName: GlobalCatalogItemFunctions
var x_aigg2_pax_appl_0 = x_aigg2_pax_appl_0 || {};
x_aigg2_pax_appl_0.GlobalCatalogItemFunctions = (function() {
"use strict";
return {
setAttachmentMandatory: function(isMandatory) {
var isSuccess;
try {
angular.element("#sc_cat_item").scope().c.data.sc_cat_item.mandatory_attachment = isMandatory;
isSuccess = true;
} catch (e) {
isSuccess = false;
}
return isSuccess;
},
type: "AttachmentUtil"
};
})();
Catalog Client Script: Did not change anything, just wanted to see if it's going to work.
function onSubmit() {
if (g_form.getValue('id_required_for_every_employer') == "No") {
var alertWord = "Please use the paperclip icon below to attach documents before submitting the request.";
try {
var attachments = g_form.getControl('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
alert(alertWord);
return false;
}
} catch (e) { //For Service Portal
var count = getSCAttachmentCount();
if (count <= 0) {
alert(alertWord);
return false;
}
}
}
}
JS Include on S Portal Theme:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 08:54 PM - edited 09-28-2023 08:55 PM
The theme you added. Is that the same using on the Portal?If yes add the alert and check the value below
var getID = g_form.getValue('id_required_for_every_employer');
alert(getID);
var alertWord = "Please use the paperclip icon below to attach documents before submitting the request.";
if (getID == 'No') {
try {
var attachments = g_form.getControl('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
alert(alertWord);
return false;
}
} catch (e) { //For Service Portal
var count = getSCAttachmentCount();
if (count <= 0) {
alert(alertWord);
return false;
}
}
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 09:14 PM
This is pop-up came up