Home:ALL Converter>The parameter to the function is required but was not passed in

The parameter to the function is required but was not passed in

Ask Time:2017-03-17T21:41:53         Author:Vince

Json Formatter

I am making a filter in order to drill down into a report. I have two fields that are dependent on the selection of another field (which is a multiselect list). When I make my selection(s) from that multiselect field, it looks like the parameter is being passed in as an array and ultimately not being recognized. It looks as if my parameter is being passed in as an array, which I'm thinking is the issue

Browser Debug Screen

Javascript Code:

function getMO()
{
    var fa_code = $('#tslcFilterFA').val();
    var ao_code = $('#tslcFilterAO').val();
    var wq_code = $('#tslcFilterWQ').val();
    var newOption = '';
    $('#tslcFilterMO').empty();
    $('#tslcFilterMO').append(newOption);
    $('#TSLC_MO_Loading').css('display','inline');

    $.ajax({
        url: '../TSLC/getData.cfc',
        type:"POST",
        cache: false,
        dataType: "text",
        async:true,
        data: {method: "getMO",
            fa_code: fa_code,
            ao_code: ao_code,
            wq_code: wq_code
       },
      success: function(returnMsg)
          {

                try
                {
                    var obj = JSON.parse(returnMsg);
                    $.each(obj.DATA, function(index,row) {
                        if (obj.DATA.length == 1)
                        {
                            var newOption = '<option selected="selected" value="' + row[0] + '">' + row[1] + '</option>';
                        }
                        else
                        {
                            if (row[2] == "1")
                            {
                                var newOption = '<option selected="selected" value="' + row[0] + '">' + row[1] + '</option>';
                            }
                            else
                            {
                                var newOption = '<option value="' + row[0] + '">' + row[1] + '</option>';
                            }


                        }

                        $('#tslcFilterMO').append(newOption);


                    });
                    try
                    {
                        $('#tslcFilterMO').multiselect('destroy');
                    }
                    catch(e) {}
                    $('#tslcFilterMO').multiselect({
                        selectedList: 4
                        }).multiselectfilter();
                    $('.ui-multiselect').css('width','225px');
                    $('#TSLC_MO_Loading').css('display','none');

                }
                catch(e)
                {
                  alert('getMO Error parsing JSON');
                }



          },
        error: function(httpRequest, textStatus, errorThrown)
               {
                    alert("getMO status=" + textStatus + ",error=" + errorThrown);
             }
        });
    }

I've tried to change this line:

var ao_code = $('#tslcFilterAO').val();

to this:

var ao_code = $('#tslcFilterAO').multiselect('getChecked').map(function () {return this.value;}).get();

I've also tried to wrap my ao_code variable in URLDecode() to see if it would pass the value as a string instead of an array, but neither works.

CF Code (from component):

<cffunction name="getMO" access="remote" returntype="any" returnformat="plain" hint="Get distinct Managing Orgs based on FA=ATT_IT and AO">
    <cfargument name="fa_code" type="string" required="true">
    <cfargument name="ao_code" required="true">
    <cfargument name="wq_code" required="true">

    <cfquery name="qMO" datasource="#request.dbdsn_ic4p#" username="#request.dbuser_m66266#" password="#request.dbpw_m66266#">
         SELECT DISTINCT managing_org MANAGING_ORG, DECODE(managing_org,'*','*ALL*',managing_org) MANAGING_ORG_DISPLAY, DECODE(managing_org,'*',1,2) sortcol
        <cfif #fa_code# NEQ "ATT_IT">
             FROM HAS_TICKET_STATE_GUI_LOOKUP
             WHERE client_id = '#fa_code#'
        <cfelse>
            FROM IT_TICKET_STATE_GUI_LOOKUP
            WHERE 1=1
        </cfif>
        <cfif #ao_code# neq "">
            AND active_org IN (<cfqueryparam value="#ao_code#" cfsqltype="cf_sql_varchar" list="true" />)
        </cfif>
        <cfif #wq_code# neq "">
            <!--- !COM: is workaround for commas in listbox items! --->
            AND work_queue IN (#replace(ListQualify(wq_code,"'",",","CHAR"),":COM!",",","all")#)
        </cfif>
        ORDER BY 3, 1
    </cfquery>

    <cfreturn serializeJson(qMO)>
</cffunction>

Author:Vince,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42859100/the-parameter-to-the-function-is-required-but-was-not-passed-in
ultimoTG :

Change this line in your JS code \n\nvar ao_code = $('#tslcFilterAO').val(); \n\n\nto \n\nvar ao_code = $('#tslcFilterAO').val().join(\",\"); \n\n\nThat should give you a list of string values from the multiple select field that you're expecting in your function in the CFC.\n\nThe join() method joins all elements of an array into a string. More on \"join\" here. ",
2017-03-18T03:43:06
Vince :

This article helped me solve my problem... https://christierney.com/2011/06/07/returning-multiple-value-elements-to-coldfusion-remote-method-via-jquery-ajax/\n\nfunction getWQ()\n{\nvar fa_code = $('#tslcFilterFA').val();\nvar ao_code = $('#tslcFilterAO').val();\nif ($.isArray(ao_code))\n var ao_code_array = ao_code.join(\",\");\nelse\n var ao_code_array = ao_code;\nvar mo_code = $('#tslcFilterMO').val();\nif ($.isArray(mo_code))\n var mo_code_array = mo_code.join(\",\");\nelse\n var mo_code_array = mo_code;\nvar newOption = '';\n$('#tslcFilterWQ').empty();\n$('#tslcFilterWQ').append(newOption);\n$('#TSLC_WQ_Loading').css('display','inline');\n\n$.ajax({\n url: '../TSLC/cfcs/getData.cfc',\n type:\"POST\",\n cache: false,\n dataType: \"text\",\n async:true,\n data: {method: \"getWQ\",\n fa_code: fa_code,\n mo_code: mo_code_array,\n ao_code: ao_code_array\n },\n success: function(returnMsg)\n {\n",
2017-04-19T17:12:21
yy