catalog client script not working in service portal

Thomas99
Tera Contributor
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

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.