Professional Web Applications Themes

Web Service and Arrays - Coldfusion - Advanced Techniques

Hi, I am receiving an array of an array and having lots of problems. If you look at the code, I receive an array of 10 objects and then each object has five elements in it. The query setup goes fine for few records and then gives an error saying that certain element of the array is undefined. I have checked the input and it perfectly fine. Any clue?? I would really appreciate any help. Thanks, Salman Maqsood Saltech Systems <cffunction name="fncSetStats" access="remote" returntype="string" output="false"> <cfargument name="authString" type="string" required="yes" /> <cfargument name="strStats" type="array" required="yes" /> <cfif isdefined("application.webservice.#Trim(arguments. authString)#")> <cfif isArray(strStats)> ...

  1. #1

    Default Web Service and Arrays

    Hi,

    I am receiving an array of an array and having lots of problems. If you look
    at the code, I receive an array of 10 objects and then each object has five
    elements in it. The query setup goes fine for few records and then gives an
    error saying that certain element of the array is undefined. I have checked the
    input and it perfectly fine. Any clue?? I would really appreciate any help.

    Thanks,
    Salman Maqsood
    Saltech Systems


    <cffunction name="fncSetStats" access="remote" returntype="string"
    output="false">
    <cfargument name="authString" type="string" required="yes" />
    <cfargument name="strStats" type="array" required="yes" />

    <cfif isdefined("application.webservice.#Trim(arguments. authString)#")>
    <cfif isArray(strStats)>

    <cfset myQuery = QueryNew("Field1,Field2.Field3,Field4,Field5")>
    <cfset newRow = QueryAddRow(myQuery, ArrayLen(strStats))>
    <cfloop from="1" to="#ArrayLen(strStats)#" index="i">
    <cfset temp = QuerySetCell(myQuery, "Field1", strStats[1], i)>
    <cfset temp = QuerySetCell(myQuery, "Field2", strStats[2], i)>
    <cfset temp = QuerySetCell(myQuery, "Field3", strStats[3], i)>
    <cfset temp = QuerySetCell(myQuery, "Field4", strStats[4], i)>
    <cfset temp = QuerySetCell(myQuery, "Field5", strStats[5], i)>
    </cfloop>

    </cfif>
    </cfif>
    </cffunction>

    saltech Guest

  2. #2

    Default Re: Web Service and Arrays

    If it's an array of arrays, wouldn't you want....

    <cfset temp = QuerySetCell(myQuery, "Field1", strStats[1], i)>
    ....
    BSterner Guest

  3. #3

    Default Re: Web Service and Arrays

    Otherwise, the query column types would be arrays. Also, this might be a typo
    just in this post, but one of the column names has a '.' separating it instead
    of a ','

    <cfset myQuery = QueryNew("Field1,Field2.Field3,Field4,Field5")>

    Couple other suggestions...

    1) I would recommend scoping any variables you reference.

    Eg) <cfif isArray(arguments.strStats)>

    2) Any variables created in the function should have the 'var' (aka private)
    scope.

    <cffunction name="fncSetStats" access="remote" returntype="string"
    output="false">
    <cfargument name="authString" type="string" required="yes" />
    <cfargument name="strStats" type="array" required="yes" />

    <cfset var myQuery = "" />
    <cfset var newRow = "" />
    <cfset var temp = "" />

    <cfif isdefined("application.webservice.#Trim(arguments. authString)#")>
    <cfif isArray(strStats)>

    <cfset myQuery = QueryNew("Field1,Field2,Field3,Field4,Field5")>
    <cfset newRow = QueryAddRow(myQuery, ArrayLen(strStats))>
    <cfloop from="1" to="#ArrayLen(strStats)#" index="i">
    <cfset temp = QuerySetCell(myQuery, "Field1", strStats[1], i)>
    <cfset temp = QuerySetCell(myQuery, "Field2", strStats[2], i)>
    <cfset temp = QuerySetCell(myQuery, "Field3", strStats[3], i)>
    <cfset temp = QuerySetCell(myQuery, "Field4", strStats[4], i)>
    <cfset temp = QuerySetCell(myQuery, "Field5", strStats[5], i)>
    </cfloop>

    </cfif>
    </cfif>
    </cffunction>



    BSterner Guest

Similar Threads

  1. Arrays (combine two arrays)
    By RonFusion in forum Coldfusion - Getting Started
    Replies: 11
    Last Post: May 2nd, 09:35 PM
  2. Nesting Arrays within arrays.
    By JimmySlam in forum Macromedia Flash Ad Development
    Replies: 3
    Last Post: March 15th, 09:42 AM
  3. Storing Web Service Results in Unique Arrays/Objects
    By csgdemon in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: May 24th, 03:32 PM
  4. Passing arrays of structs from C# web service to raw C++?
    By WTH in forum ASP.NET Web Services
    Replies: 1
    Last Post: April 20th, 06:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139