Skip to main content
Known Participant
August 10, 2010
Question

cfcomponent & cfscript

  • August 10, 2010
  • 1 reply
  • 1748 views

I found a UDF that is very useful for my web app. But the UDF is written in cfscript

I want to create a component and put this UDF inside since I'm sure in the future I will be using a lot of this function. So anytime I need this function I can just call using cfinvoke

Usually I use cfinvoke to call my component this way:

<cfinvoke component="#Location#" method="MyFunction" st_MyStuct ="#st_MyStuct#" MyList = "#MyList#">

Then in the CFComponent I have something like:

<cfcomponent

displayname="NameCheckSystem" hint="">

  

     <CFFUNCTION

name="CheckAddresses">

         <cfargument name="st_MyStruct" type="Structure" required="true">

         <cfargument name="MyList" type="String" required="true">

         .....etc

     </CFFUNCTION>

</cfcomponent>

Since this UDF is written in cfscript, I'm not sure how is the right syntax to pass the arguments.

<cfcomponent

displayname="NameCheckSystem" hint="">

<!--- below is the original cfscript codes --->

<cfscript>

function ListUnion(List1, List2)

{

var TempList = "";

var CombinedList = "";

Var SortType="text";

Var SortOrder="asc";

var Delim1 = ",";

var Delim2 = ",";

var Delim3 = ",";

var i = 0;

// Handle optional arguments

switch(ArrayLen(arguments)) {

case 3:

{

Delim1 = Arguments[

3];

break;

}

case 4:

{

Delim1 = Arguments[

3];

Delim2 = Arguments[

4];

break;

}

case 5:

{

Delim1 = Arguments[

3];

Delim2 = Arguments[

4];

Delim3 = Arguments[

5];

break;

}

case 6:

{

Delim1 = Arguments[

3];

Delim2 = Arguments[

4];

Delim3 = Arguments[

5];

SortType = Arguments[

6];

break;

}

case 7:

{

Delim1 = Arguments[

3];

Delim2 = Arguments[

4];

Delim3 = Arguments[

5];

SortType = Arguments[

6];

SortOrder = Arguments[

7];

break;

}

}

// Combine list 1 and list 2 with the proper delimiter

CombinedList =

ListChangeDelims(List1, Delim3, Delim1) & Delim3 & ListChangeDelims(List2, Delim3, Delim2);

// Strip duplicates if indicated

for (i=1; i LTE ListLen(CombinedList, Delim3); i=i+1) {

if (NOT ListFindNoCase(TempList, ListGetAt(CombinedList, i, Delim3), Delim3)){

TempList =

ListAppend(TempList, ListGetAt(CombinedList, i, Delim3), Delim3);

}

}

Return ListSort(TempList, SortType, SortOrder, Delim3);

}

</cfscript>

</cfcomponent>

This topic has been closed for replies.

1 reply

Inspiring
August 10, 2010

Same as you normally would.  The argument names are list1 & list2.

--

Adam

aleckenAuthor
Known Participant
August 10, 2010

But I can't use cf tags inside cfscript am I right?

<cfscript>

     <cfargument name="List2" type="String" required="true">

     <cfargument name="List2" type="String" required="true">

    I thought this not allowed????

</cfscript>

Inspiring
August 10, 2010

You don't need <cfargument> tags.  You don't need to modify the UDF code at all.  You asked how to CALL the UDF: you call it exactly the same way you would any other function, be it a built-in CF function or a CFML-written one.

<cfset someVar = myFunction(arg1, arg2, [etc)>

Or similarly with <cfinvoke> if you want to.  There is no difference in how you call it at all.

--

Adam