catalog client script not working in service portal
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2023 09:20 AM
Can someone please help!
I cant get this catalog client script working in service portal, however works fine in the native UI.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var currentDate = new Date();
var minStartDate = calculateMinStartDate(currentDate, 2);
var startDateField = g_form.getControl('start_date'); // Replace 'start_date' with the actual field name
var selectedStartDate = new Date(startDateField.value);
if (selectedStartDate < minStartDate) {
var message = 'Start date must be at least two business days from today';
g_form.showErrorBox('start_date', message);
startDateField.value = ''; // Clear the field
}
function calculateMinStartDate(currentDate, days) {
// Add 'days' business days to the current date, excluding weekends
var minDate = new Date(currentDate);
while (days > 0) {
minDate.setDate(minDate.getDate() + 1);
if (minDate.getDay() !== 0 && minDate.getDay() !== 6) {
days--;
}
}
return minDate;
}
}
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2023 11:13 AM - edited 10-21-2023 11:32 AM
Hello @Thomas99 ,
try the below code I hope this will work for you.
function(spModel)
{ var field = spModel.getField('table_name', 'field_name');
field.setError('This is an error message);
}
If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers!
Thanks and Regards,
Abhijeet Pawar.