Restrict attachments to specific catalog items via BR

KB15
Giga Guru

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?

1 ACCEPTED SOLUTION

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.

View solution in original post

17 REPLIES 17

Updated answer.

Nice. Thanks for your help! Make sense for single items like this.

Just want to add that I'm seeing this error on on other tables when attaching:

Exception (TypeError: Cannot convert null to an object. (sys_script_include.fd2e2f5fdbe46c1079867c9239961960.script; line 12)) occured while evaluating'Condition: new catalogAttachmentUtils().checkRestriction(current.table_sys_id);' in business rule

Would there be another condition to add if it's null? I'm not sure what's null here.