Guest User

Untitled

a guest
Jul 2nd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cffunction name="updateCompoundWithNonPK" returntype="void" access="public" output="false" hint="I update a relation table that has a non-PK field">
  2.     <cfargument name="Tablename" type="string" required="true">
  3.     <cfargument name="CompoundPivotField" type="string" required="true">
  4.     <cfargument name="CompoundPivotValue" type="string" required="true">
  5.     <cfargument name="CompoundMultiField" type="string" required="true">
  6.     <cfargument name="CompoundMultiValue" type="string" required="true">
  7.     <cfargument name="NonPKField" type="string" required="true">
  8.     <cfargument name="NonPKValue" type="string" required="true">
  9.    
  10.     <cfset var sUpdate = StructNew()>
  11.     <cfset var sExisting = StructNew()>
  12.     <cfset var ExistingList = "">
  13.     <cfset var qExistingRecords = 0>
  14.     <cfset var IncomingCompoundMultiValue = arguments.CompoundMultiValue>
  15.    
  16.     <cfset var debugoutput = "">
  17.  
  18.     <!--- First, handle the list relation update --->
  19.     <cfset sExisting[CompoundPivotField] = CompoundPivotValue>
  20.     <cfset qExistingRecords = getRecords(tablename=arguments.Tablename,data=sExisting)>
  21.  
  22.     <cfif qExistingRecords.RecordCount>
  23.         <cfoutput query="qExistingRecords">
  24.             <cfset ExistingList = ListAppend(ExistingList,qExistingRecords[arguments.CompoundMultiField][CurrentRow])>
  25.         </cfoutput>
  26.         <cfset arguments.CompoundMultiValue = ListAppend(arguments.CompoundMultiValue,ExistingList)>
  27.     </cfif>
  28.     <cfif arguments.tablename EQ "cfsTopicsMandatory2Locations" AND qExistingRecords.RecordCount>
  29.         <cffile action="append" file="/home/timd/git/cfs-new/f/ajax/debug.cfm" output="Called at #now()#. ">
  30.     </cfif>
  31.    
  32.     <cftry>
  33.     <cfset saveRelationList(arguments.Tablename,arguments.CompoundPivotField,arguments.CompoundPivotValue,arguments.CompoundMultiField,arguments.CompoundMultiValue)>
  34.     <cfcatch>
  35.         <cfsavecontent variable="debugoutput">
  36.             <cfdump var="#cfcatch#">
  37.         </cfsavecontent>
  38.         <cffile action="append" file="/home/timd/git/cfs-new/f/ajax/debug.cfm" output="ERROR:Called at #now()#.<br>#debugoutput#">
  39.     </cfcatch>
  40.     </cftry>
  41.    
  42.     <!--- Now, we can do a simple save to add the non-PK value --->
  43.     <cfset sUpdate[arguments.CompoundPivotField] = arguments.CompoundPivotValue>
  44.     <cfset sUpdate[arguments.CompoundMultiField] = IncomingCompoundMultiValue>
  45.     <cfset sUpdate[arguments.NonPKField] = arguments.NonPKValue>
  46.     <cfset saveRecord(tablename=arguments.Tablename,data=sUpdate)>
  47.    
  48. </cffunction>
Add Comment
Please, Sign In to add comment