How can I validate documents field in the workflow

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2015 07:16 AM
Hello,
I'm new in using Alfresco and I have a question
My matter is actually, when submitting start workflow, to check if the logged on user is the document coordinator and if the document is not already in an other active workflow.
I know that this must be done with client side validation via js file.
Thanks in advance
I'm new in using Alfresco and I have a question

My matter is actually, when submitting start workflow, to check if the logged on user is the document coordinator and if the document is not already in an other active workflow.
I know that this must be done with client side validation via js file.
Thanks in advance

Labels:
- Labels:
-
Archive
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2015 01:31 PM
Hello,
I'm back with a solution even if I'm not sure if it's the best. Any way that solved my problem.
I modified the method ObjectRenderer_renderCellAdd of object-finder.js to check if the user is the document coordinator and if there is no other active workflow linked to the document.
Instead of :
<javascript>
elCell.innerHTML = '<a id="' + containerId + '" href="#" ' + style + ' class="add-item add-' + scope.eventGroup + '" title="' + scope.msg("form.control.object-picker.add-item") + '" tabindex="0"><span class="addIcon"> </span></a>';
</javascript>
I put :
<javascript>
var showSelectLink = true;
if(oRecord.getData("type") == "cm:content"){
showSelectLink = false;
//Checking if the document is already in an other active worflow
var xmlHttp = new XMLHttpRequest();
var url = window.location.href;
var arr = url.split("/");
xmlHttp.open( "GET", (arr[0] + "//" + arr[2]).concat("/alfresco/s/api/node/").concat((oRecord.getData("nodeRef")).replace(":/","")).concat("/workflow-instances"), false );
xmlHttp.send( null );
var json = JSON.parse(xmlHttp.responseText);
if(json.data.length == 0){
//Checking if the logged on user is the document coordinator
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", (arr[0] + "//" + arr[2]).concat("/alfresco/s/slingshot/doclib/permissions/").concat((oRecord.getData("nodeRef")).replace(":/","")), false );
xmlHttp.send( null );
var json = JSON.parse(xmlHttp.responseText);
var hasDirectPermission = false;
//Direct permission
if(json.direct.length != 0){
var permission;
for(var index = 0; index < json.direct.length; index++){
permission = json.direct[index];
if(permission.role == "Coordinator"){
showSelectLink = true;
hasDirectPermission = true;
break;
}
}
}
//Inherited Permission
if(!hasDirectPermission && json.inherited.length != 0){
var permission;
for(var index = 0; index < json.inherited.length; index++){
permission = json.inherited[index];
if(permission.role == "Coordinator"){
showSelectLink = true;
break;
}
}
}
}
}
if(showSelectLink){
elCell.innerHTML = '<a id="' + containerId + '" href="#" ' + style + ' class="add-item add-' + scope.eventGroup + '" title="' + scope.msg("form.control.object-picker.add-item") + '" tabindex="0"><span class="addIcon"> </span></a>';
}
</javascript>
Regards,
I'm back with a solution even if I'm not sure if it's the best. Any way that solved my problem.
I modified the method ObjectRenderer_renderCellAdd of object-finder.js to check if the user is the document coordinator and if there is no other active workflow linked to the document.
Instead of :
<javascript>
elCell.innerHTML = '<a id="' + containerId + '" href="#" ' + style + ' class="add-item add-' + scope.eventGroup + '" title="' + scope.msg("form.control.object-picker.add-item") + '" tabindex="0"><span class="addIcon"> </span></a>';
</javascript>
I put :
<javascript>
var showSelectLink = true;
if(oRecord.getData("type") == "cm:content"){
showSelectLink = false;
//Checking if the document is already in an other active worflow
var xmlHttp = new XMLHttpRequest();
var url = window.location.href;
var arr = url.split("/");
xmlHttp.open( "GET", (arr[0] + "//" + arr[2]).concat("/alfresco/s/api/node/").concat((oRecord.getData("nodeRef")).replace(":/","")).concat("/workflow-instances"), false );
xmlHttp.send( null );
var json = JSON.parse(xmlHttp.responseText);
if(json.data.length == 0){
//Checking if the logged on user is the document coordinator
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", (arr[0] + "//" + arr[2]).concat("/alfresco/s/slingshot/doclib/permissions/").concat((oRecord.getData("nodeRef")).replace(":/","")), false );
xmlHttp.send( null );
var json = JSON.parse(xmlHttp.responseText);
var hasDirectPermission = false;
//Direct permission
if(json.direct.length != 0){
var permission;
for(var index = 0; index < json.direct.length; index++){
permission = json.direct[index];
if(permission.role == "Coordinator"){
showSelectLink = true;
hasDirectPermission = true;
break;
}
}
}
//Inherited Permission
if(!hasDirectPermission && json.inherited.length != 0){
var permission;
for(var index = 0; index < json.inherited.length; index++){
permission = json.inherited[index];
if(permission.role == "Coordinator"){
showSelectLink = true;
break;
}
}
}
}
}
if(showSelectLink){
elCell.innerHTML = '<a id="' + containerId + '" href="#" ' + style + ' class="add-item add-' + scope.eventGroup + '" title="' + scope.msg("form.control.object-picker.add-item") + '" tabindex="0"><span class="addIcon"> </span></a>';
}
</javascript>
Regards,
