Unable to restrict users from subitting a time sheet past 30 days in the future

Rhonda9
Tera Expert

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:

 
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
}
1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

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.

 

View solution in original post

4 REPLIES 4

Bert_c1
Kilo Patron

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.

 

Rhonda9
Tera Expert

Thank you , I tried the br and it did give me the message but the time card still submitted.

 

Bert_c1
Kilo Patron

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.

Rhonda9
Tera Expert

Thank you for your help, this did work for me after I changed the scope to global.