Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Create Run Server Side Script to test Script Include

escanor
Giga Contributor

Hi guys,

I'm trying to create a Run Server Side Script to test one of my script include. But i'm still new with this ATF and don't know how to wirte it. This script below is one of my scipt include. PLs help me to write a run server script to test it ! 

var CalAge = Class.create();
CalAge.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	generateAge: function() {
		var dob = this.getParameter('sysparam_id');
		var today = new GlideDateTime();
		var todayYear = today.getYearLocalTime();
		var bday = new GlideDateTime(dob.toString());
		var bdayYear = bday.getYearLocalTime();
		var age =todayYear - bdayYear;
		return age;
	},
	type: 'CalAge'
});

or this one

var EmailValid = Class.create();
EmailValid.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	isEmailValid: function(email){
			var getEmail = this.getParameter('sysparm_id') || email;	
			var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}/; 
			return regex.test(getEmail);
	},
    type: 'EmailValid'
});
1 ACCEPTED SOLUTION

RAHUL Khanna1
Mega Guru

Hi escanor, 

 

I understand you are trying to test the script Include. The script include what you have written is used to call in client-scripts. How ever you can test the same in the background script, by writing the following code. I did that and could get some result. 

find_real_file.png

 

 

 

View solution in original post

6 REPLIES 6

RAHUL Khanna1
Mega Guru

Forgot  to mention ,

you need to modify SI little to acheive this, which is as follows,

 

generateAge: function(dob) {
//var age = '45' ;
// var dob = this.getParameter('sysparam_id');
var today = new GlideDateTime();
var todayYear = today.getYearLocalTime();
var bday = new GlideDateTime(dob.toString());
var bdayYear = bday.getYearLocalTime();
var age =todayYear - bdayYear;
return age;
}, 

 

 

ty bro ! i really appreciate that. Can you help me the rest of my script code

Email

var EmailValid = Class.create();
EmailValid.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	isEmailValid: function(email){
			var getEmail = this.getParameter('sysparm_id') || email;	
			var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}/; 
			return regex.test(getEmail);
	},
    type: 'EmailValid'
});

Password

var passValid = Class.create();
passValid.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	isPassword: function(){
			var password = this.getParameter('sysparm_id');
			var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}/g;
			return regex.test(password);
	},
    type: 'passValid'
});

Phone

//SERVIEWT 2018/7/4 KhiemNB Common phone valid 
var PhoneValid = Class.create();
PhoneValid.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	isPhoneValid: function(phone){
			var getPhone = this.getParameter('sysparm_id') || phone;
			var regex = /(09|01[2|6|8|9])+([0-9]{8})\b/g;
			return regex.test(getPhone);
	},
    type: 'PhoneValid'
});