0

I am trying to build the array to store the report column names, but I got the following error: You have attempted to dereference a scalar variable of type class coldfusion.runtime. Array as a structure with members.

enter image description here

My code is:

<cfscript>
        currentAssetNum  = 0;
        headerLabels     = "";
        headerUnderlines = "";
        reportContent    = "";

        columns = eqInventoryHelper.getPreformattedColumnCharacteristics(showComponents = variables.showComponents);

        // Get an array of the columns in the order they should be displayed.
        columnOrder = StructSort(columns, "numeric", "asc", "sortOrder");

        for (columnName in columnOrder) {
            //for (columnIndex=1; columnIndex <= StructCount(columns); columnIndex++){                          
            if (columns[columnName].justify == "left") {                        
                headerLabels &= LJustify(columns[columnName].label, columns[columnName].length) & " ";
            } else {                    
                headerLabels &= RJustify(columns[columnName].label, columns[columnName].length) & " ";
            }
            headerUnderlines &= RepeatString( "-", columns[columnName].length ) & " ";
        }       
        reportHeaders = headerLabels & variables.newLine & headerUnderlines;

    </cfscript> 

eqInventoryHelper.cfc:

<cffunction name="getPreformattedColumnCharacteristics" output="false">
    <cfargument name="showComponents" required="true"/>
    <cfscript>
        var columnSort = 1;         
        var columns = {
            asset_num = {label = "KFS Asset Number", length = 16, justify = "left", sortOrder = columnSort++},
            manufacturer_name = {label = "Manufacturer", length = 30, justify = "left", sortOrder = columnSort++},
            manufacturer_model_num = {label = "Model", length = 30, justify = "left", sortOrder = columnSort++},
            serial_num = {label = "Serial Number", length = 30, justify = "left", sortOrder = columnSort++},
            condition_code = {label = "Cond CD", length = 8, justify = "left", sortOrder = columnSort++},
            owner_chart = {label = "Owner", length = 6, justify = "left", sortOrder = columnSort++},
            owner_acct = {label = "Account", length = 10, justify = "left", sortOrder = columnSort++},
            cur_uc_fnd = {label = "UC Fund", length = 8, justify = "left", sortOrder = columnSort++},
            org_cd = {label = "Org Code", length = 10, justify = "left", sortOrder = columnSort++},
            custodial_code = {label = "Custodial Code", length = 15, justify = "left", sortOrder = columnSort++},
            pi_name = {label = "Principal Investigator", length = 30, justify = "left", sortOrder = columnSort++},
            uc_acquisition_code = {label = "Acq. Type", length = 10, justify = "left", sortOrder = columnSort++},
            received_date = {label = "Received Date", length = 14, justify = "right", sortOrder = columnSort++},
            asset_desc = {label = "Asset Description", length = 51, justify = "left", sortOrder = columnSort++},
            ucop_tag_num = {label = "UCOP Tag Number", length = 16, justify = "left", sortOrder = columnSort++},
            asset_location = {label = "Asset Location", length = 60, justify = "left", sortOrder = columnSort++},
            asset_type = {label = "Asset Type", length = 11, justify = "left", sortOrder = columnSort++},
            is_uc_title = {label = "UCD Title", length = 14, justify = "left", sortOrder = columnSort++},
            total_cost = {label = "Total Cost", length = 12, justify = "right", sortOrder = columnSort++},
            useful_life = {label = "Useful Life", length = 12, justify = "right", sortOrder = columnSort++}
        };

        // If showing components, we tack the component specific columns to the main columns array.
        if (arguments.showComponents) {
            columns.component_num = {label = "Component Number", length = 18, justify = "left", sortOrder = columnSort++};
            columns.component_desc = {label = "Component Description", length = 45, justify = "left", sortOrder = columnSort++};
            columns.component_manufacturer_name = {label = "Manufacturer Name", length = 18, justify = "left", sortOrder = columnSort++};
            columns.component_model_num = {label = "Manufacturer Model Number", length = 26, justify = "left", sortOrder = columnSort++};
            columns.component_serial_num = {label = "Serial Number", length = 20, justify = "left", sortOrder = columnSort++};
            columns.component_po_number = {label = "PO Number", length = 12, justify = "right", sortOrder = columnSort++};
        }
        return columns;
    </cfscript>
</cffunction>

Thank you.

9
  • 1
    Which one is line 538? Commented Jul 25, 2014 at 17:37
  • On cfscript, line 538 : for (columnName in columnOrder) { Commented Jul 25, 2014 at 17:52
  • Looks like the value you passed in argument 4 doesn't exist in the struct and the array is empty Commented Jul 25, 2014 at 18:10
  • Argument 4...Did you mean the sortOrder on this code? <cfscript>... columnOrder = StructSort(columns, "numeric", "asc", "sortOrder");...</cfscript> Commented Jul 25, 2014 at 18:27
  • Did you look at the contents of the various variable you're trying to use, and check what's in them? You don't say you did or provide that information, if you did. Pls investigate and update question accordingly. Commented Jul 25, 2014 at 18:30

1 Answer 1

2

I have a strong suspicion you are using a version of ColdFusion that predates the for(index in array) syntax. This was only added in ColdFusion 9.0.1.

So if you are running 9.0, it will not work, and it will assume you mean to be iterating over a struct.

Sign up to request clarification or add additional context in comments.

5 Comments

Adam's probably right. Dump your full version number. The docs say it was introduced in ColdFusion 9 Update 1. Sounds like you are using 9,0,0.
Cheers @Leigh: I've updated my answer accordingly. Couldn't find that ref when I first checked.
Thanks. Yes, my version is 9,0,0,251028.
The syntax "for(index in array)" is working, but not "for(index in arraysort)".
I sincerely doubt both of those last two statements are accurate. Can you pls run this code and post the results: gist.github.com/daccfml/5321f6dcb24c724dc586

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.