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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi KB - You can apply filter condition in business rule i.e catalog item is | XYZ so that BR will only run for those Items.

Would I have to edit the BR to run off the cat item table instead of the attachment table?

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

If the business rule is on attachment table then you can get the catalog item value via dot-walking script. 

Can you dotwalk from the attachment table when the item hasn't been submitted yet? There's nothing to reference the request item from there.