Genesys Cloud - Main

 View Only

Sign Up

  • 1.  Need Help Filtering and Converting API Date Formats

    Posted 3 days ago

    Hi Team,

    I am receiving date formats from an API such as:
    "Nov 17, 2025 - Dec 17, 2025", "Nov 17,25", "Feb 2025-Dec 2025", "[Dec 19, 2025]", "[Nov 17, 2025 - Dec 17, 2025]", "[Feb 2025-Dec 2025]", "[Feb 2025]", "Feb 2025", etc.

    I want to consider only the following valid formats:
    Nov 12,25
    Nov 12,2025
    [Nov 17, 2025]

    All other formats should be ignored and treated as NOT_SET.

    I have tried a few approaches, but they are not working. Could someone please provide the correct expression/logic to achieve this inside a loop? After filtering, I also need to convert the valid values into a proper date format and 

    Play the Date format to the customer.


    #ArchitectandDesign

    ------------------------------
    Srikanth k s
    ------------------------------


  • 2.  RE: Need Help Filtering and Converting API Date Formats

    Posted 3 days ago

    Hi Srikanth, I would handle this in Architect.

    My suggestion is to configure the Data Action to return the date value as raw data, without transforming it in the action. Then, inside the Architect loop, parse the returned string by breaking it into month, day and year.
    From there, you can validate only the expected formats, ignore ranges or unsupported values, normalize the brackets/spacing when needed, convert the month abbreviation to a number, adjust the year if it comes with two digits, and then rebuild it as a proper DateTime.
    After that, you can use ToAudioDate() or ToAudioDateTime() to play the date to the customer.
    I would only use a Genesys Cloud Function if this rule becomes more complex or needs to be reused across multiple flows. For this case, keeping the logic in Architect should be simpler and easier to debug.


    ------------------------------
    Att,
    Breno Canyggia Ferreira Marreco
    ------------------------------



  • 3.  RE: Need Help Filtering and Converting API Date Formats
    Best Answer

    Posted 3 days ago

    Hi,

    For this scenario, I would suggest using a Function Data Action instead of trying to handle all the validation directly inside Architect.

    Since the API can return many different date formats, Architect expressions can become hard to maintain. A function would let you validate the raw value, reject unsupported formats, and return only a normalized date back to the flow.

    For example, you could send the raw date value to the function and only accept formats like:

    Nov 12,25

    Nov 12,2025

    [Nov 17, 2025]

    Anything with a range, missing day, or month/year only would return NOT_SET.

    Example Function Data:

    JavaScript

    // index.js

    exports.handler = async (event) => {

      const rawDate = event.rawDate || "";

      const normalizedDate = normalizeDate(rawDate);

      return {

        originalValue: rawDate,

        isValid: normalizedDate !== "NOT_SET",

        normalizedDate: normalizedDate

      };

    };

    function normalizeDate(value) {

      if (!value || typeof value !== "string") {

        return "NOT_SET";

      }

      let dateText = value.trim();

      // Reject ranges like "Nov 17, 2025 - Dec 17, 2025"

      if (dateText.includes("-")) {

        return "NOT_SET";

      }

      // Handle optional brackets

      const startsWithBracket = dateText.startsWith("[");

      const endsWithBracket = dateText.endsWith("]");

      if (startsWithBracket !== endsWithBracket) {

        return "NOT_SET";

      }

      if (startsWithBracket && endsWithBracket) {

        dateText = dateText.substring(1, dateText.length - 1).trim();

      }

      // Accept: Nov 12,25 or Nov 12,2025 or Nov 12, 2025

      const regex = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+([1-9]|[12][0-9]|3[01]),\s*(\d{2}|\d{4})$/i;

      const match = dateText.match(regex);

      if (!match) {

        return "NOT_SET";

      }

      const monthMap = {

        jan: 1,

        feb: 2,

        mar: 3,

        apr: 4,

        may: 5,

        jun: 6,

        jul: 7,

        aug: 8,

        sep: 9,

        oct: 10,

        nov: 11,

        dec: 12

      };

      const month = monthMap[match[1].toLowerCase()];

      const day = parseInt(match[2], 10);

      let year = parseInt(match[3], 10);

      if (year < 100) {

        year = 2000 + year;

      }

      // Validate real calendar date

      const testDate = new Date(Date.UTC(year, month - 1, day));

      if (

        testDate.getUTCFullYear() !== year ||

        testDate.getUTCMonth() + 1 !== month ||

        testDate.getUTCDate() !== day

      ) {

        return "NOT_SET";

      }

      return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;

    }

    Example input:

    JSON

    {

      "rawDate": "Nov 12,25"

    }

    Example output:

    JSON

    {

      "originalValue": "Nov 12,25",

      "isValid": true,

      "normalizedDate": "2025-11-12"

    }

    Then in Architect, you only need to check the function response. If normalizedDate is NOT_SET, skip it or use your fallback logic. If it returns a valid value like 2025-11-12, you can convert/play that date back to the customer.

    If this is running inside a loop, this approach will keep the flow much cleaner than trying to build all the string validation directly in Architect.



    ------------------------------
    Arthur Pereira Reinoldes
    ------------------------------



  • 4.  RE: Need Help Filtering and Converting API Date Formats

    Posted 2 days ago

    Hi Arthur Pereira Reinoldes, I used a similar approach to what you suggested. I separated the day, month, and year, converted them properly, and then combined them into a single variable. After that, I tested it, and it worked as expected. Thank you so much.



    ------------------------------
    Srikanth k s
    ------------------------------