catalog client script not working in service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2023 09:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2023 10:09 AM
Hi,
g_form.getControl() does not work in Service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2023 10:16 AM
Hi @Thomas99,
Yes I agree with @Shruti . g_form.getControl() will not work.
Can you try updating line as
var startDateField = g_form.getValue('start_date'); // Replace 'start_date' with the actual field name
If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2023 10:24 AM
Hello @Thomas99 ,
Service Portal does not support all client scripting APIs that are available in the platform UI. The script you provided uses the g_form.getControl() method, which is not supported in Service Portal.
1. Remove the line var startDateField = g_form.getControl('start_date'); because g_form.getControl() is not supported in Service Portal.
2. Replace startDateField.value with g_form.getValue('start_date') to get the value of the 'start_date' field.
3. Replace startDateField.value = ''; with g_form.setValue('start_date', ''); to clear the field.
Here's the modified script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var currentDate = new Date();
var minStartDate = calculateMinStartDate(currentDate, 2);
var selectedStartDate = new Date(g_form.getValue('start_date'));
if (selectedStartDate < minStartDate) {
var message = 'Start date must be at least two business days from today';
g_form.showErrorBox('start_date', message);
g_form.setValue('start_date', ''); // 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;
}
}
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2023 11:00 AM
Thank you Abhiijeet.
This works and the dates clear, however , I do not get the error on the field.