cancel
Showing results for 
Search instead for 
Did you mean: 

Added Categories and Execute script in workflow

irene08
Champ in-the-making
Champ in-the-making
Hi!

Good Day! I've done my own javascript and I will execute this in workflow and I also added some category name in categories.xml. Here with is the code that I've done and below this script is the category name I've added. Please help. Thank you.
—————————————————————————————————————————————————————'
requiredpercent_actualpercent.js <—- this is the javascript I've created. I'm running this but it has no effect. Maybe I'm calling also the wrong property/id for category. In short, I want my file to be automatically tagged to "Approval" when Required Approval Percent is equal to Actual Approval Percent.

/*IRENE-Tagging file from reviewed to approval*/
   <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                if (wf_requiredApprovePercent = 100 && wf_actualPercent = 100)
                {
                logger.log(“Irene…Reading the if statement”);
                cm:generalclassifiable=”Approval”;
                logger.log(“enabling the approval”);
               
                if (wf_requiredApprovePercent == wf_actualPercent)
                {
                logger.log(“Irene…Reading the 2nd if statement”);
                cm:generalclassifiable=”Approval”;
                     logger.log(“enabling the approval.. 2nd if statement”);
                     }
                </activiti:string>
                  </activiti:field>
    </activiti:taskListener>
/*IRENE*/
————————————————————————————————————————————————————————
categories.xml

<!– IRENE-Document Review Status –>
<cm:category>
   <cm:name>Document Review Status</cm:name>
      <cm:subcategories>
                   <cm:category>
         <cm:name>Draft</cm:name>
         <cm:name>Reviewed</cm:name>
         <cm:name>Approval</cm:name> <—-here is the name that should be automatically tag in the file.
         <cm:name>Approved</cm:name>
         <cm:name>Published</cm:name>
         <cm:name>Abandoned</cm:name>
               </cm:category>   
                 </cm:subcategories>
</cm:category>
————————————————————————————————————————————————————————

Thank you,
Irene
8 REPLIES 8

afaust
Legendary Innovator
Legendary Innovator
Hello,

the following statement in your script does not make any sense to me:
cm:generalclassifiable=”Approval”;

If you want to add a tag to a document, you need to obtain the document reference first and then call addTag() to add a single tag. But cm:generalclassifiable is not a tag, just a common category, in which case you would need to update the cm:categories property of the document.

Some sample code (NOT directly applicable to your context, just a demonstration - also NOT tested, writtend ad-hoc):

// some code

// get the first document from the workflow package
var document = bpm_package.childFileFolders(true, false)[0];
var oldCategories = document.properties["cm:categories"];
var categoryToAdd = null;

var categories = classification.getRootCategories("cm:generalclassifiable");
var remainingNames = ["Document Review Status", "Approval"];
while(categoryToAdd == null && categories && remainingNames.length > 0){
   var idx = 0, max = categories.length, innerCategories = categories;
   // reset categories to prevent further iterations if we don't find a match
   categories = null;

   for(;idx < max; idx++){
      var category = categories[idx];
      if(category.name.equals(remainingNames[0])){
          if(remainingNames.length == 1){
             categoryToAdd = category;
          }else{
             categories = category.getSubCategories();
             remainingNames.shift();
             break;
          }
      }
   }
}

if(categoryToAdd != null){
   var newCategories = oldCategories != null ? oldCategories : [];
   newCategories.push(categoryToAdd);
   document.properties["cm:categories"] = newCategories;
   document.save();
}

// some more code

Regards
Axel

irene08
Champ in-the-making
Champ in-the-making
Hi!

I really appreciate your reply and effort. I just want to clarify that tag and category are different. I created my own category for me to use it as a tag.

Steps:
1. If author/creator uploads the file—->Draft(automatically)
…Author/Creator will set workflow for reviewers…
2. If updated the file and one of the reviewers approve it—->Reviewed(automatically)
3. If all reviewers approve the file and required percent is equal to actual percent—>Approval(should be automatically)
…Author/Creator will set another workflow for approvers…
4. If all approvers approve the file—>Approved(should be automatically)
5. Author/Creator will MANUALLY tag the file as Published.

I can set the the 'Draft' and 'Reviewed' automatically tag in the file thru user interface of alfresco share in MANAGE RULE. But I don't know why
I can't set the 'Approval' and 'Approved' category in manage rule so I decided to execute own script for this but my script doesn't work. I hope this helps and make sense. Smiley Happy Thank you really.

Again, Thank you.
Irene Smiley Happy

afaust
Legendary Innovator
Legendary Innovator
Hello,

tags are "enhanced categories", i.e. Alfresco provides special interfaces / methods that simplify dealing with tags. Technically, they are of the same nature.

Rules are only for content changes and don't react to workflow events if those events don't actually change anything (approval state in workflow is managed separately from content). This is why you need a script in your workflow.

Regards
Axel

irene08
Champ in-the-making
Champ in-the-making
Hello,

tags are "enhanced categories", i.e. Alfresco provides special interfaces / methods that simplify dealing with tags. Technically, they are of the same nature.

Rules are only for content changes and don't react to workflow events if those events don't actually change anything (approval state in workflow is managed separately from content). This is why you need a script in your workflow.

Regards
Axel

Thank you. I appreciate your help. Smiley Happy
Irene

rubiecasana
Champ in-the-making
Champ in-the-making
Hi Axel,

I'm working on the same problem. tried adding this code in the parallelreview_group_processdefinition.xml. Restarted Alfresco, however I think it's not executed.

Have I missed any step for this to take effect?

var nodeId = document.id;
var theDocument = search.findNode("workspace://SpacesStore/" + nodeId);
var summary = theDocument.properties["cm:summary"];
theDocument.properties["cm:summary"] = "Approved";
theDocument.save();

Hello,

the following statement in your script does not make any sense to me:
cm:generalclassifiable=”Approval”;

If you want to add a tag to a document, you need to obtain the document reference first and then call addTag() to add a single tag. But cm:generalclassifiable is not a tag, just a common category, in which case you would need to update the cm:categories property of the document.

Some sample code (NOT directly applicable to your context, just a demonstration - also NOT tested, writtend ad-hoc):

// some code

// get the first document from the workflow package
var document = bpm_package.childFileFolders(true, false)[0];
var oldCategories = document.properties["cm:categories"];
var categoryToAdd = null;

var categories = classification.getRootCategories("cm:generalclassifiable");
var remainingNames = ["Document Review Status", "Approval"];
while(categoryToAdd == null && categories && remainingNames.length > 0){
   var idx = 0, max = categories.length, innerCategories = categories;
   // reset categories to prevent further iterations if we don't find a match
   categories = null;

   for(;idx < max; idx++){
      var category = categories[idx];
      if(category.name.equals(remainingNames[0])){
          if(remainingNames.length == 1){
             categoryToAdd = category;
          }else{
             categories = category.getSubCategories();
             remainingNames.shift();
             break;
          }
      }
   }
}

if(categoryToAdd != null){
   var newCategories = oldCategories != null ? oldCategories : [];
   newCategories.push(categoryToAdd);
   document.properties["cm:categories"] = newCategories;
   document.save();
}

// some more code

Regards
Axel

afaust
Legendary Innovator
Legendary Innovator
Hello,

the code looks alright. Have you redeployed your updated process definition and started a new workflow? Only then will a change in a process definition actually lead to a result.

Regards
Axel

irene08
Champ in-the-making
Champ in-the-making
Hello,

the code looks alright. Have you redeployed your updated process definition and started a new workflow? Only then will a change in a process definition actually lead to a result.

Regards
Axel

Hi!

What do you mean by redeployed process definition? Is that the bpmn20.xml? It's different from processdefinition.xml. Right?

Thank you,
Irene

afaust
Legendary Innovator
Legendary Innovator
Hello,

processdefinition.xml (JBPM, can actually be named anything - need not be named processdefinition.xml at all) is equivalent to .bpmn20.xml (Activiti) and if any changes are made to either file, these changes only take effect if the respective file is redeployed (not just put into the correct directory on the server).

Regards
Axel