Skip to content

Commit eddf1ae

Browse files
authored
Create DataValidationUtils.js
Script Include Code
1 parent eb03799 commit eddf1ae

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var DataValidationUtils = Class.create();
2+
DataValidationUtils.prototype = {
3+
initialize: function() {},
4+
5+
validateIncidentData: function(incidentRecord) {
6+
var errors = [];
7+
8+
// Validate short description if the field exists
9+
if (incidentRecord.isValidField('short_description')) {
10+
if (gs.nil(incidentRecord.short_description)) {
11+
errors.push('Short description is required.');
12+
}
13+
} else {
14+
errors.push('Field "short_description" does not exist on the record.');
15+
}
16+
17+
// Validate priority if the field exists
18+
if (incidentRecord.isValidField('priority')) {
19+
if (gs.nil(incidentRecord.priority) || incidentRecord.priority < 1 || incidentRecord.priority > 5) {
20+
errors.push('Priority must be between 1 and 5.');
21+
}
22+
} else {
23+
errors.push('Field "priority" does not exist on the record.');
24+
}
25+
26+
return errors;
27+
},
28+
29+
type: 'DataValidationUtils'
30+
};

0 commit comments

Comments
 (0)