07-09-2018 06:20 AM
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.
08-01-2018 04:39 AM
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.
07-09-2018 06:30 AM
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
07-09-2018 06:41 AM
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
07-09-2018 06:59 AM
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.
07-09-2018 07:21 AM
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.
07-09-2018 07:46 AM
This field is getting added by apply aspect. So it would be difficult to modify out of the box 'Save' functionality
07-09-2018 07:58 AM
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.
08-01-2018 04:39 AM
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.
Explore our Alfresco products with the links below. Use labels to filter content by product module.