Hi all,
We're working in a webscript that creates custom type nodes inside a folder. Alfresco 7.1 installed.
The problem appears when trying to create a node with the same name. This can happen, since the names are read from a list that can have repeated records. The webscript should avoid this behaviour by cheking if the node just created exists, but alfresco doesn't find it and if we try to catch de duplicatedNodeNameException to handle the error, when the webscript ends the structure is not created.
If the list does not contain repeated records the webscript works like charm and the webscript creates the nodes correctly. It seems that, even handling the exception, Alfresco makes a rollback somehow.
The custom type is therefore well defined in our model and looks like this:
<type name="tc:caja">
<title>Caja</title>
<parent>cm:cmobject</parent>
<properties>
<property name="tc:uiAgtcCaja">
<type>d:int</type>
<index enabled="true">
<atomic>false</atomic>
<stored>false</stored>
<tokenised>both</tokenised>
</index>
</property>
<property name="tc:cajaLibre">
<title>Caja libre</title>
<type>d:boolean</type>
<mandatory>true</mandatory>
<default>true</default>
</property>
</properties>
</type>I've developed a dummy ws to recreate the case, with this descriptor:
<webscript>
<shortname>test</shortname>
<description>test</description>
<url>es/mycompany/transfer/test</url>
<authentication runas="admin">user</authentication>
</webscript>The js code:
function main() {
//Search for the boxes root folder (CAJAS) and create if it does not exist
var boxesFolderQuery = {
query: "PATH:\"/app:company_home/cm:CAJAS\"",
language: "fts-alfresco",
onerror: "no-results",
};
var boxesFolder = search.query(boxesFolderQuery)[0];
if (boxesFolder == null) {
boxesFolder = companyhome.createNode('CAJAS', 'cm:folder');
}
logger.debug("Boxes Folder created: " + boxesFolder.nodeRef);
//Create a box inside boxes root folder
var tmpBox = boxesFolder.createNode(1000, "tc:caja");
tmpBox.properties["tc:uiAgtcCaja"] = 1000;
tmpBox.properties["tc:cajaLibre"] = false;
tmpBox.save();
logger.debug("Box created: " + tmpBox.nodeRef);
//Search for the box just created
var boxQuery = {
query: "TYPE:\"tc:caja\" AND @cm:name:1000",
language: "fts-alfresco",
onerror: "no-results",
};
var box = search.query(boxQuery)[0]; //This should return at least 1 result, but it turns out that is null
//Alfresco attempts to create the node again and the duplicatedChildNodeNameException is managed so the webscript does not fail
if (box == null) {
try {
boxesFolder.createNode(1000, "tc:caja");
} catch (error) {
logger.warn(error);
}
}
}
main();Caja means box in Spanish 
The view simply prints "ok" if the webscript doesn't fail. And it prints "ok" always, by the way, even if the folder and every node inside it are not created.
if I run the webscript in debug mode, the log shows:
2023-01-13 11:55:55,703 DEBUG [org.alfresco.repo.jscript.ScriptLogger] [http-nio-8080-exec-11] Boxes Folder created: workspace://SpacesStore/59d9436f-92c3-4a1e-b409-e44d4aeda3ba
2023-01-13 11:55:55,738 DEBUG [org.alfresco.repo.jscript.ScriptLogger] [http-nio-8080-exec-11] Box created: workspace://SpacesStore/5e9076c6-d716-415a-9c43-833f0f2deb18
2023-01-13 11:55:55,806 WARN [org.alfresco.repo.jscript.ScriptLogger] [http-nio-8080-exec-11] JavaException: org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: 1000
Hope someone can help me, thank you very much in advance 