diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php
index <HASH>..<HASH> 100644
--- a/grade/edit/tree/item_form.php
+++ b/grade/edit/tree/item_form.php
@@ -267,7 +267,11 @@ class edit_item_form extends moodleform {
                         } else {
                             $element =& $mform->createElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
                         }
-                        $mform->insertElementBefore($element, 'parentcategory');
+                        if ($mform->elementExists('parentcategory')) {
+                            $mform->insertElementBefore($element, 'parentcategory');
+                        } else {
+                            $mform->insertElementBefore($element, 'id');
+                        }
                         $mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
                     }
MDL-<I> fixed broken item editing when only one category present; merged from MOODLE_<I>_STABLE