cancel
Showing results for 
Search instead for 
Did you mean: 

Create content from web form without web client

lirux
Champ in-the-making
Champ in-the-making
Hi,
I want to create content using e pre-defined web form programmatically (via web script for example), i.e. without the web client wizard.
In other words:
1) create a web form as usual (xsd, deploy in alfresco…)
2) using the API: find the form, fill in the required information and generate the content
3) the generated content (xml, html,… ) must appear in the user's sandbox "Modified items"

Could someone post some example code? I searched the forum but I haven't found any example…

For my application, another option would be using the web client wizard but with the "name" in the first step pre-populated by the application. Can I do this thing or, better, skip over the first step?

Thank you in advance,
Lirux
3 REPLIES 3

lirux
Champ in-the-making
Champ in-the-making
Excuse me, I've posted this question on the wrong forum.

Sorry,
Lirux

benvercammen
Champ in-the-making
Champ in-the-making
I'm not 100% sure if this is what your looking for, but I've recently done something rather similar to what I think you're looking for (http://forums.alfresco.com/en/viewtopic.php?f=30&t=17027).

What we actually did was create a custom wizard (triggered by a custom command from outside the web client) where we could provide an XSD for each step. So for each step the form would be automatically rendered by Alfresco and all we had to do in the end was combine all data from the different steps/forms and create/update some files and trigger the renderings. Now I know this isn't exactly what you're looking for, but perhaps you can get a few ideas from that thread.

Please note that it was implemented on Enterprise 2.2.2 and adapted later on to work on 3.0.1. I don't know what version you're currently working with, but I seem to remember reading somewhere that something like "ECM Forms" would be implemented in Enterprise 3.1 (and is already in the Labs 3 version), so perhaps you could check out the code over there?

Anyway, you'll probably have more luck digging through the Alfresco code and trying things for yourself than hoping for someone else to hand it to you (though you probably already knew that since I'm the first to respond in 2 weeks time). Nevertheless, in case you do figure something out, it would still be nice if you could share it here  Smiley Happy

lirux
Champ in-the-making
Champ in-the-making
Thank you for your post.
I've read the post you mention but is rather advanced for my current knowledge of Alfresco.
Nevertheless it sounds quite interesting, and I'll try to understand it in the future.
Returning on my question, after further digging in the forum, I found some example that creates an xml content in WCM that is visibile in the user's sandbox "Modified items",
and link it with the corresponding web form. What is missing is the trigger of renditions. Have you any idea of how I can accomplish this?

My code is contextualised in the press release example of the "WCM 2_1 Product Evaluation Guide.pdf". Is quite experimental but I think it's understandable:


model.toWho = (args.param != null) ? args.param : person.properties.userName;
model.store = avm.lookupStore("alfrescosample–admin");
model.webappFolder = avm.webappsFolderPath;
var storeRootNode = avm.lookupStoreRoot(args.store);
model.rootNode = storeRootNode;
if (storeRootNode != null) {
   var path = storeRootNode.path + "/ROOT/media/releases/content";
   model.path = path;
   var node = avm.lookupNode(path);
   model.node = node;
   
   var timestamp = new Date().getTime();
   
   // Creates the new node
   var fileName = "mioContenuto_" + timestamp + ".xml";
   var contentNode = node.createNode(fileName, "wcm:avmplaincontent");
   // Sets the file name
   contentNode.properties["cm:name"] = fileName;
   
   // Adding the aspect for the web forms
   var props= new Array(2);
   props["wca:parentformname"] = "company-footer";
   props["wca:originalparentpath"] = "alfrescosample–admin–preview:/www/avm_webapps/ROOT";
   contentNode.addAspect("wca:forminstancedata", props);
   contentNode.save();

   // Creates the xml content
   var pressReleaseXml2=  <pr:company_footer xmlns:pr="http://www.alfresco.org/alfresco/pr"
                  xmlns:alf="http://www.alfresco.org"
                  xmlns:chiba="http://chiba.sourceforge.net/xforms"
                  xmlns:ev="http://www.w3.org/2001/xml-events"
                  xmlns:xf="http://www.w3.org/2002/xforms"
                  xmlns:xhtml="http://www.w3.org/1999/xhtml"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   >
   <pr:name>Alfresco</pr:name>
   <pr:body>Body xml</pr:body>
   </pr:company_footer>;

   contentNode.content = pressReleaseXml2.toXMLString();
   contentNode.save();
   
   // TODO: trigger the renditions

} else {
  logger.log("No store: " + args.store);
}