• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problem updating db table from an array

New Here ,
Dec 18, 2009 Dec 18, 2009

Copy link to clipboard

Copied

I get this error when running this query from a custom tag using this array:

Element 13 is undefined in a CFML structure referenced as part of an expression.

Query:

<cfif mode is "update" and type is "request">
     <cfdump var="#session.aDelgtRR#" />    
     <cftry>
    <cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
        <cfloop List="#ArrayLen(session.aDelgtRR.session.AreaID)#" index="y">
            <!--- 12/18/09 nothing I've tried works. Still get undefined error in cfcatch
            <cfif NOT ArrayIsEmpty(session.aDelgtRR[#x#].session.AreaID)> --->
           
            <cfloop List="#ArrayLen(session.aDelgtRR.session.AreaID.session.JobRole)#" index="z">       
                       
                   
                    <cfquery name="qUpUserRemove_Rqst" datasource="#request.at_datasource#">
                        UPDATE JOB_DelgtAreaRole
                        Set RemoveType=<cfqueryparam value="#session.aDelgtRR.session.RemoveType#" cfsqltype="CF_SQL_VARCHAR" />,
                        RemoveRqstStat=<cfqueryparam value="SUBMITTED" cfsqltype="CF_SQL_VARCHAR" />,
                        Updated=<cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAMP" />,
                        WhoUpdated=<cfqueryparam value="#IHSUID#" cfsqltype="CF_SQL_INT" />
                        WHERE IHSUID = <cfqueryparam value="#session.aDelgtRR.session.DelgtID#" cfsqltype="CF_SQL_INT" />
                        and IHSAreaAssignedID = <cfqueryparam value="#session.aDelgtRR#" cfsqltype="CF_SQL_SMALLINT" />               
                        and fk_JobUser_Role = <cfqueryparam value="#session.aDelgtRR.session.JobRole#" cfsqltype="CF_SQL_SMALLINT" /> 
                    </cfquery>       
                
            </cfloop>
        <!---     <cfelse>
            </cfif> --->
        </cfloop>
    </cfloop>
           <cfcatch type="coldfusion.runtime.UndefinedElementException"><cfdump var="Undefined error" /></cfcatch>         
              <cfcatch type="coldfusion.runtime.CfJspPage$ArrayBoundException"><cfdump var="Array Bound error" /></cfcatch>
          </cftry>
</cfif>
<cfcatch type="Any">
    <cftransaction action="rollback" />
<cfset ArrayAppend(session.serror,"Your submission has encountered an error.") />
</cfcatch>
</cftry>
</cftransaction>

IHS Jobs Vacancies

array
1
struct
SESSION
struct
AREAID
array
1
struct
SESSION
struct
JOBROLE
array  [empty]
2
struct
SESSION
struct
JOBROLE
array  [empty]
3
struct
SESSION
struct
JOBROLE
array  [empty]
4
struct
SESSION
struct
JOBROLE
array  [empty]
5
struct
SESSION
struct
JOBROLE
array  [empty]
6
struct
SESSION
struct
JOBROLE
array  [empty]
7
struct
SESSION
struct
JOBROLE
array  [empty]
8
struct
SESSION
struct
JOBROLE
array  [empty]
9
struct
SESSION
struct
JOBROLE
array  [empty]
10
struct
SESSION
struct
JOBROLE
array  [empty]
11
struct
SESSION
struct
JOBROLE
array  [empty]
12
struct
SESSION
struct
JOBROLE
array  [empty]
13
struct
SESSION
struct
JOBROLE
array
15
27
DELGTID8074
REMOVETYPE
struct
1Remove Role
2
struct
SESSION
struct
AREAID
array
1
struct
SESSION
struct
JOBROLE
array
16
24
2
struct
SESSION
struct
JOBROLE
array  [empty]
3
struct
SESSION
struct
JOBROLE
array  [empty]
4
struct
SESSION
struct
JOBROLE
array  [empty]
5
struct
SESSION
struct
JOBROLE
array  [empty]
6
struct
SESSION
struct
JOBROLE
array  [empty]
7
struct
SESSION
struct
JOBROLE
array  [empty]
8
struct
SESSION
struct
JOBROLE
array  [empty]
9
struct
SESSION
struct
JOBROLE
array  [empty]
10
struct
SESSION
struct
JOBROLE
array
14
23
11
struct
SESSION
struct
JOBROLE
array  [empty]
12
struct
SESSION
struct
JOBROLE
array  [empty]
13
struct
SESSION
struct
JOBROLE
array  [empty]
DELGTID14599
REMOVETYPE
struct
2Remove Role

IHS Jobs Vacanc


TOPICS
Advanced techniques

Views

479

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2009 Dec 18, 2009

Copy link to clipboard

Copied

To start, you have this:

<cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
        <cfloop List="#ArrayLen(session.aDelgtRR.session.AreaID)#" index="y">

Just for fun, do this:

<cfldump var ="#ArrayLen(session.aDelgtRR)#">       
<cfcump var="#ArrayLen(session.aDelgtRR.session.AreaID)#">
<cfabort>

Are there any similarities between what you see and what you expected to see?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2009 Dec 18, 2009

Copy link to clipboard

Copied

I did this:

<cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
        <cfloop List="#ArrayLen(session.aDelgtRR.session.AreaID)#" index="y">
        aDegtRR length: <cfdump var="#ArrayLen(session.aDelgtRR)#">
    aDegtRR Area ID length: <cfdump var="#ArrayLen(session.aDelgtRR.session.AreaID)#">
        <cfabort />

And got this:

IHS Jobs VacanciesaDegtRR length:2 aDegtRR Area ID length:13

AreaID length should be 13 for each aDelgtRR length.

Then I did this:

<cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">       
        <cfloop List="#ArrayLen(session.aDelgtRR.session.AreaID)#" index="y">

          <cfloop List="#ArrayLen(session.aDelgtRR.session.AreaID.session.JobRole)#" index="z">       
                aDegtRR length: <cfdump var="#ArrayLen(session.aDelgtRR)#">
                aDegtRR Area ID length: <cfdump var="#ArrayLen(session.aDelgtRR.session.AreaID)#">
                aDegtRR Area ID Job Role length: <cfdump var="#ArrayLen(session.aDelgtRR.session.AreaID.session.JobRole)#">

IHS Jobs Vacancies

And got this:

aDegtRR length:2 aDegtRR Area ID length:13 aDegtRR Area ID Job Role length:0Undefined error

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2009 Dec 18, 2009

Copy link to clipboard

Copied

You're making progress.  If this:  aDegtRR length: <cfdump var="#ArrayLen(session.aDelgtRR)#">
gives you this:  aDegtRR length: 13

It tells you that the array has 13 elements.  So far, so good.

Then if you do this:

<cfloop List="#ArrayLen(session.aDelgtRR)#" index="x"> 

<cfdump var="x is #x#"><br>

</cloop>

Do you see what you expected to see?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2009 Dec 18, 2009

Copy link to clipboard

Copied

I so appreciate you helping me out !!

I didn't get what you indicated.

There are 2 delgts. Each delgt will have 13 areas. Only some areas will have job roles.

This give me a length of 2:  aDegtRR length:

This give me a length of 13:  aDegtRR Area ID length: <cfdump var="#ArrayLen(session.aDelgtRR.session.AreaID)#"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 19, 2009 Dec 19, 2009

Copy link to clipboard

Copied

Maybe this will make it more clear.  From what you said, ArrayLen(session.aDelgtRR) is 2, and ArrayLen(session.aDelgtRR.session.AreaID) is 13.  The code below is a simplified version of your OP.  Look at it and try to figure out what you would see if you run it.  Then run it and see if your were right.

<cfoutput>

<cfloop List="#ArrayLen(session.aDelgtRR)#" index="x">

x is #x# <br>

<cfloop List="#ArrayLen(session.aDelgtRR.session.AreaID)#" index="y">

y is #y# <br>

</cfloop>

</cfloop>

<hr>

</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2009 Dec 22, 2009

Copy link to clipboard

Copied

LATEST

I got what I expected:

x is 2

y is 13

In the first pass through the array, Delgtid 8074, element 13 is the only one that actually has job roles.

The second pass, for Delgtid 14599, has jobroles for area 1 and 10, but does not have any job roles for element 13.

Thanks for your help, Dan.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation