- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2017 07:51 AM
Hello SNC -I am designing a catalog item where when a specific dropdown choice is chosen - lets call it choice_1, then I want to make it mandatory to attach a PDF, and only a PDF. I am new to catalog items in general, and tying this to a UI policy/action as well.
Here is a catalog client script Im working with - but it is far from what I need in this use case. Any help would be appreciated:
function onSubmit() {
if (g_form.getValue('check_attachment') == 'Yes') {
var ord_id = gel('sysparm_cart_edit').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", ord_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
else if (g_form.getValue('check_attachment') == 'No') {
var cat_id = gel('sysparm_item_guid').value;
var gf = new GlideRecord("sys_attachment");
gf.addQuery("table_name", "sc_cart_item");
gf.addQuery("table_sys_id", cat_id);
gf.query();
if (!gf.next()) {
alert("You must attach the required form to submit.");
return false;
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2017 09:50 AM
Content type for pdf will be 'application/pdf'
You can use GlideAjax sync because onSubmit should wait for decision. It will have better performance on checking table with GlideRecord.
On GlideAjax you can check if attachment exist and if so, does any of existing attachments have content type as 'application/pdf', then you can return true/false to Ajax call.
OnSubmit is essential as trigger to check attachments. You can also do it on ui action but onSubmit is better considering its catalog item so only right items will be affected.
Summarizing:
OnSubmit with GlideAjax
GlideAjax with GlideRecord and logic to determine right file
GlideAjax returning true/false
OnSubmit checking return from GlideAjax and deciding to return false or continue
For application/pdf content, its better to double check by attaching any file on your instance and check what is in column Content Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2017 06:52 AM
If anyone else has feedback or has links to relevant examples that would be appreciated as well.
Thank you in advance,
Jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2023 10:30 PM
Try This one
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name',current.getTableName());
attach.addQuery('table_sys_id',current.sys_id);
attach.query();
if(attach.getRowCount() < 2)
{
//gs.addInfoMessage('Submitted');
current.setAbortAction(true);
}
else
{
//gs.addErrorMessage("add at least 2 attachment, Order Empty');
current.setAbortAction(false);
}