Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-70058

Textarea custom field can't be updated by core_course_update_courses webservice

    XMLWordPrintable

Details

    • MOODLE_39_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-70058-402
    • MDL-70058-403
    • Hide

      Setup

      1. Log in as admin
      2. Navigate to Courses > Course custom fields in site administration
      3. Add a new category (if none exists)
      4. Add a new Text area custom field:
        • Name: My text area
        • Shortname: mytextarea
      5. Add a new Short text custom field:
        • Name: My short text
        • Shortname: myshorttext
      6. Enable web services (Site admin > General > Advanced features > Enable web services)
      7. Create a new custom external service: (Site admin > Server > Web services > External services)
        • Name: Course management
        • Enabled: Yes
      8. Add the following functions to the new service:
        • core_course_create_courses
        • core_course_update_courses
      9. Create a token for the admin user to use the new service

      Create course with custom fields

      1. Execute the following:

        $ curl --silent "<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json" --data "wstoken=<TOKEN>&wsfunction=core_course_create_courses&courses[0][shortname]=ENG&courses[0][fullname]=English&courses[0][categoryid]=1&courses[0][customfields][0][shortname]=mytextarea&courses[0][customfields][0][value]=Textarea&courses[0][customfields][1][shortname]=myshorttext&courses[0][customfields][1][value]=Shorttext" | python -m "json.tool"
        

      2. Confirm you get back the following (make a note of the returned course ID):

        [
            {
                "id": 3,
                "shortname": "ENG"
            }
        ]
        

      3. Manually navigate to

        <WWWROOT>/course/index.php

      4. Confirm the course you just created has the following values:
        • My text area: Textarea
        • My short text: Shorttext

      Update course with custom fields

      1. Execute the following:

        $ curl --silent "<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json" --data "wstoken=<TOKEN>&wsfunction=core_course_update_courses&courses[0][id]=<COURSEID>&courses[0][customfields][0][shortname]=mytextarea&courses[0][customfields][0][value]=Potatoes&courses[0][customfields][1][shortname]=myshorttext&courses[0][customfields][1][value]=Carrots" | python -m "json.tool"
        

      2. Confirm you get back the following:

        {
            "warnings": []
        }
        

      3. Manually navigate to

        <WWWROOT>/course/index.php

      4. Confirm the course you just created has the following values:
        • My text area: Potatoes
        • My short text: Carrots
      Show
      Setup Log in as admin Navigate to Courses > Course custom fields in site administration Add a new category (if none exists) Add a new Text area custom field: Name: My text area Shortname: mytextarea Add a new Short text custom field: Name: My short text Shortname: myshorttext Enable web services (Site admin > General > Advanced features > Enable web services) Create a new custom external service: (Site admin > Server > Web services > External services) Name: Course management Enabled: Yes Add the following functions to the new service: core_course_create_courses core_course_update_courses Create a token for the admin user to use the new service Create course with custom fields Execute the following: $ curl --silent "<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json" --data "wstoken=<TOKEN>&wsfunction=core_course_create_courses&courses[0][shortname]=ENG&courses[0][fullname]=English&courses[0][categoryid]=1&courses[0][customfields][0][shortname]=mytextarea&courses[0][customfields][0][value]=Textarea&courses[0][customfields][1][shortname]=myshorttext&courses[0][customfields][1][value]=Shorttext" | python -m "json.tool" Confirm you get back the following (make a note of the returned course ID): [ { "id": 3, "shortname": "ENG" } ] Manually navigate to <WWWROOT>/course/index.php Confirm the course you just created has the following values: My text area: Textarea My short text: Shorttext Update course with custom fields Execute the following: $ curl --silent "<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json" --data "wstoken=<TOKEN>&wsfunction=core_course_update_courses&courses[0][id]=<COURSEID>&courses[0][customfields][0][shortname]=mytextarea&courses[0][customfields][0][value]=Potatoes&courses[0][customfields][1][shortname]=myshorttext&courses[0][customfields][1][value]=Carrots" | python -m "json.tool" Confirm you get back the following: { "warnings": [] } Manually navigate to <WWWROOT>/course/index.php Confirm the course you just created has the following values: My text area: Potatoes My short text: Carrots

    Description

      Custom fields of type textarea are not updated when calling course update core webservice without a warning. They are just ignored.

      Looking into the code, textarea data_controller looks for {customfieldshortname}_editor param to be an array with text and format keys, but webservice allows only external value of PARAM_ALPHANUMEXT type.

      I'm not sure if the bug belongs to core webservice or to customfield handler, but as textarea is kind of special type (ie. wants _editor appended to shortname) I think it should care of being able to update through webservice.

      Attachments

        1. (1) 2 Passed -- (Main)MDL-70058.png
          44 kB
          Kim Jared Lucas
        2. (1) 4 Passed -- (Main)MDL-70058.png
          108 kB
          Kim Jared Lucas
        3. (2) 2 Passed -- (Main)MDL-70058.png
          38 kB
          Kim Jared Lucas
        4. (2) 4 Passed -- (Main)MDL-70058.png
          74 kB
          Kim Jared Lucas

        Issue Links

          Activity

            People

              pholden Paul Holden
              carreraj Juan Carrera
              Carlos Escobedo Carlos Escobedo
              Jun Pataleta Jun Pataleta
              Kim Jared Lucas Kim Jared Lucas
              Votes:
              6 Vote for this issue
              Watchers:
              29 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 5 hours, 35 minutes
                  5h 35m

                  Clockify

                    Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.