Problem passing map to function

Problem passing map to function

Sry for the long post. Including all documentation. Zoho is triggering the following error when I try to pass a map to a function, and I can't figure out why:

Error during validation: Error at line : 14, Function specified in criteria has returned null value and it cannot be evaluated

1. My form creates a map of required fields On Validate:

requiredFieldValues = Map();

// Fetch required fields for the form
requiredFields = Fields[form.form_name == "API Protocols" && is_required == true];

for each field in requiredFields
{
    fieldValue = getFieldValue(field.link_name);
    requiredFieldValues.put(field.field_name, fieldValue);
    info "Key: " + field.link_name + ", Value: " + fieldValue;    
}

info "Constructed requiredFieldValues: " + requiredFieldValues;

// Check if the map is empty
if (requiredFieldValues.isEmpty())
{
    alert "No fields to validate.";
    cancel submit;
}

try {
    // Validate required fields - this is line that triggers error
    validationResult = thisapp.validateRequiredFields(requiredFieldValues);

    // Check validation status
    if (validationResult == null || validationResult.get("status") != "success")
    {
        alert "Enter a value for the following required fields: " + validationResult.get("message") ;
        cancel submit;
    }
} catch(e) {
     // Log the error and provide a fallback message
    info "Error during validation: " + e.toString();
    alert "An unexpected error occurred during validation. Please try again.";
    cancel submit;
}

2. The above info lines return the following, which looks like a valid map:
Required fields: api_protocol,eff_date,exp_date
Key: api_protocol, Value: Test
Key: eff_date, Value: 01-01-2025
Key: exp_date, Value: 12-31-2999
Constructed map requiredFieldValues: {"API Protocol":"Test","Eff Date":"01-01-2025","Exp Date":"12-31-2999"}

3. That map is fed into the following function, which takes a map as argument:

map validateRequiredFields(map requiredFieldValues)
{

    // Initialize the response map
    validationResult = Map();
    validationResult.put("status", "success");
    validationResult.put("message", "All required fields are filled");

    // List to track empty fields
    emptyFieldList = List();

    // Iterate over the keys in the map
    for each fieldKey in requiredFieldValues.keys()
    {
        fieldValue = requiredFieldValues.get(fieldKey);
        // Check for null or empty values
        if (fieldValue == null || (fieldValue.isEmpty()))
        {
            emptyFieldList.add(fieldKey);
        }
    }

    // If there are empty fields, update the validation result
    if (emptyFieldList.size() > 0)
    {
        validationResult.put("status", "failure");
        validationResult.put("message", emptyFieldList);
        //validationResult.put("emptyFields", emptyFieldList);
    }

    return validationResult;
}

4. If I test the function by itself with the above map, the function works as expected.

5. When I execute the form, this line fails On Validate:
    validationResult = thisapp.validateRequiredFields(requiredFieldValues);

But if I replace the variable with its actual value (per the info line), it works.
    validationResult = thisapp.validateRequiredFields({"API Protocol":"Test","Eff Date":"01-01-2025","Exp Date":"12-31-2999"});

What am I missing?

    Access your files securely from anywhere







                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts





                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner









                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ



                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方