Creating a Custom Function

Sherry Collins asked on June 2, 2015 20:49

I have a need to create a custom transformation.

I found an article https://docs.kentico.com/display/K8/Adding+custom+methods+to+transformations that explained how to do this. I followed the instructions to the letter and I am not able to call my function from the transformation.

Path to my customfunction = CMSApp_Appcode\Old_App_Code\CMSTransformationMethods\CMSTransformation.cs

I have a public method and here is the signature:

namespace CMSAppAppCode.Old_App_Code.CMSTransformationMethods { public class CMSTransformation {

    public int GetBlogLikesCount(int DocumentID)

One thing I took the default namespace because the KB article said to use CMS.Controls and I think because they were showing how to manipulate a textbox control.

It could be as simple as me using the wrong namespace maybe?

Anyway here is my call to the method from my transformation.

<br><span id="newlikes" data-currentuser="<%# BlogFunctions.GetUserName(Eval("NodeOwner")) %>" data-blogposttitle="<%# Eval("DocumentID")%>"><a href="#"><%#GetBlogLikesCount(Eval("DocumentID"))%> Likes</a></span></div>

Here is the complete error:

[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=2819f47b-7d66-4115-91f8-811086a7ed82/IntranetPortal.Transformations/BlogPostDetail_KeepingTrac---showeditdelete-0.ascx(19): error CS0103: The name 'GetBlogLikesCount' does not exist in the current context

Can someone please help me.

Thanks.

Correct Answer

Sherry Collins answered on June 3, 2015 18:53

It turned out that I needed to put my custom function in the Old_App_Code folder as the KB article stated. The namespace needed to be CMS.Controls. Once I went back and implemented it as the instructions said, the error went away.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Charles Matvchuk answered on June 2, 2015 21:37 (last edited on June 2, 2015 21:38)

="#"><%# CMSTransformation.GetBlogLikesCount(Eval("DocumentID"))%> Are you using a Web App or Web Site structure. If you are using website Put it in your App_Code Folder in its own namespace.

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on June 2, 2015 21:40

How can I tell which one. I didn't install this.

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on June 2, 2015 21:47

Just verified this is a webapplication structure.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 2, 2015 21:49

You need to fully qualify the call to the method. Try CMSTransformation.GetBlogLikesCount

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on June 2, 2015 21:55

Tried that and I get this error:

[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=14610e5d-4899-4ddf-822e-fa23bc7eefaf/IntranetPortal.Transformations/BlogPostDetail_KeepingTrac---showeditdelete-0.ascx(19): error CS0117: 'CMS.Controls.CMSTransformation' does not contain a definition for 'GetBlogLikesCount'

Here is the transformation:

<br><span id="newlikes" data-currentuser="<%# BlogFunctions.GetUserName(Eval("NodeOwner")) %>" data-blogposttitle="<%# Eval("DocumentID")%>"><a href="#"><%# CMSTransformation.GetBlogLikesCount(Eval("DocumentID"))%> Likes</a></span></div>

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 2, 2015 22:04

, I believe if it is a web app, you will need to rebuild the entire project.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 2, 2015 22:06

That namespace is really not a good place to put your custom transformations. Since you have a webapp just create a folder that will house your custom transformation methods. Then create your class, then your method, make sure you have the proper usings at the top, build/publish you webapp and then you can call it by Namespace.Method()

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on June 3, 2015 00:48

Created new folder under CMSApp_AppCode called CustomTransformation. Created my class and method and added the new namespace/method to the transformation.

I am still getting this error. What is the CMSVirtualFiles folder that it is looking at?

[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=520a6c2f-fbcc-46c5-b473-2c2f8bd02e94/IntranetPortal.Transformations/BlogPostDetail_KeepingTrac---showeditdelete-0.ascx(19): error CS0103: The name 'CustomTransformation' does not exist in the current context

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 3, 2015 18:49

Where did you do this ? On the live production site? Or on development machine? Did you rebuild entire solution?

0 votesVote for this answer Mark as a Correct answer

Divyanshu Gupta answered on December 20, 2016 08:28

Hi,
I was getting the same issue so i rebuild the entire solution.
Finally custom method is recognized in transformation.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.