Category: Scenario based QA - 6
Updated on: August 2, 2025  |  0

Scenario-Based Questions PART 6

📘 Scenario-Based Question

Q: I have a catalog item with two fields: start date and end date. The end date should always be exactly 3 days after the start date. If this condition is not met, the form should not be submitted, and an error message should be displayed. How can you achieve this?

 

Answer:

There are two main approaches to implement this logic:


🧠 Option 1: Client Script (onSubmit)

Create a Catalog Client Script of type onSubmit with the following script:

function onSubmit() {
  var startDate = g_form.getValue('start_date');
  var sd = getDateFromFormat(startDate, g_user_date_format);
  var endDate = g_form.getValue('end_date');
  var ed = getDateFromFormat(endDate, g_user_date_format);

  var dayDiff = (ed - sd) / (1000 * 60 * 60 * 24); // Convert ms to days

  if (dayDiff !== 3) {
    g_form.addErrorMessage("End date must be exactly 3 days after the start date.");
    return false;
  }
  return true;
}

Note: Adjust field names 'start_date' and 'end_date' to match your variable names.


🛠 Option 2: UI Policy

If you prefer a configuration-based (low-code) solution, you can use a UI Policy with conditions for date validation. This works best for simpler logic or enforcing visibility/read-only behavior.

However, in this case, since precise date math is involved, using a Catalog Client Script is more appropriate for blocking form submission.


Best Practice:
Always validate date logic on the client-side for faster feedback and better user experience. Optionally, you can enforce the same on the server using a Catalog Business Rule to ensure integrity.

Comments

No comments yet.


Log in to post a comment