- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 02:34 PM
I have a requirement to create a validation for users not to be able to submit a time sheet that is greater than 30 days in the future. I created a script include and a business rule but I am getting the msg "Access to api 'setAbortAction' from scope 'sn_itsm_mobile_agt' has been refused due to the api's cross-scope access policy.
Script Include:
var validator = new MobileTimeCardValidation();
var isValid = validator.validateTimeCardDate(current.week_starts_on);
if (!isValid) {
gs.addErrorMessage('You cannot create a time card for a date more than 30 days in the future.');
current.setAbortAction(true); // Abort the insert/update action
}
Before Business Rule:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 05:58 PM - edited 10-22-2024 06:01 PM
hi Rhonda9,
I tried a business rule defined on the 'time-sheet' table, that worked for me. It runs Before for Insert/Update and Filter condition "Week starts on", "Changes". Advanced is checked and the script logic follows:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var wsoDate = current.week_starts_on;
var curDate = new GlideDate();
curDate.addDays(30);
//gs.addInfoMessage('wso date: ' + wsoDate + ' and date limit = ' +curDate);
if (wsoDate > curDate) {
gs.addErrorMessage('You cannot create a time card for a date more than 30 days in the future.');
current.setAbortAction(true); // Abort the insert/update action
}
})(current, previous);
I have no idea what "MobileTimeCardValidation" object is. The above doesn't use that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 05:58 PM - edited 10-22-2024 06:01 PM
hi Rhonda9,
I tried a business rule defined on the 'time-sheet' table, that worked for me. It runs Before for Insert/Update and Filter condition "Week starts on", "Changes". Advanced is checked and the script logic follows:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var wsoDate = current.week_starts_on;
var curDate = new GlideDate();
curDate.addDays(30);
//gs.addInfoMessage('wso date: ' + wsoDate + ' and date limit = ' +curDate);
if (wsoDate > curDate) {
gs.addErrorMessage('You cannot create a time card for a date more than 30 days in the future.');
current.setAbortAction(true); // Abort the insert/update action
}
})(current, previous);
I have no idea what "MobileTimeCardValidation" object is. The above doesn't use that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 06:23 PM
Thank you , I tried the br and it did give me the message but the time card still submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:43 AM - edited 10-23-2024 07:44 AM
hi @Rhonda9
It works in my instance, the condition I have does allow users with the 'admin' or 'user_admin' role to enter whatever date value they like. Again, I have no idea what "MobileTimeCardValidation" is. I suggest you post what you have done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:49 AM
Thank you for your help, this did work for me after I changed the scope to global.