- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 03:18 AM
Hi All,
I have a field called Attachment, In that I have 3 choices i.e Test1 Test2 and Test3
if I select Test1 and Test2,
Error message should display attachemt is manadatory
if I select Test3
it should not give any error
Note: Only for Test1 and Test2 only we have the attachment not for entire form.
could you please help on this
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:28 AM
@Community Alums Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 03:40 AM
Create an onChange Client Script on your table to trigger when new value is Test1 or Test2 and use
g_form.addErrorMessage('You need to attach an attachment to this record');
to show the error message. Or use showFieldMsg() to show it under the field itself.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 03:42 AM
Hi @Community Alums ,
Please apply below Business Rule on your form
(function executeRule(current, previous /*null when async*/) {
// Get the value of the 'Attachment' field
var attachment = current.attachment;
// Check if the 'Test1' and 'Test2' options are selected
var test1Selected = attachment.includes('Test1');
var test2Selected = attachment.includes('Test2');
// Check if either 'Test1' or 'Test2' is selected
var test1Or2Selected = test1Selected || test2Selected;
// Check if 'Test3' is selected
var test3Selected = attachment && attachment.includes('Test3');
// If 'Test1' or 'Test2' is selected and there is no attachment, display an error message
if (test1Or2Selected && !current.u_attachment) {
gs.addErrorMessage('Attachment is mandatory when "Test1" or "Test2" is selected.');
}
// If 'Test3' is selected, do not display an error message
if (test3Selected) {
gs.clearErrorMessage('Attachment is mandatory when "Test1" or "Test2" is selected.');
}
})(current, previous);
If this is helpful for you, Please mark Helpful and Correct solution
Thanks & Regards
Adarsh Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 03:46 AM
Hi @Community Alums ,
I tried your problem and it works for me please refer below steps
1. Create Before Business Rule and add this below script
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
gs.log('BR Called = ' + current.getTableName());
var att = new GlideAggregate('sys_attachment');
att.addAggregate('COUNT');
att.addQuery('table_name', current.getTableName());
att.addQuery('table_sys_id', current.sys_id);
att.query();
var count = 0;
if (att.next()) {
count = att.getAggregate('COUNT');
if (count < 1) {
gs.addErrorMessage("Please attach Attachment");
current.setAbortAction(true);
}
}
})(current, previous);
Result
I save with test_one value in attahcment and I tried to save that record which has no attachment and it throws me the error.
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 04:02 AM
it is not for table it is for catalog form