- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 08:16 AM
I'm looking to create a BR to exclude file attachments with certain characters that get to sc_cart_item. It works but can I make this more specific so it only applies to specific catalog items?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2020 01:38 AM
Hi KB,
I have an idea for your problem statement. Please follow below steps and I think, this will work for selective catalog item.
- Create a script include with below details
Name: catalogAttachmentUtils
Client callable: True/checked
Script:
var catalogAttachmentUtils = Class.create();
catalogAttachmentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
restrictAttachment: function() {
var cartID = this.getParameter("sysparm_restrictid");
gs.log(cartID, "cartID");
if (cartID)
gs.getSession().putClientData('catalog.attachment.restriction.id', cartID);
},
checkRestriction: function(id){
return (gs.getSession().getClientData('catalog.attachment.restriction.id').toString() == id.toString())?true:false;
},
type: 'catalogAttachmentUtils'
});
Client script
Name: Restrict Attachment
Type: Onload
Isolate script : false/ unchecked(this is very important, if not available on form, please add this field on form )
Script:
function onLoad() {
var cart_id = gel('sysparm_attachment_cart_id').value;
var ga = new GlideAjax('catalogAttachmentUtils');
ga.addParam('sysparm_name', 'restrictAttachment');
ga.addParam('sysparm_restrictid', cart_id);
ga.getXML(callbackFunction);
function callbackFunction(response) {
// just a placeholder
}
}
Finally, the business rule(on sys_attachment table with condition, table name = sc_cart_item) condition
new catalogAttachmentUtils().checkRestriction(current.table_sys_id)
Above steps will make sure, the business rule will only apply if, the catalog item has above onload script enabled.
Hopefully, this will work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 11:46 AM
Hey KB,
- create a system property named "control.catalog.list" and put all applicable items there
- create a script include named "attachmentRestrictionUtils"
- add Below method in the script include
validCatalog: function(table, id){
var targetCatalog = gs.getProperty("control.catalog.list");
var checkItem = new GlideRecord(table);
checkItem.addQuery("cat_item", "IN", targetCatalog);
checkItem.addQuery("sys_id", id);
checkItem.query();
return (checkItem.hasNext())?true:false;
}
- In Business rule condition add this line new attachmentRestrictionUtils().validCatalog(current.table_name.toString(), urrent.table_sys_id.toString());
Above will restrict your BR to items which are mentioned in system property control.catalog.list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 12:39 PM
How should I add the items in the property? By sys_id?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 12:44 PM
Yes,
It should have sys_ids
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 12:47 PM
The script include doesn't seem to work. Are there substitutions and where should the code be added from the pre-filled script section?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 12:54 PM
Hi,
Script Include
Name: attachmentRestrictionUtils
Code:
var attachmentRestrictionUtils = Class.create();
attachmentRestrictionUtils.prototype = {
initialize: function() {},
validCatalog: function(table, id) {
var targetCatalog = gs.getProperty("control.catalog.list");
var checkItem = new GlideRecord(table);
checkItem.addQuery("cat_item", "IN", targetCatalog);
checkItem.addQuery("sys_id", id);
checkItem.query();
return (checkItem.hasNext()) ? true : false;
},
type: 'attachmentRestrictionUtils'
};
Screenshot
Business Rule Condition