Gregory's Blog

Using a dynamic variable to set a dynamic path variable when dropping a cookie

ColdFusion sometimes drives me a bit wonky when I try to set a dynamic variable inside a tag. Most ColdFusion tags support embedded dynamic variables, but quite a few tags don't support this. Probably the most frustrating issue is when you want to use a dynamic variable to extend an application in a sub-folder using two or more application.cfc templates. It seems that every other time I do this I slap my head and think 'Oops! it's time to set up proxy extensions', sigh... but this frustrating issue requires a very long blog entry for a different day. Back to my point...

If you try to use a dynamic variable using a cfcookie tag, you will get the following nasty error:

view plain about
1<cfcookie name="isAdmin" value="true" path="#application.baseUrl#" expires="never">

Attribute validation error for tag CFCOOKIE. It has an invalid attribute combination: expires,name,path,value. Possible combinations are: Required attributes: 'name'. Optional attributes: 'domain,encodevalue,expires,httponly,preservecase,secure,value'. Required attributes: 'domain,name,path'. Optional attributes: 'encodevalue,expires,httponly,preservecase,secure,value'.

To get around this, simply use the cookie scope instead in order to set the dynamic path value.

view plain about
1<!--- Using the cfcookie tag does not work with dynamic vars in the path. --->
2<cfset cookie.isAdmin = { value="true", path="#application.baseUrl#", expires=30 }>

Both cfcookie and the cookie scope do the same thing, send a cookie to the client, but at least the cookie scope allows you to embed dynamic variables for in the path name.

This entry was posted on June 28, 2019 at 12:11 PM and has received 304 views.

There are currently 0 comments. Download attachment.

ColdFusion error: "The current user is not authorized to invoke this method."

I wanted to document this as this error is not often found using google, but if you receive a ColdFusion error "The current user is not authorized to invoke this method.", it could be due to using the roles attribute in a cfffunction tag that don't match the roles that you set using the cflogin tag upon successful login.

I received this error when converting the original application.cfm tag in BlogCfc to use an application.cfc instead. During the conversion processes, I noticed that there was a 'roles' argument on the cffunction that did not match up with the new role that I had just programmed in the cflogin logic. When I searched for this error, I found a bunch of errors relating to using ColdFusions built in administrative user interface, and could not find that it was due to the role restrictions on the cffunction tag and thought to document it. It is a relatively intuitive error, but I am surprised that Adobe did not elaborate and write something like 'The role on the function does not match the cflogin role'. ColdFusion has always been good at that.

If you receive this error, check the roles attributes that you have used. It will likely fix the problem.

This entry was posted on June 2, 2019 at 2:32 PM and has received 342 views.

There are currently 0 comments. Download attachment.

Shorthand struct return

There are many ways to return multiple values from a cfc. Typically we return a query object, a json string, an array, or a structure, but one of my favorite ways to return multiple bits of data is using a shorthand structure. It is much easier and intuitive to use on both the back and front end than using an array. Here is a simple example:

Cfc:

view plain about
1<!--- There are two types of routing titles. The original design used an routing title that was used to populate a contract and this title was not the official title, but something more generic that was easily identifiable on a written contract. The other title is the official title that is coming from the workday database We will use the original routing title if the user was assigned a routing title that is found in the routing database, otherwise, we will use the official workday title. --->
2 <cffunction name="getTitleByEmail" access="remote" returntype="struct" hint="Determines the approver title. This will be either the routing title that was used in previous contracts, or the official title found in workday. We need to return multiple values, so this returns a one dimension array instead of a string.">
3 <cfargument name="email" type="string" required="yes" hint="Supply the email.">
4
5 <cfparam name="title" default="">
6
7 <!---Format the email--->
8 <cfinvoke component="#WorkdayUsersObj#" method="formatUwEmail" returnvariable="uwEmail">
9     <cfinvokeargument name="email" value="#arguments.email#">
10        </cfinvoke>
11
12 <!--- Query the Approval database to see if the title exists. --->
13 <cfquery name="approvalTitle" datasource="Contracts">
14     SELECT TOP (1)
15                ApproverTitle
16                FROM dbo.Approval
17                WHERE (Email = <cfqueryparam value="#uwEmail#" cfsqltype="cf_sql_varchar">)
18 </cfquery>
19 <!---Set the ApproverTitle--->
20 <cfset ApproverTitle = approvalTitle.ApproverTitle>
21         <!---Get the workday job title. --->
22         <cfinvoke component="#WorkdayUsersObj#" method="getEmployeeJobTitle" returnvariable="workdayTitle">
23            <cfinvokeargument name="email" value="#email#">
24         </cfinvoke>
25
26 <!---Build the shorthand struct --->
27 <cfset titleStruct = {workdayTitle = #workdayTitle#, ApproverTitle = #ApproverTitle#}>
28
29 <cfreturn titleStruct>
30
31 </cffunction>

On the client side, simply use the following to output the value:

view plain about
1<cfset thisRoutingTitle = getTitleByEmail(thisApproverEmail).ApproverTitle>
2<cfset thisWorkdayTitle = getTitleByEmail(thisApproverEmail).WorkdayTitle>

This entry was posted on December 14, 2018 at 12:34 PM and has received 102 views.

There are currently 0 comments.

Localization Support Dropped

I am going to forgo using Raymond's localization support for this version. To incorporate a few languages, Raymond uses the resourceBundle.cfc template that was originally coded by Paul Hastings. I believe that it supports two variants Dutch and German languages, along with English of course. Raymond labels his buttons and text messages in the different languages in 4 different .properties files, and uses the 'rb('message var') function to display the text and messages. I have decided not to incorporate the localization as I can't translate between English and the other languages, and this blog is also intended to be a living example how to use Kendo with ColdFusion. Using 'rb('pleaseWait') in my code will be confusing to the reader wanting to know how I am using ColdFusion and Kendo. It is much easier to read:

view plain about
1'$.when(kendo.ui.ExtWaitDialog.show({ title: "Please wait...", message: "Searching.", icon: "k-ext-information" }));'
than
view plain about
1'$.when(kendo.ui.ExtWaitDialog.show({ title: "<cfoutput>#rb(pleaseWait)#</cfoutput>", message: "<cfoutput>#rb(searching)#</cfoutput>", icon: "k-ext-information" }));'
for example. In one of the next versions, if someone wants to assist me in translating the English into the supported languages, I may revisit this decision and incorporate localization into the code.

This entry was posted on December 8, 2018 at 11:15 PM and has received 125 views.

There are currently 0 comments.




Footer Logo

Your input and contributions are welcomed!

If you have an idea, BlogCfc based code, or a theme that you have built using this site that you want to share, please contribute by making a post here or share it by contacting us! This community can only thrive if we continue to work together.

Images and Photography:

Gregory Alexander either owns the copyright, or has the rights to use, all images and photographs on the site. If an image is not part of the "Galaxie Blog" open sourced distribution package, and instead is part of a personal blog post or a comment, please contact us and the author of the post or comment to obtain permission if you would like to use a personal image or photograph found on this site.

Credits:

Portions of Galaxie Blog are powered on the server side by BlogCfc, an open source blog developed by Raymond Camden. Revitalizing BlogCfc was a part of my orginal inspiration that prompted me to design this site. Some of the major open source contributers to BlogCfc include:

  1. Peter Farrell: the author of 'Lyla Captcha' that is used on this blog.
  2. Pete Freitag: the author of the 'ColdFish' code formatter that is also used on this blog.

Version:

Galaxie Blog Version 1.35 September 6 2019