Question
Value from CFC using cfscript
I've got a function in a CFC that inserts a parent value into
an Oracle table (see below). I want to extend the function to
return the new parent ID so that I can use it to insert the child
values. I'm using <cfscript> to execute the function which
works fine with the data insert, but I can't quite work out how to
output the new parent ID value in <cfscript>. Any help
appreciated.
Thanks in advance
Roy.
<cffunction name="insertApp" hint="Insert Applications" returntype="query">
<cftry>
<!--- Insert Values --->
<cfquery name="qryAppInsert" username='#this.uid#' password='#this.pwd#' datasource='#this.source#'>
INSERT INTO
impsapp.tblAPPLICATIONS
VALUES
(#this.ID#, '#this.dType#', TO_DATE('#this.cDate#','dd-mon-yyyy'))
</cfquery>
<!--- Select current Value form DUAL --->
<cfquery name="qryNewSeq" username='#this.uid#' password='#this.pwd#' datasource='#this.source#'>
SELECT impsapp.Test_SEQ.currval x FROM dual
</cfquery>
<cfcatch type="any">
<cfreturn "Error in Function insertApp">
</cfcatch>
</cftry>
<!--- Return Query --->
<cfreturn qryNewSeq>
</cffunction>
<cfscript>
// create componet object
comTest = createObject("component", "cfc.Test");
// Set the properties from Form
comTest.uid = '#myUser#';
comTest.pwd = '#myPasswd#';
comTest.source = '#myDS#';
comTest.holder= #Form.eID#;
comTest.appType = '#Form.pType#';
comTest.recDate = '#DateFormat("#Form.dateReq#", "dd/mmm/yyyy")#';
//Call insert finction
apply_Card.insertApplications();
//I need to be able to output and use the value x from the qryNewSeq above
</cfscript>
Thanks in advance
Roy.
<cffunction name="insertApp" hint="Insert Applications" returntype="query">
<cftry>
<!--- Insert Values --->
<cfquery name="qryAppInsert" username='#this.uid#' password='#this.pwd#' datasource='#this.source#'>
INSERT INTO
impsapp.tblAPPLICATIONS
VALUES
(#this.ID#, '#this.dType#', TO_DATE('#this.cDate#','dd-mon-yyyy'))
</cfquery>
<!--- Select current Value form DUAL --->
<cfquery name="qryNewSeq" username='#this.uid#' password='#this.pwd#' datasource='#this.source#'>
SELECT impsapp.Test_SEQ.currval x FROM dual
</cfquery>
<cfcatch type="any">
<cfreturn "Error in Function insertApp">
</cfcatch>
</cftry>
<!--- Return Query --->
<cfreturn qryNewSeq>
</cffunction>
<cfscript>
// create componet object
comTest = createObject("component", "cfc.Test");
// Set the properties from Form
comTest.uid = '#myUser#';
comTest.pwd = '#myPasswd#';
comTest.source = '#myDS#';
comTest.holder= #Form.eID#;
comTest.appType = '#Form.pType#';
comTest.recDate = '#DateFormat("#Form.dateReq#", "dd/mmm/yyyy")#';
//Call insert finction
apply_Card.insertApplications();
//I need to be able to output and use the value x from the qryNewSeq above
</cfscript>
