Uploaded image for project: 'Service Packs and Hot Fixes'
  1. Service Packs and Hot Fixes
  2. MNT-20012

findFormFieldWithId() does not consistently work in a custom form stencil

    Details

      Description

      Summary
      When using scope.findFormFieldWithId() in a custom form stencil, sometimes there is an error thrown like the following:

      Error: scope.findFormFieldWithId(...) is undefined
      this.formRendered@http://localhost:6197/activiti-app/app/rest/script-files/controllers:27:28
      $scope.processFormRenderedEvent/<@http://localhost:6197/activiti-app/workflow/scripts/943af5c5.scripts.js:4:6464
      f/l<@http://localhost:6197/activiti-app/libs/angular_1.3.13/angular.min.js:138:175
      e@http://localhost:6197/activiti-app/libs/angular_1.3.13/angular.min.js:40:72
      nf/m.defer/c<@http://localhost:6197/activiti-app/libs/angular_1.3.13/angular.min.js:44:112
      

      Refreshing the browser page rendering the stencil in the task form does at some point find the call and deliver expected results. Therefore this lloks to be a race condition issue happening while loading all our scripts.

      Steps to reproduce
      1. Import and publish the attached app "new.zip"
      NOTES:

      • The app comes with a simple process: Start event->user task->user task->end event
      • The first user task has a form defined with a simple text field named "quote"
      • The second user task has a display value field to display the value of quote
      • The second user task is also using a custom stencil field "quote" as part of the stencil "new"
      • The stencil controler code looks like:
        angular.module('activitiApp')
            .controller('MyNewControllerProcessSpecific', ['$rootScope', '$scope', function ($rootScope, $scope) {
                console.log('MyNewControllerProcessSpecific instantiated');
                console.log($scope);
                // Register this controller to listen to the form extensions methods
                $scope.registerCustomFieldListener(this);
                this.formRendered = function (form, scope) {
                    console.log('rendered');
                    $scope.myquote = scope.findFormFieldWithId(scope.currentAndHistoricFormFields, 'quote').value;
        
                }
            }]);
        

        2. From the published app start a new process
        3. In the created user task, fill the quote field with value "Defect" and complete the task
        4. Open the browser developer tool console
        5. Inspect the console and the field values in the second created user task form

      Current behaviour
      The stencil field does not have a value filled in and the browser console shows an error:

      Error: scope.findFormFieldWithId(...) is undefined

      Expected behaviour

      • The stencil field shows the value that was entered for the quote field, e.g. "Defect".
      • There should not be any errors in the browser console

      Supporting evidence

      • Reproduced with latest APS 1.9 release
      • Refreshing the second user tasks form eventually renders the correct value for the stencil field and does not throw any console error. You might need to refresh a few times to make it work.

        Attachments

        1. new.zip
          10 kB
        2. new-updated.zip
          11 kB

          Structure

            Activity

              People

              • Assignee:
                closedbugs Closed Bugs (Inactive)
                Reporter:
                dkoch Dennis Koch
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Structure Helper Panel