XSLT FAQ

Can I call C1 Functions AJAX style from JavaScript or Flash?

I would like to create AJAX based functionality - I have created a function in C1 that builds an XML structure and now I would like to call this function from the browser (JavaScript or Flash) and get the XML – how can I execute my function directly through a URL?

Answer:

By default C1 Functions can not be executed directly through a HTTP request (for security reasons), but it’s fairly easy to enable this on individual functions. When the code files below are copied unchanged to your site, you can execute a URL like this:

http://mysite/Ajax/My.Xslt.Function.ashx?cultureScope=nl-NL&PageNum=2&PageSize=25

This will execute the function named “My.Xslt.Function” in the Dutch data scope (yielding Dutch data, when data is localizable) - the function will be called with the parameters “PageNum” and “PageSize” set to 2 and 25. The result is returned to the client as XML.

Note: When calling a function, both the file name and URL parameters are case-sensitive.

To enable this feature you need to copy a single “base file” to your /App_Code directory and then copy + rename a small “function stub” file to a location of your choice (like a new “/Ajax” directory). You should name the function stub file like “(your full function name).ashx”.

The reason you have to create function stub files for each C1 Function to call via HTTP is for security reasons – a number of functions are not desirable to expose to the public.

To enable this feature first download this file and copy it to your /App_Code directory (or a subfolder below the /App_Code directory). After download you can also upload the file via the C1 Consoles System perspective.

Secondly, download this file and copy it to your desktop (or some other temp location). This file is like a template - simply rename the file to the name of your function followed by “.ashx”, like “Composite.Pages.QuickSitemap.ashx” and upload the file to your website in a subfolder, like "/Ajax".

At this point you should be able to call the function using URLs like

http://mysite/Ajax/Composite.Pages.QuickSitemap.ashx
http://mysite/Ajax/Composite.Pages.QuickSitemap.ashx?cultureScope=nl-NL
http://mysite/Ajax/Composite.Pages.QuickSitemap.ashx?cultureScope=nl-NL&someCustomParam=5

First request will execute using the default data language of the site, second URL sets an explicit culture scope (data language) for the request, making it return Dutch content. The last one also sets a parameter named "someCustomParam" to "5" (which could be of type int in this case) when calling the function.