- 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 12:55 PM
Update :
There was a typo in condition script, correct is below
new attachmentRestrictionUtils().validCatalog(current.table_name.toString(), current.table_sys_id.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 11:53 AM
Thanks for the help but I don't think this works as I expected.
The table referenced in the BR condition is sc_cart_item. Unfortunately, there's nothing created in this table until after the item is added to the cart. The query would always return false since nothing is returned.
I'd like to prevent the attachment from being added while the user attaches the file to the form for a specific catalog item. While I can do this globally, this needs to be for a specific item.

- 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-23-2020 01:18 PM
Just so I understand how this new script runs:
- The AJAX client script runs and loads my cart_id from my session
- The business rule condition (when applicable) sends the table ID to the script include (eg sys_attachment table sys_id)
- The script include will then compare my session id with the table id from (which is the session id as well?)
- If the table id and session id match, run the BR
Does this work because it's simply doing a "duplicate check" based on the attachment and session ids and nothing else? And that this condition only runs on this single BR?
To put it simply, "If I see the item echoing the same sys_id, run the BR, otherwise, don't run it"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2020 01:32 PM
Hi KB,
You are close. Script does below.
- Onload client takes the form's cart id and send to script include
- Script method "restrictAttachment" set the id in session with key "catalog.attachment.restriction.id"
- Business rule condition execute the script include method "checkRestriction" to check if current attachement's table_sys_id (which is cart id, it is unique on every pageload) matches to current cart id, if not then you are on different catalog than intended.
Above will give you the window to apply your logic on selective catalogs only.
I did not write the logic as mentioned above that , you are able to do it globally but want to do it on specific catalogs only.