run a business rule on a particular catalog item(service portal)

ArcRaj
Giga Contributor

HI TEAM,

 

when to run-BEFORE

table-sys_attachment

I WANT THE BELOW BUSINESS TO RULE ON PARTICULAR CATALOG ITEM

/////Business rule///when 2 files are attached with same file name then there will be alert in below BR

(function executeRule(current, previous /*null when async*/) {
{

var gr = new GlideRecord("sys_attachment");
gr.addQuery('table_sys_id', current.table_sys_id);
gr.addQuery('table_name', current.table_name);
gr.addQuery('file_name', current.file_name);
gr.addQuery('content_type', current.content_type);
gr.addQuery('size_bytes', current.size_bytes);
gr.query();
if (gr.next()) {
{
current.setAbortAction(true);
gs.addInfoMessage("File already exist");

}}


})(current, previous);

1 ACCEPTED SOLUTION

you can not , business rule runs on table and catalog form is not a table 

View solution in original post

13 REPLIES 13

Hi Ashok,

 Above code is not working for me

May I see the script?

Thanks

//I placed sys_id of above item 1f97236a2f9e84104e1fa1fef699b688

 if(gr.cat_item == 'sys_id of your catalog item')

Chaitanya Redd5
Tera Guru

Hi,

Harshvardhan is correct and you can not have a business rule to check the attachment on the catalog item, because business rule will be triggered on table level when the record is being inserted/updated/queried/deleted.

I believe you want to restrict the user to attach more than 1 file with the same name on the catalog form. If my understanding is correct then you could achieve this with the help of client script and script include. 

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya