Reputation: 354
I wrote a cfc to handle all of the functions for one aspect of a project. I typically write in tags but chose to learn something new so I wrote it in script. All my workup and testing was done on a CommandBox running Lucee for quick spin up and a dev environment. It worked like a charm. Now when I uploaded it to our production server running ACF 8 it will not read any of the file. I navigate to the address of the cfc and where it would typically display the functions that are accessible I get the code in a paragraph.
Before I rewrite this in tags I want to make sure that it is a compatibility issue with ACF 8 and not my code and/or any work a rounds. Please do not hammer me for not using params.
Here is my code:
component {
DSN = 'xxxx';
public function init(){
}
remote function BranchContact(MainContactID, BranchOfContactID, UserID) returnformat="plain"{
data = IsBranch(BranchOfContactID);
if(data.branchTotal == 0){
// result = 'no branches';
result = InsertBranch(MainContactID, BranchOfContactID, UserID);
//WriteBranchingHistory(MainContactID, BranchOfContactID, UserID);
result = 1;
}
else{
// message = 'It appears that you are branching to an account is already a branch - from component';
queryString = 'Select top 1 ParentCID from branches where ChildCID =' & BranchOfContactID;
data = RunQuery(queryString);
result = data.ParentCID;
}
return result;
}
private function IsBranch(BranchOfContactID){
queryString = 'Select count(*) as branchTotal from branches where ChildCID = ' & BranchOfContactID;
RunQuery(queryString);
return data;
}
private function InsertBranch(ParentCID, ChildCID, UserID){
// try{
queryString = 'Insert into Branches (ParentCID, ChildCID, UserID) values (' & ChildCID & ', ' & ParentCID & ', '& UserID & ')';
data = RunQuery(queryString);
//WriteBranchingHistory(MainContactID, BranchOfContactID, UserID);
//need to write the branching history to the contact history table so that is can be tracked
contactResultsID = 102;
note = 'Account branched to - ' & ChildCID;
quotedNote = ''''¬e&'''';
activityType = 'Branched';
quotedActivity = ''''&activityType&'''';
campaignID = 0;
today = 'getdate()';
AddContactHistory(ParentCID, today, contactresultsID, UserID, quotedActivity, quotedNote, campaignID);
//return history;
return data;
// }
// catch(e){
// errorMessage = 'While trying to branch account';
// message = error(errorMessage);
// return message;
// }
}
remote function Delete(ChildCID, UserID) returnformat="plain"{
// try{
//have to use a query to get the parentcid since it will be empty when the ajax query is triggered
Parent = GetParent(ChildCID);
queryString = 'Delete from branches where ChildCID = ' & ChildCID;
data = RunQuery(queryString);
//WriteBranchingHistory(MainContactID, BranchOfContactID, UserID)
contactResultsID = 103;
note = 'Account unbranched from - ' & Parent.parentCID;
quotedNote = ''''¬e&'''';
activityType = 'Removed Branch';
quotedActivity = ''''&activityType&'''';
campaignID = 0;
today = 'getdate()';
AddContactHistory(ChildCID, today, contactresultsID, UserID, quotedActivity, quotedNote, campaignID);
return data;
// }
// catch(e){
// errorMessage = 'While trying to delete branching';
// message = error(errorMessage);
// return e;
// }
}
private function Update(){
}
<!--- WriteBranchHistory has not been completed
public function WriteBranchingHistory(MainContactID, BranchOfContactID, UserID) returnformat="plain"{
try{
queryString = 'insert into BranchHistory(contactID, ChildContactID, UserID, InsertDate) values
('& MainContactiD &', '& BranchContactID & ', ' & UserID & ', getdate());';
data = RunQuery(queryString);
// return data;
//oldMar = GetOldMar(MainContactID);
// writeDump(oldMar);
// writeDump(queryString);
//return oldMar;
}
catch(e){
errorMessage = 'While trying to add branch history';
message = error(errorMessage);
return message;
}
}
--->
public function GetParent(ChildCID) returnformat="html"{
queryString = 'Select top 1 parentCID from branches where childCID = ' & ChildCID;
data = RunQuery(queryString);
return data;
}
public function GetUserInfo(userid){
myQuery = new Query();
myQuery.addParam(name="userid", value=userid, cfsqltype="cf_sql_numeric");
myQuery.setDataSource(DSN);
myQuery.setSQL('select * from users where userid = :userid');
data = myQuery.execute().getResult();
return data;
}
private function RunQuery(queryString){
myQuery = new Query();
// myQuery.addParam(name="ContactID", value=ContactID, cfsqltype="cf_sql_numeric");
myQuery.setDataSource(DSN);
myQuery.setSQL(queryString);
data = myQuery.execute().getResult();
return data;
}
private function error(errorMessage){
message = "Oops something went wrong <br/>" & errorMessage;
return message;
}
private function AddContactHistory(ParentCID, today, contactresultsID, UserID, quotedActivity, quotedNote, campaignID) {
InsertHistoryString = 'insert into contacthistory (contactid, historydate, contactresultID, userid, activitytype, note, campaignID) values
('&ParentCID& ', ' &today& ', ' &contactresultsID& ', ' &UserID& ', ' "edActivity& ', ' "edNote& ', ' &CampaignID& ');';
InsertHistory = RunQuery(InsertHistoryString);
}
}
Upvotes: 1
Views: 114
Reputation: 1509
component
was not supported in cfscript until CF9, so yes, this is a compatibility issue.
Pete Freitag on his blog has a good cheatsheet for cfscript compatability, linked here: https://www.petefreitag.com/cheatsheets/coldfusion/cfscript/
Upvotes: 4