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

Variables inside loop not assigning properly

Guest
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

Hey Guys,

I am probably making a totally novice error here somewhere, but hell if I can see it. Basically I have some code that loops over a query, inside that query I assign some information into an array. Probelm is my array comes out completly filled with information from the last record of the query. So for example if my query had the people

   Name

1 Tom

2 Frank

3 Jones

I want my array (which is actuall an array of structures) to have the info like

1.Name:Tom

2.Name:Frank

3.Name:Jones

but I'm ending up with

1.Name:Jones

2.Name:Jones

3.Name:Jones

All elements take the same info as the last record in the query. If you still don't quite follow here is a link that shows an actual query, and the resulting structure.

http://portal.fpitesters.com/queryexample.cfm

And here is the relevent code.

<cfloop query="CampaignMembers">
     <cfset LoopCounter = LoopCounter + 1>
     <cfset batchcounter = batchcounter + 1>

     <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Calling #Contact_IVRPHONE__c# At #timeformat(now())#">

     <cfset GuidArray[LoopCounter] = server.AngelAPI.PlaceCallToAngel(CampaignMembers.Contact_Name,CampaignMembers.Contact_PID__c,CampaignMembers.Contact_IVRPHONE__c,url.AngelSite,url.MaxWaitTime)>     
     <cfset GuidArray[LoopCounter].ContactID = CampaignMembers.Contact_ID>
     <cfset GuidArray[LoopCounter].CampaignMemberID = CampaignMembers.ID>
     

     <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Placed Call: GUID Is #GuidArray[LoopCounter].GUID#. Called #Contact_IVRPHONE__c#. Status is: #GuidArray[LoopCounter].Message#">
                                                       
     <cfif batchcounter EQ form.batchsize>                                   
     
          <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Finished Batch #maincounter/url.batchsize# At #timeformat(now())#">
          <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="------------------------------------------------------------">
          <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="  ">

          <cfoutput>#repeatString(" ", 73729)#</cfoutput>
          <cfflush>
                                                            
          <cfif url.waittime GT 0 and maincounter LT CampaignMembers.RecordCount>
               <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Started Waiting At #timeformat(now())#">
               <CFTHREAD ACTION="SLEEP" DURATION="#url.waittime*60000#"></cfthread>
               <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="  ">
          </cfif>   
          <cfset batchcounter = 0>
     </cfif>     
     

     <cfset maincounter = maincounter + 1>
</cfloop>     

TOPICS
Advanced techniques

Views

2.2K

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 ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

Include the rownumber of your query output.

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 ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

What does server.AngelAPI.PlaceCallToAngel() return?  It looks to me like it's returning the same struct over and over again, so that each element of your array is actually containing the same struct, so you're updating ALL of the array elements when you set the ContactID and CampaignMemberID values.

You can test this by dumping out the array each iteration, and I imagine all elements will contain the latest record only.

If so, you should probably return a DUPLICATE of the struct in your method, or set GuidArray[LoopCounter] to be a duplicate of the return value from PlaceCallToAngel().

PS: when one iterates over a query, one gets a counter variable currentRow exposed automatically.  This being the case, you can probably use that instead of having LoopCounter.

--

Adam

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
Community Expert ,
Aug 28, 2009 Aug 28, 2009

Copy link to clipboard

Copied

Go to where the array is populated. Look at how the array's index is updated. You should find that the index isn't dynamically updated, starting from 1, but  instead has a static value. In any case, what you have given is not the relevant code.

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
Guest
Aug 29, 2009 Aug 29, 2009

Copy link to clipboard

Copied

Hey guys, thanks for the help.

The

server.AngelAPI.PlaceCallToAngel

call returns a structure with information about the results of that call. You give that function a number to call and some other revelent info, it calls an API linked to an automatic phone system, that system places the call and returns the unique ID (Called a GUID, hence the name GUIDArray) for that call and some other info. I assign that structure to the current element in the GUIDarray, then add a few more peices of info.

I do think the counter is getting incrimented, GUIDARRAY uses Loopcounter as an index, and that get incrimented every iteration. That example link I posted is a dumb of the original query that feeds the loop, and then the resulting array with containted structures. The array has the same number of elements as the query has rows, so the index counter is working there I beleive. Either way I will post the entire page when I get back to work on monday, and the contents of the function that it is calling (the PlaceCalltoAngel function).

Again, thats for the help.

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
Guest
Aug 29, 2009 Aug 29, 2009

Copy link to clipboard

Copied

Actually I was able to get a hold of the code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Angel IVR Call Placer</title>

    <script type="text/javascript"></script>
   
    <style type="text/css" title="currentStyle" media="screen">
        @import "http://scheduler.fpitesters.com/images/redirect/style.css";
    </style>
    <link rel="Shortcut Icon" type="image/x-icon" href="http://www.csszengarden.com/favicon.ico" />   
    <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.csszengarden.com/zengarden.xml" />
<link href="http://scheduler.fpitesters.com/Images/redirect/style2.css" rel="stylesheet" type="text/css" />
<cfsetting requestTimeOut = "500000">

<!--- Incoming url paramters --->
<cfparam name="url.studyid" type="string" default="701400000009Utu">
<cfparam name="url.numbertosend" type="string" default="500">
<cfparam name="url.AngelSite" type="string" default="100041">
<cfparam name="url.StartStatus" type="string" default="Not Dialed">
<cfparam name="url.EndStatus" type="string" default="Qualified">
<cfparam name="url.action" type="string" default="0">
<cfparam name="url.maxwaittime" type="numeric" default="5">
<cfparam name="url.batchsize" type="numeric" default="250">
<cfparam name="url.waittime" type="numeric" default="20">


<cfset email = "carlos.villalpando@foodperspectives.com">
<cfset pin = "Angel123">
           
<cfset BatchNumber = Randrange(1000000,99999999)>

<cfif isdefined("form.submit")>
    <cfset url.studyid = form.studyid>
    <cfset url.numbertosend = form.numbertosend>
    <cfset url.AngelSite = form.AngelSite>
    <cfset url.StartStatus = form.StartStatus>
    <cfset url.batchsize = form.batchsize>
    <cfset url.waittime = form.waittime>
    <cfset url.EndStatus = form.EndStatus>
    <cfset url.maxwaittime = form.maxwaittime>       
</cfif>

<!---
So the basic process is
1) Get a list of campaign members, based on study id, and the limit
2) From that list of campaign members, find the contacts information, including PID and Name
3) Update the campaign members so they don't get called again
4) Loop over that list of contacts and send an Angel Call for each one
5) Record the results of the call into the database for later review

--->

    <cfset Study = server.oSF.queryObject("SELECT Id,
                                               Project_Number__c                                       
                                            FROM Campaign WHERE
                                            RecordTypeID = '01240000000DiVD' and
                                            IsActive = True
                                            Order By Project_Number__c") />
                                           
<style type="text/css">
<!--
#QuoteDiv {
    position:relative;
    left:165px;
    top:95px;
    width:190px;
    height:77px;
    z-index:1;
    color:#000;
    font-weight:bold;
    font-size:14px;
}
-->
</style>
</head>

<body id="Taste Test Sign In">

<div id="container">
    <div id="intro">
        <div id="pageHeader">
            <cfoutput>
                <div id="QuoteDiv"><iframe src="getquote.cfm" width="200" height="150" scrolling="no"  frameborder="0"></iframe></div>
            </cfoutput>
            <h1><span></span></h1>
            <h2><span></span></h2>
        </div>

        <div id="quickSummary">
            <p class="p1"><span>Provided by <a href="http://fpitesters.com" target="_blank">FPI</a> </span></p>
            <p class="p2"><span>Provided by <a href="http://fpitesters.com" target="_blank">FPI</a> </span></p>
        </div>

        <div id="preamble">
            <p class="p1">
                <span>

                </span>
            </p>
        </div>
    </div>

    <div id="supportingText">
        <div id="explanation">
            <p class="p1">
                <span>
                       
                    <cfoutput>
                        <cftry>
                           
                       
                            <cfif url.action eq 0>
                   
                               
                               
                                <cfform name="AngelCallPlacerform" method="post" action="#cgi.scriptname#?action=1">
                                    <table cellpadding="5" cellspacing="5" width="300">
                                        <tr>
                                            <td colspan="2" align="center"><strong>Angel IVR Call Placer</strong></td>
                                        </tr>
                                        <tr>
                                            <td align="left" colspan="2">
                                                Configure the Parameters below to being placing calls for a study. You can also pass information in directly by including information in the url, setting the action to 1. <br />For example<br />
                                                http://webservices.fpitesters.com/AngelCalls.cfm?studyid=#url.studyID#&numbertosend=#url.numbertosend#&AngelSite=#url.angelsite#&StartStatus=#url.startstatus#&EndStatus=#url.endStatus#&action=1<br>
                                                <br />
                                            </td>
                                        </tr>
                       
                                        <tr>
                                            <td colspan="2" align="center">If you are getting stupid IVR errors, click <a href="../IVR/Relog.cfm" target="_blank">HERE</a>, then refresh the page</td>
                                        </tr>
                                       
                                        <tr>
                                            <td colspan="2" align="center"><strong>IVR Outbound Call Config</strong></td>
                                        </tr>
                                                       
                                        <tr>
                                            <td align="left">Master Study ID</td>
                                            <td>
                                                <cfselect class="formbox"name="StudyID" tooltip="Which Study to you wish to view?">
                                                    <option value="000" style="width:200;">--Select a Study--</option>
                                                    <cfloop query="Study.Results">
                                                   
                                                          <option value="#Study.Results.id#">#Study.Results.Project_Number__c#</option>
                                                    </cfloop>   
                                                </cfselect>       
                                                <cfinput name="ProjectName" type="hidden" bind="{StudyID.text}">                                   
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left">Number of Calls To Send Total</td>
                                            <td>
                                                <cfselect name="numbertosend" required="yes">
                                                    <cfloop from="500" to="20000" step="500" index="i">
                                                        <option value="#i#">#i# Calls Total</option>
                                                    </cfloop>
                                                </cfselect>

                                            </td>
                                        </tr>   
                                        <tr>
                                            <td align="left">Angel Site</td>
                                            <td>
                                                <cfselect name="AngelSite" required="yes">
                                                    <option value="100041">Regular Outbound</option>
                                                    <option value="100072">Reminder Calls</option>
                                                </cfselect>

                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left">Call Members With Status</td><td><cfinput name="StartStatus" required="yes" value="#url.StartStatus#" type="text"></td>
                                        </tr>   
                                        <tr>
                                            <td align="left">Set Member Status To</td><td><cfinput name="EndStatus" required="yes" value="#url.EndStatus#" type="text"></td>
                                        </tr>
                                        <tr>
                                            <td align="left">Batch Size</td>
                                            <td>
                                                <cfselect name="BatchSize" required="yes">
                                                    <cfloop from="200" to="2000" step="50" index="i">
                                                        <option value="#i#">#i# Calls Per Batch</option>
                                                    </cfloop>
                                                </cfselect>

                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left">Delay Between Batches (in minutes)</td><td><cfinput name="waittime" required="yes" value="#url.waittime#" type="text" validate="integer"></td>
                                        </tr>                                           
                                        <tr>
                                            <td align="left">Call Max Wait Time</td><td><cfinput name="maxwaittime" required="yes" value="#url.maxwaittime#" type="text"></td>
                                        </tr>                   
                                        <tr>
                                            <td colspan="2" align="center"><cfinput name="submit" value="submit" type="submit"></td>
                                        </tr>           
                                                   
                                    </table>
                                </cfform>
                               
                            </cfif>
                       
                            <cfif url.action eq 1>
                                <cfif datecompare(CreateODBCDateTime(NOW()),Server.AngelIVR.TokenExpirationDateTime, "n") GTE 0>
                                    NOW IS #CreateODBCDateTime(NOW())#<br />
                                    Relogin At #Server.AngelIVR.TokenExpirationDateTime#<br />
                                    <strong>Token Expired, Logging In Again</strong><br>
                                    <cfset server.AngelLogin =  server.AngelAPI.login()>
                                    Login Results: #server.AngelLogin.success#
                                </cfif>
                                <cfoutput>#repeatString(" ", 73729)#</cfoutput>
                               
                               
                                <!--- Step 1) Get list of Campaign Members --->
                                    <cfset CampaignMembers = server.AngelAPI.GetCampaignMemberData(url.studyid,url.StartStatus, url.numbertosend)>
                                   
                                    <cfif not IsQuery(CampaignMembers)>
               
                                            Could not find any respondents in #form.ProjectName# with status of #form.StartStatus#!<br><br />

                                            <cfif not fileexists("C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log")>
                                                <cffile action="write" file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" addnewline="yes" output="Log File Initilized at #timeformat(NOW())# on #dateformat(now())#. No Campaign Members Found To Call">
                                            </cfif>                                                   
                                            <cfabort>
                                           
                                            <cfelse>
                                                Found #CampaignMembers.RecordCount# People to Call<br><br />
                                                <cfflush>
                                                <cfif not fileexists("C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log")>
                                                    <cffile action="write" file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" addnewline="yes" output="Log File Initilized at #timeformat(NOW())# on #dateformat(now())#. Found #CampaignMembers.RecordCount# people to call">
                                                </cfif>                                                   
                                    </cfif>   
                                   

                                <!--- Step 2) Update the Campaign Members ---->   
                                    Updating Campaign Member Records...<br><br />
                                    <cfflush>
                                    <cfset UpdateResult = server.AngelAPI.MarkCampaignMemberssAscontacted(CampaignMembers,url.endstatus)>
                                    Updated #UpdateResult.Success# / #updateResult.TotalRecords# Campaign Member Records<br><br />
                               
                                <!--- Step 3) Loop over the results and place the calls --->
                               
                                    <cfset GuidArray = arraynew(1)>

                   
                                    <cfoutput>#repeatString(" ", 73729)#</cfoutput>
                                        Sending out calls. Please view the log file <a href="http://portal.fpitesters.com/Secure/Reports/IVRLogs/Calls_For_#url.studyid#.Log" target="_blank">HERE</a> for more details.<br><br />

                                        Waiting for #url.waittime# minute(s) between mailings (#form.waittime*60000# nanoseconds). Batch size of #form.batchsize#<br><br />
                                                   
                                        <cfset completetime = ((CampaignMembers.recordcount/form.batchsize) * form.waittime )- form.waittime>
                                        #CampaignMembers.recordcount# calls to send. Will take approximatly #completetime# minutes to complete (#timeformat(dateadd("n",completetime,now()))#). <br><br />

                                    <cfflush>       
                                   
                                    <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Starting Calling At #timeformat(now())#">   
                                   
                                    <cfset LoopCounter = 0>   
                                    <cfset maincounter = 1>
                                    <cfset batchcounter = 0>
                                   
                                    <cftry>
                                        <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="------------------------------------------------------------">
                                        <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Starting Batch #maincounter#">
                                       

                                        <cfloop query="CampaignMembers">
                                            <cfset LoopCounter = LoopCounter + 1>
                                            <cfset batchcounter = batchcounter + 1>
   
                                            <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Calling #Contact_IVRPHONE__c# At #timeformat(now())#">
   
                                            <cfset GuidArray[LoopCounter] = server.AngelAPI.PlaceCallToAngel(CampaignMembers.Contact_Name,CampaignMembers.Contact_PID__c,CampaignMembers.Contact_IVRPHONE__c,url.AngelSite,url.MaxWaitTime)>   
                                            <cfset GuidArray[LoopCounter].ContactID = CampaignMembers.Contact_ID>
                                            <cfset GuidArray[LoopCounter].CampaignMemberID = CampaignMembers.ID>
                                           
                                       
                                            <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Placed Call: GUID Is #GuidArray[LoopCounter].GUID#. Called #Contact_IVRPHONE__c#. Status is: #GuidArray[LoopCounter].Message#">
                                                                                   
                                            <cfif batchcounter EQ form.batchsize>                           
                                           
                                                <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Finished Batch #maincounter/url.batchsize# At #timeformat(now())#">
                                                <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="------------------------------------------------------------">
                                                <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="  ">

                                                <cfoutput>#repeatString(" ", 73729)#</cfoutput>
                                                <cfflush>
                                                                                       
                                                <cfif url.waittime GT 0 and maincounter LT CampaignMembers.RecordCount>
                                                    <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Started Waiting At #timeformat(now())#">
                                                    <CFTHREAD ACTION="SLEEP" DURATION="#url.waittime*60000#"></cfthread>
                                                    <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="  ">
                                                </cfif>   
                                                <cfset batchcounter = 0>
                                            </cfif>   
                                           
   
                                            <cfset maincounter = maincounter + 1>
                                        </cfloop>   
                                       
                                        <cfcatch type="any">
                                            An Error Occured. Please see the log for more details.
                                            #cfcatch.Message#<br />
                                            #cfcatch.Detail#<br />
                                            #cfcatch.Type#<br />
                                            <cfsavecontent variable="errordata">
                                                <cfmail to="lkeene@foodperspectives.com" from="Errors@foodperspectives.com" subject="IVR Call Placed for Study #url.studyid# Errored" type="html" MIMEAttach="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log">
                                                    An error occured while placing outbound calls. Below is the error data. The log of calls should be attached.
                                                    <cfdump var="#cfcatch#">
                                                </cfmail>
                                                <cfdump var="#cfcatch#" format="text">
                                            </cfsavecontent>
                                            <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="#errordata#">
                                        </cfcatch>
                                    </cftry>   
                                    <cffile file="C:\Website\Portal\Secure\Reports\IVRLogs\Calls_For_#url.studyid#.Log" action="append" addnewline="yes" output="Finished Placing Calls At #timeformat(now())#">               
                                   
                                <!--- Step 5) Records the Results of the calls into the database --->
                                    Logging Call Result Data to the Database..<br /><br />
                                    <cfflush>
                                    <cfloop from="1" to="#arraylen(GuidArray)#" index="i">
                                        <cfquery name="LogCallInit" datasource="#server.primaryDSN#">
                                            INSERT INTO IvrOutbound (CALLGUID,
                                                                     ContactID,
                                                                     CampaignMemberID,
                                                                     ContactPID,
                                                                     TimeOfCall,
                                                                     DateofCall,
                                                                     MasterStudyId,
                                                                     BatchNum,
                                                                     ProjectNumber)
                                                            VALUES('#GuidArray.GUID#',
                                                                   '#GuidArray.ContactID#',
                                                                   '#GuidArray.CampaignMemberID#',
                                                                    #GuidArray.PID#,
                                                                   '#timeformat(now())#',
                                                                   '#dateformat(now())#',
                                                                   '#url.studyid#',
                                                                   '#BatchNumber#',
                                                                   '#form.ProjectName#')
                                        </cfquery>   
                                    </cfloop>   
                               
                                                               
                                    <strong>All Calls have been placed!</strong><br><br />
                                    <br /><br />
                                    <center>
                                    <strong>When you are done with placing calls don't forget to run the</strong><br />
                                    <a href="http://portal.fpitesters.com/index.cfm?navcode=IVR/GetCallStatus.cfm">Call Status Backfiller</a>
                                    </center>
                            </cfif>           
                           
                            <cfcatch type="any">
                                Some Kind Of Error Occured
                                <cfdump var="#cfcatch#">

                                <cfmail to="lkeene@foodperspectives.com" from="Errors@foodperspectives.com" subject="IVR Call Placed for Study #url.studyid# Errored" type="html">
                                    An error occured while placing outbound calls. Below is the error data. The log of calls should be attached.
                                    <cfdump var="#cfcatch#">
                                </cfmail>                               
                            </cfcatch>
                       
                        </cftry>
                    </cfoutput>   
                </span>
            </p>
        </div>
    </div>
</div>


</body>
</html>

    <cffunction name="PlaceCallToAngel" returntype="struct" access="public" hint="I place a call using the Angel IVR System and return a call GUID">
        <cfargument name="ContactName" type="string" required="yes" hint="The name of the person being called">
        <cfargument name="ContactPID" type="string" required="yes" hint="The PID of the person being called">
        <cfargument name="PhoneNumber" type="string" required="yes" hint="The phone number to call">
        <cfargument name="AngelSite" type="string" required="yes" hint="The angel IVR site to use">
        <cfargument name="MaxWaitTime" type="string" required="yes" hint="The maximum amount of time to wait between calls">

        <cfset var PhoneNumberToCall = ReReplace(arguments.phonenumber, "[^0-9]", "", "ALL")>
       
        <cftry>
               
            <cfif datecompare(CreateODBCDateTime(NOW()),Server.AngelIVR.TokenExpirationDateTime, "n") GTE 0>
                <cfset server.AngelLogin =  server.AngelAPI.login()>
            </cfif>
                   
            <cfset VariablesArray = ArrayNew(1)>
                   
            <cfset Record1.Name = "callerName">
            <cfset Record1.Value = arguments.ContactName>
           
            <cfset Record2.Name = "callerPID">
            <cfset Record2.Value = arguments.ContactPID>
           
            <cfset ArrayAppend(VariablesArray,StructCopy(Record1))>
            <cfset ArrayAppend(VariablesArray,StructCopy(Record2))>
           
            <cfif isnumeric(PhoneNumberToCall) and len(PhoneNumberToCall) EQ 10>
               
                <!--- Build a call object --->
                <cfset CallItem = StructNew() > <!--- For Good Measure --->
                <cfset CallItem.maxWaitTime = arguments.maxwaittime >
                <cfset CallItem.phoneNumbers = arrayNew(1) /> <!--- Required --->
                <cfset CallItem.phoneNumbers[1] = PhoneNumberToCall>
                <cfset CallItem.siteNumber = arguments.AngelSite>
                <cfset CallItem.variables = VariablesArray>
                   
               
                <!--- Send the call object to the webservice --->
               
               
                <cfinvoke webservice="http://www.angel.com/outbound/wsdl/OutboundCallService.wsdl" method="placeCall" returnvariable="placecall">
                    <cfinvokeargument name="Token" value="#server.AngelLogin.Token#"/>
                    <cfinvokeargument name="CallItem" value="#CallItem#"/>
                </cfinvoke>
               
                <cfset callReturn.GUID = placecall[1].getOutboundCallGUID()>
                <cfset callReturn.NumberDialed = PhoneNumberToCall>
                <cfset callReturn.PID = arguments.ContactPID>
                <cfset callReturn.message = "Call Placed Successfully">
       
                <cfelse>
                    <cfset callReturn.GUID = 000000000000>
                    <cfset callReturn.NumberDialed = PhoneNumberToCall>
                    <cfset callReturn.PID = arguments.ContactPID>
                    <cfset callReturn.message = "Invalid phone number">       
            </cfif>
           
            <cfcatch type="any">
                    <cfset callReturn.GUID = 000000000000>
                    <cfset callReturn.NumberDialed = PhoneNumberToCall>
                    <cfset callReturn.PID = arguments.ContactPID>
                    <cfset callReturn.message = cfcatch.message & " " & ctcatch.detail>               
            </cfcatch>
        </cftry>   
        <cfreturn callReturn>
    </cffunction>

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
Explorer ,
Sep 10, 2009 Sep 10, 2009

Copy link to clipboard

Copied

The code as shown should work corectly, assuming:

1) <cfset CampaignMembers = server.AngelAPI.GetCampaignMemberData(url.studyid,url.StartStatus, url.numbertosend)>

returns correct query

2) <cfset UpdateResult = server.AngelAPI.MarkCampaignMemberssAscontacted(CampaignMembers,url.endstatus)>

does NOT change the query object in unexpected way...

Every time the query fields are accessed without [rownumber] (i.e. CampaignMembers.ID instead of CampaignMembers.ID[1..RecordCount] the behaviour may be NOT what you expect:

<set value = CampaignMembers.ID />

will get you a value of the field in current row if accessed within <cfoutput> tag, but will get you a value of the field in FIRST row if accessed within <cfloop> tag

QuerySetCell(query, column_name, value) [without rownumber]

will set value for LAST row ONLY [AFAIR]

So it is always better to add rownumber after your Query.FieldName[Query.CurrentRow]

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
Guest
Sep 14, 2009 Sep 14, 2009

Copy link to clipboard

Copied

Thanks for your reply. I think i understand what you are saying, but how would I apply that change to  my code? Sorry, I just don't quite know where I need to place that update. My brain is kinda fried.

My other though is to have the logging just be a sub function of the call placment. So instead of placing all calls then logging all calls, it places a call and logs it, places a call and logs it, etc. Thoughts on that approach?

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
Explorer ,
Sep 15, 2009 Sep 15, 2009

Copy link to clipboard

Copied

LATEST

Replace all references to query fields inside

<cfloop query="CampaignMembers">

from

CampaignMembers.fieldName

to

CampaignMembers.fieldName[CampaignMembers.CurrentRow]

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