cancel
Showing results for 
Search instead for 
Did you mean: 

Request of information on form + adv workflow

baffo1971
Champ in-the-making
Champ in-the-making
Hi all,
this is my first post on the Alfresco forum, then please forgive me if I am not "perfect" with the submission of my request.

I am trying to understand - as I am not an experienced Java developer - if there is a "simple" way to create a form within the Alfresco Explorer, to be used only by some allowed users: the form must contain a number of meta info, and the submission of the form must create a document which is used as a resource for an advanced workflow (using jBPM).

The process should be some kind of multiple, but serial, approve/reject steps, and during each phase only one person within the group allowed to approve/reject can add new meta fields and/or modify the previously entered ones.

Can you please advise on what technology and/or means should be used to:

1. create the form and manage the availability to allowed users only
2. create and store the documents generated by each form submission (I am thinking of XML data, that could be transformed into some more readable formats, but later - the important thing is now store the data)
3. manage the start of the advanced workflow - later on I will then go into the details of the workflow

Many thanks in advance!
2 REPLIES 2

granddams
Champ in-the-making
Champ in-the-making
Hi,

i'm not experienced too, but i'd do the form with freemarker (to put it in a dashlet).
It sends informations to a webscript which contains a secure test and which checks if the user is authorized.
The webscript constructs a xml file with form's informations. Xml file is stored in the user homefolder.
And for start the workflow you can use :

var xmlfile = "the noderef of your xmlfile";
var workflowDefinition = workflow.getDefinitionByName("jbpm$youradvancedworkflow");

var workflowPackage = workflow.createPackage();
workflowPackage.addNode(xmlfile);

var workflowParameters = [];

var workflowPath = workflowDefinition.startWorkflow(workflowPackage, workflowParameters);

// End the start task
var tasks = workflowPath.getTasks();
for (task in tasks)
  {
   tasks[task].endTask(null);
  }

Any other ideas from skilled alfresco users?

granddams
Champ in-the-making
Champ in-the-making
For your project, i think, you've to:
- create a dashlet in Share which shows to authorized user the form you want they fill
- create a webscript in Explorer which check if current user is authorized to fill the form
- create an other webscript which create an xml file with infos of the form, save this xml, and loach a custom workflow


1) Create the dashlet on share

1.1 create an xml file named "mycustomdashlet.get.desc.xml"

<webscript>
   <shortname>My dashlet name</shortname>
   <description>A description</description>
   <family>user-dashlet</family>
   <url>/components/dashlets/mycustomdashlet</url>
</webscript>

1.2 create a ftl file "mycustomdashlet.get.html.ftl"
It's the graphic part of your dashlet, you can customize the look of your form here with freemarker language.

<#assign userIsAuthorized = results["isAuthorized"]>
<div class="dashlet">
   <div class="title">Complete the Form</div>
   <div class="body">
      <#if userIsAuthorized = "true">
      <form action="${url.serviceContext}/createXmlAndLauch" method="post" enctype="multipart/form-data" accept-charset="utf-8">
         <h4>Form</h4>
         <table>
            <tr>
               <td><label for="name"><strong>Name : </strong></label></td>
               <td><input name="name" value="" /></td>
            </tr>
            <tr>
               <td><label for="age"><strong>Age : </strong></label></td>
               <td><input name="age" value="" /></td>
            </tr>
            …
            <tr>
               <td><input type="submit" name="submit" value="Send"></td>
            </tr>
         </table>
      </form>
      <#else>
         You're not authorized to complete the form.
      </#if>
   </div>
</div>

1.3 create a scirpt "mycustomdashlet.get.js"
Here you receive informations from an Alfresco Explorer script

var connector = remote.connect("alfresco");
var data = connector.get("/sample/mycustomdashlet_prop.json);

// create json object from data
var result = eval('(' + data + ')');
model.results = result["data"];

2) Create the webscript in AlfrescoExlporer which gives informations to the dashlet:

2.1 create a "mycustomdashlet_prop.get.desc.xml"

<webscript>
   <shortname>Mycustomdashlet Properties</shortname>
   <description>Gives informations to the dashlet mycustomdashlet</description>
   <url>/sample/mycustomdashlet_prop.json</url>
   <authentication>user</authentication>
   <transaction>required</transaction>
</webscript>

2.2 create a file "mycustomdashlet_prop.get.js"
This alfresco script will tell you if the user is in a group which can fill the form.

var groups = people.getContainerGroups(person);
var authorized = false;
for (var group in groups){
   if(group == people.getGroup("GROUPS_myAuthorizedGroup"){
      authorized = true;
   }
}
model.Authorized = authorized;

2.3 create a "mycustomdashlet_prop.get.json.ftl"
with your js information, you've to create a json object to pass it to your share dashlet.

{
   "data" :
   {
      "isAuthorized" : "${Authorized?string}"
   }
}

3) Create a script to produce an xml file and start the workflow

3.1 create a "createXmlAndLauch.post.desc.xml"

<webscript>
   <shortname>CreateXmlAndLauch webscript</shortname>
   <description>gather information from form, create an xml file and launch an advanced workflow</description>
   <url>/sample/createXmlAndLauch</url>
   <authentication>user</authentication>
   <transaction>required</transaction>
</webscript>

3.2 "createXmlAndLauch.post.js"

var name=args["name"];
var age=args["age"];


var Header = '<?xml version="1.0" ?>\n';
var Content = '<name>'+name+'</name>\n'
+'<age>'+age+'</age>\n'
+'…\n'
+'…\n';

//Creation of the xml file
var xmlFile=person.properties["cm:homeFolder"].createNode('myNewXmlFile.xml');
xmlFile.content=Header+Content;
xmlFile.save();

//start workflow
var workflowDefinition = workflow.getDefinitionByName("jbpm$youradvancedworkflow");
var workflowPackage = workflow.createPackage();
workflowPackage.addNode(xmlFile);
var workflowParameters = [];
var workflowPath = workflowDefinition.startWorkflow(workflowPackage, workflowParameters);

var tasks = workflowPath.getTasks();
for (task in tasks){
   tasks[task].endTask(null);
  }



I think these snippets will help you.
I'm not an expert, i work on alfresco and share since 3months, so there's perhaps some mistakes or clumsiness or if someone have a better way to do this, post your solution, i want to learn too.
For your workflow, to send emails and create documents, are just another scripts added in your tasks in processdefinition file.


var mail = actions.create("mail");
var to = "" ;
var from = "" ;
var subject = "" ;

mail.parameters.to = to ;
mail.parameters.subject = subject ;
mail.parameters.from =  from ;

var mailText = "blablabla";
mail.parameters.text =  mailText;

mail.execute(bpm_package);


var Content = 'blablabla';
var file=person.properties["cm:homeFolder"].createNode('file.txt');
file.content=Content;
file.save();

good luck