- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:56 AM
Use Below code in before insert rule for change request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:56 AM
Use Below code in before insert rule for change request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 06:06 AM
you can use before insert BR on your table with this script
You need not query with table name; only table sysId is enough
You can also use GlideAggregate for optimization
(function executeRule(current, previous /*null when async*/ ) {
var rec = new GlideRecord("sys_attachment");
rec.addQuery("table_sys_id", current.getUniqueValue());
rec.query();
var count = rec.getRowCount();
if (count < 5) {
gs.addErrorMessage("Please attach 5 files");
current.setAbortAction(true);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 07:53 AM - edited 08-01-2023 07:54 AM
Hi @Ankur Bawiskar ,
Thanks for your response. I have 3 categories. if category = Test1 i need to set one attachment mandatory
category = Test2 i need 3 documents mandatory
Category = Test 10 i need set 10 documents mandatory. How we can implement this in BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 08:00 AM
just use if else and add the correct count check
I hope you will be able to enhance the below code as per your requirement by adding correct choice value for category and field name
(function executeRule(current, previous /*null when async*/ ) {
var rec = new GlideRecord("sys_attachment");
rec.addQuery("table_sys_id", current.getUniqueValue());
rec.query();
var count = rec.getRowCount();
var cat = current.category;
if(cat == 'Test1' && count < 1){
gs.addErrorMessage("Your Message 1");
current.setAbortAction(true);
}
else if(cat == 'Test2' && count < 3){
gs.addErrorMessage("Your Message 2");
current.setAbortAction(true);
}
else if(cat == 'Test10' && count < 10){
gs.addErrorMessage("Your Message 3");
current.setAbortAction(true);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader