I want to create a property (d:int) which would unique across the repository.
e.g User cannot enter a number which already exists. It would display error that 'Duplicate Number'
I have another alternative that I can go for an autogenerated number but the customer did not agree on this.
Solved! Go to Solution.
I have solved this issue in a very effective manner. I have overridden the "form.post.json.js" file.
Basically, I have to validate this before DML perform.
try
{
if(itemId == "xm:ratik" ){
var luceneQuery = "@xm\\:ratik:24";
var result = search.luceneSearch(luceneQuery);
if(result != ""){
status.setCode(409, "duplicate..");
return;
}
}
persistedObject = formService.saveForm(itemKind, itemId, repoFormData);
}
I have also tried with constraint handler but Ajax request is the problem in constraint handler.
I hope that i was able to explain.
If you want to set the restriction at repository layer, you can use a constraint
https://docs.alfresco.com/community/concepts/metadata-model-contraints.html
https://blog.arvixe.com/custom-constrains-in-alfresco-model/
You can also add a JavaScript validation for Share UI in Form Field Validation
Its bit difficult.One approach would be like below.
Create a behavior/policy in alfresco(OnCreateNode).This policy should search the document with the value user has entered in the form for your specific unique property.If document has been found.Throw exception.So the new document will not get create with duplicate value.
how to implement policies and behavior , you can find more details on below link.
Behaviours / Policies | Alfresco Documentation
Implementing Custom Behaviors in Alfresco | ECMArchitect | Alfresco Developer Tutorials
I have used this approach in another situation but difficult was that when we are throwing an error from Java. We are not able to show error on Share UI because we are not adding any new share UI.
e.g - I am adding a new Field on 'Create Folder' form like UniqueNumber (d:int) of This Folder. So If I handle this in behavior on update/create policy. In that case, I can not show error on UI.
If we don't handle the exception in back end , it will throw exception in share UI as well.The only thing is , its bit of an ugly message string.If that is what you are worried about than.You can customize the field and add validate button.On click of validate display error message which you would like to have.
This field is getting added by apply aspect. So it would be difficult to modify out of the box 'Save' functionality
You do not need to modify save functionality define the custom control for your field.You only need to customize field.Refer below link for more details.
I have solved this issue in a very effective manner. I have overridden the "form.post.json.js" file.
Basically, I have to validate this before DML perform.
try
{
if(itemId == "xm:ratik" ){
var luceneQuery = "@xm\\:ratik:24";
var result = search.luceneSearch(luceneQuery);
if(result != ""){
status.setCode(409, "duplicate..");
return;
}
}
persistedObject = formService.saveForm(itemKind, itemId, repoFormData);
}
I have also tried with constraint handler but Ajax request is the problem in constraint handler.
I hope that i was able to explain.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.