sp-date-picker validation on ServicePortal

Kalik2
Tera Expert

Kalik2_0-1670706255468.png

I have created start date and end date field using angular ng template using the below code.

 

<sp-date-picker
field="::spDatePickerConfig.startTime || {}"
ng-model="start.value"
sn-include-time="true"
sn-change="timeChange('start')">
</sp-date-picker>

 

I want that if the user selects a time outside office hours 9am-6pm , he should be asked to select time between office hours.

 

And if the user selects the time in the office hours but that time is already past, the next day's date should populate automatically.

How can I achieve this?

 

11 REPLIES 11

<wsd-search-filter
mode="c.mode"
location-tree-data="c.data.location_tree_data"
reservation="c.reservation"
start="c.start"
end="c.end"
day-start="c.data.dayStart"
day-end="c.data.dayEnd"
page-size="c.options.page_size"
init-config="::c.data.initSearchConfig"
is-multi-item-selection="c.selectedItems.length > 1"
disable-change-location="c.isChangeLocationDisabled()"
disable-change-module="c.isEditing || c.selectedItems.length >= 1"
types = "c.data.reservable_modules"
translations = "c.data.translations">
</wsd-search-filter>

@Kalik1 Its angular provider. Please post angular provider code.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@Kalik1 Please write the client side function in controller of angular provider

 

Code needs some update as below. c should be changed to $scope.

 

$scope.timeChange = function(start){
$scope.data.enteredDateTime = start.value;
$scope.data.action = "checkStartDate";
$scope.server.update().then(function(resp){
if(resp.message){
alert(resp.message)
}

if($scope.data.isOldDate){
alert("Entered date is past date, setting to new date")
start.value = $scope.data.newDate;
}
})
}

 

Please try this, this should solve your issue.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Kalik1_0-1670768680021.png

 

Kalik1_2-1670768840826.png