Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-71521

DDLRecordLocalServiceUtil.addRecord interprets Collections and arrays as single String values



      The DDLRecordLocalServiceUtil.addRecord(long, long, long, int displayIndex, Map<String, Serializable>, ServiceContext) method allows the user to pass in a map with values for each field in the DDLRecordSet. The Fields variable is then constructed from this Map.

      However, there is no way to pass in multiple values for a repeatable field. If you put an array or a Collection of values into the Map for that field name, the addRecord method interprets the entire Collection or array as a single String value. So, only one value is added for that field, instead of however many values were in the array.

      Note that this method is deprecated in master and ee-7.0.x. However, the bug still exists regardless, so we will fix it in there. This method is by far the most user-friendly one for programmatically creating DDLRecords, as it doesn't require the user to go through the convoluted process of creating a Fields object or a DDMFormFieldValues object.

      Note also that the user will be required to add in the _fieldsDisplay value to the Map that they pass in in order for the method to work properly with repeatable fields. If the _fieldsDisplay value is not passed in, there would be scenarios under which it would be impossible to know the order in which repeatable elements should be listed in the DDLRecord. For this reason, it should be required that the user construct and pass in the _fieldsDisplay. If the user does not do this, each repeatable element will only show up once, regardless of the sizes of the Lists or arrays that were passed in.

      Steps to Reproduce

      1. Start Liferay and sign in as the admin user.
      2. Go to Left-Hand Navigation menu > Liferay > Content > Dynamic Data Lists > Add Button
      3. Give your List a name.
      4. For Data Definition, click Select and then use the Add Button to add a new Data Definition.
      5. Give your Data Definition a name.
      6. For your fields, add a single non-repeatable Text field, and a single repeatable Boolean field nested inside the Text field.
      7. Note the Name of your text field and your Boolean field (this will be important later on).
      8. Save your Data Definition and select it for use in your List.
      9. Save your List
      10. Find the following Ids and make a note of them:
        • userId of Test Test: Left-Hand Navigation menu > Test > My Account > Account Settings > User ID
        • groupId of the Liferay Site: Left-Hand Navigation menu > Liferay > Configuration > Site Settings > Site ID
        • recordSetId of the DDL you created: Left-Hand Navigation menu > Liferay > Content > Dynamic Data Lists > ID
      11. Navigate to Left-Hand Navigation menu > Control Panel > Configuration > Server Administration > Script.
      12. Change the Language to Groovy.
      13. Download the attached callAddRecord.groovy file corresponding to the version of Liferay you are testing on, and paste the contents into the Script box.
      14. Change these lines to the values you noted in step 7:
        String textFieldName = "Text6y1p";
        String booleanFieldName = "Booleancdyk";
      15. Change these lines to the values you noted in step 10:
        long userId = 20153;
        long groupId = 20140;
        long recordSetId = 34708;
      16. Click Execute.
      17. Navigate to Left-Hand Navigation menu > Liferay > Content > Dynamic Data Lists > Click the DDL you created > Click on the new Record that the script inserted.

      Expected Result: The Booleans inserted would be "Yes" and then "No" as per this line of code:

      fieldsMap.put(booleanFieldName, [true, false]);

      Actual Result: The Booleans inserted are "No" and "No".

      Reproduced in:
      master? Yes, issue reproduced in master, although the method is deprecated in master (4c0c1a6088cc57dace55ce083e6b0eeda4582dfa)
      ee-7.0.x? Yes, issue reproduced in ee-7.0.x, although the method is deprecated in ee-7.0.x (1d202adbbb6d77698949a5f6e2e365025de32f03)
      ee-6.2.x? Yes, issue reproduced in ee-6.2.x (3739510bc58420fedf0fdad7ee8003bbe91a0fc1)


        Issue Links



              joyce.wang Joyce Wang
              michael.bowerman Michael Bowerman
              Kiyoshi Lee Kiyoshi Lee
              0 Vote for this issue
              0 Start watching this issue


                5 years, 48 weeks, 2 days ago


                  Version Package
                  6.2.X EE
                  7.0.0 DXP FP14
                  7.0.0 DXP SP3
                  7.0.3 CE GA4
                  7.0.X EE