- 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 09:15 PM
The alert is coming as null. Can you check the variable name is correct?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 09:30 PM
@Harish KM You have made my day! Thank you brother! Fixed!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 09:31 PM
Glad to know it is fixed 🙂
Harish