Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-23602

Fix automation scripting complex properties handling

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 9.2
    • Fix Version/s: 9.3
    • Component/s: Automation

      Description

      Using a Nuxeo Server 9.2 or 9.3 SNAPSHOT

      Steps to reproduce:

      Using Studio

      • Create a schema:
        • ABAMultilang
          • title (Complex)
            • eng (String)
            • spa (String)
            • ita (String)
            • fra (String)
      • Associate the schema to a document type, i.e. File
      • Create an automation script like this:
        function run(input, params) {
          
          var properties = {
              "ABAMultilang:title": {
              "eng": "title ENG",
              "fra": "title FRA",
              "ita": "title ITA",
              "spa": "title SPA",
            },
            "dc:description": "Test" // this is for the test :-) check if dc:description is modified
          };
          
          
          Console.log("Properties: " + properties);
          
          var doc = Document.Update(input, {
            'properties': properties,
            'save': true
          }
                                   );
          return doc;
        }
        
        
      • Associate the automation script with the Document created event

      When a new File is created the script is executed, but the complex field is not updated. In the other hand dc:description is updated

      The same code works on a LTS 2016, so this is a regression.


      If you try using this code:

      function run(input, params) {
       
        var properties = "\"ABAMultilang:title\"= \"{\"end\": \"title ENG\", \"fra\": \"title FRA\", \"ita\": \"title ITA\", \"spa\": \"title SPA\"}\"\n\"dc:description\"= \"Test\"";
        
        
        Console.log("Properties: " + properties);
        
        var doc = Document.Update(input, {
          'properties': properties,
          'save': true
        }
                                 );
        return doc;
      }
      
      

      Provoque this error: PropertyNotFoundException: No such schema, "ABAMultilang:title"

      Caused by: org.nuxeo.ecm.core.api.model.PropertyNotFoundException: No such schema, "ABAMultilang:title"
      	at org.nuxeo.ecm.core.api.impl.DocumentModelImpl.getProperty(DocumentModelImpl.java:1262)
      	at org.nuxeo.ecm.automation.core.util.DocumentHelper.setProperty(DocumentHelper.java:282)
      	at org.nuxeo.ecm.automation.core.util.DocumentHelper.setProperty(DocumentHelper.java:146)
      	at org.nuxeo.ecm.automation.core.util.DocumentHelper.setProperties(DocumentHelper.java:125)
      	at org.nuxeo.ecm.automation.core.operations.document.UpdateDocument.run(UpdateDocument.java:66)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:171)
      	at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:176)
      	... 156 more
      

      The schema is associated with the document type "File"


      Workaround:

      • Define the complex field as multivaluated:
        • ABAMultilang
          • title (Complex & Multi-valuated)
            • eng (String)
            • spa (String)
            • ita (String)
            • fra (String)
      • In the event that launch the automation script, select "Document type": "Mutable document"
      function run(input, params) {
        
        //Now ABAMultilang:title receive an array of objects
        var properties = {
            "ABAMultilang:title": [{
            "eng": "title ENG",
            "fra": "title FRA",
            "ita": "title ITA",
            "spa": "title SPA",
          }],
          "dc:description": "Test" // this is for the test :-) check if dc:description is modified
        };
        
        
        Console.log("Properties: " + properties);
        
        var doc = Document.Update(input, {
          'properties': properties,
          'save': true
        }
                                 );
        return doc;
      }
      

      Using this approach the operation works as a charm.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 6 hours
                6h