Skip to main content
imam_vengeance
Participant
June 11, 2015
Question

validation cfinvoke

  • June 11, 2015
  • 1 reply
  • 474 views

The database queries I had at the top of the page were moved into a CFC and now it is taking noticeable amount of time in displaying the data. how to make data entry validation that does not happen inconsistency.

Ex :

1. AddItem.cfm

<cfinvoke component="#Application.ComponentPath#.inventory.Stock"

            method="qtymin"

            datasource ="#iif(isDefined('DSN'),'DSN','Attributes.DSN')#"

            itemcode="#varItemCode#"

            trans_date="#createodbcdate(qhead.whtreqdate)#"

            trans_type="STF"

            qty="#QTY#"

            qtyrr="#QTY#"

            qtysn="#QTY#" 

            qtyprod="#QTY#" 

            unitprice="0"

            currencyunit="#COOKIE.currencyid#"

            docno="#whtreqnum#"

            lstbin="#evaluate('lstBinQty#idx#')#"

            whid="#COOKIE.LOCATION_ID#"

            companyid="#cookie.companyID#"

>

2. Stock.cfc

<cffunction name="qtymin" access="public" output="yes">

        <cfargument name="datasource" type ="string" required="true" default="#REQUEST.DSN#" />

        <cfargument name="itemcode" type="string" required="true" default=""/>

        <cfargument name="trans_date" type="date" required="true" default=""/>

        <cfargument name="trans_type" type="string" required="true" default=""/>

        <cfargument name="qty" type="numeric" required="true" default=0/>

        <cfargument name="qtyrr" type="numeric" required="true" default=0/>

        <cfargument name="qtysn" type="numeric" required="true" default=0/>

        <cfargument name="qtyprod" type="numeric" required="true" default=0/>

        <cfargument name="currencyunit" type="string" required="true" default=""/>

        <cfargument name="docno" type="string" required="true" default=""/>

        <cfargument name="lstbin" type="string" required="true" default=""/>

        <cfargument name="whid" type="string" required="true" default=""/>

        <cfargument name="companyid" type="string" required="true" default=""/>

        <cfargument name="reason" type="string" required="true" default=""/>

<cfquery name="qavailableitem" datasource="#datasource#">

            --------------SELECT-------------------------------

        </cfquery>

        <cfif qavailableitem.recordcount gt 1 and qavailableitem.item_qty gt 0>

            <cfif qavailableitem.item_qty lt qty>

                <cfquery name="qUpdateavailableitem1" datasource="#datasource#">

                   --------------------------UPDATE--------------------------------

                </cfquery>

                <cfquery name="qUpdateavailableitem2" datasource="#datasource#">

                   ------------------------------------------UPDATE-------------------------------

                </cfquery>

            </cfif>

            <cfquery name="qavailableitem" datasource="#datasource#">

              ----------------------------------SELECT-----------------------------

            </cfquery>

            <cfquery name="qavailableitem" dbtype="query">

               ------------------------INSERT---------------------

            </cfquery>

        </cfif>

</cffunction>

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    June 13, 2015

    There is something odd about the line <cfif qavailableitem.recordcount gt 1 and qavailableitem.item_qty gt 0>. If the recordcount is greater than 1 then there will be more than 1 value of qavailableitem.item_qty. Which one will you then be comparing with 0?

    Perhaps even more importantly, your component is doing too much. Functions should in general not display anything. Also, you could improve the design of your code by dividing the responsibility among several functions.

    Something like this:

    1. AddItem.cfm

    <cfinvoke component="#Application.ComponentPath#.inventory.Stock"

                method="qtymin"

            returnVariable="qavailableitem"

                datasource="#iif(isDefined('DSN'),'DSN','Attributes.DSN')#"

                itemcode="#varItemCode#"

                trans_date="#createodbcdate(qhead.whtreqdate)#"

                trans_type="STF"

                qty="#QTY#"

                qtyrr="#QTY#"

                qtysn="#QTY#"

                qtyprod="#QTY#"

                unitprice="0"

                currencyunit="#COOKIE.currencyid#"

                docno="#whtreqnum#"

                lstbin="#evaluate('lstBinQty#idx#')#"

                whid="#COOKIE.LOCATION_ID#"

                companyid="#cookie.companyID#"

    >

    <cfif qavailableitem.recordcount gt 1 and qavailableitem.item_qty gt 0>

        <!--- perform update query --->

        <cfif qavailableitem.item_qty lt qty>

            <cfinvoke component="#Application.ComponentPath#.inventory.Stock"

                      method="doUpdate"

              ...

                   >     

        </cfif>

        <!--- perform another select query --->

        <cfinvoke component="#Application.ComponentPath#.inventory.Stock"

                method="qtymin"

                ...

            >

         <!--- perform insert query --->

        <cfinvoke component="#Application.ComponentPath#.inventory.Stock"

                method="doInsert"

                ...

            > 

    </cfif>

    2. Stock.cfc

    <cffunction name="qtymin" access="public" output="no" returntype="query">

            <cfargument name="datasource" type ="string" required="true" default="#REQUEST.DSN#" />

            <cfargument name="itemcode" type="string" required="true" default=""/>

            <cfargument name="trans_date" type="date" required="true" default=""/>

            <cfargument name="trans_type" type="string" required="true" default=""/>

            <cfargument name="qty" type="numeric" required="true" default=0/>

            <cfargument name="qtyrr" type="numeric" required="true" default=0/>

            <cfargument name="qtysn" type="numeric" required="true" default=0/>

            <cfargument name="qtyprod" type="numeric" required="true" default=0/>

            <cfargument name="currencyunit" type="string" required="true" default=""/>

            <cfargument name="docno" type="string" required="true" default=""/>

            <cfargument name="lstbin" type="string" required="true" default=""/>

            <cfargument name="whid" type="string" required="true" default=""/>

            <cfargument name="companyid" type="string" required="true" default=""/>

            <cfargument name="reason" type="string" required="true" default=""/>

       

        <!--- Result-set to be returned defined as function-local variable

        <cfset var localResultSet = "">

        <cfquery name="localResultSet" datasource="#datasource#">

                --------------SELECT-------------------------------

            </cfquery>

            <cfreturn localResultSet>

    </cffunction>

    <cffunction name="doUpdate" access="public" output="no" returntype="void">

        <!--- more code --->

         <cfquery name="qUpdateavailableitem2" datasource="#datasource#">

               ------------------------------------------UPDATE-------------------------------

            </cfquery>

    </cffunction>

    <cffunction name="doInsert" access="public" output="no" returntype="void">

        <!--- more code --->

         <cfquery name="qavailableitem" dbtype="query">

                   ------------------------INSERT---------------------

            </cfquery>

    </cffunction>

    imam_vengeance
    Participant
    June 13, 2015

    Thx BKBK..

    to use <cftry> <cfcatch> whether it can be used here, and if in use how do I apply..?

    BKBK
    Community Expert
    Community Expert
    June 13, 2015

    For example:

    addItem.cfm

    <!--- At very top of page --->

    <cftry>

    ...

    ...

    <!--- At very bottom of page --->

    <cfcatch type="any">

    <cfdump var="#cfcatch#">

    </cfcatch>

    </cftry>

    You would, of course, do this in development code, not in production code.