Create form field programmatically on usertask

Hey all,

I am currently trying to programmatically add a form field to a usertask. I discovered that I should use the ‘modeling’ object.

However I cannot figure out how to add a form with a single field to a usertask.

I think i should use the moddle.create object somehow. But I haven’t been able to discover how. Something like this:

var form = moddle.create('bpmn:customExtension', { 'field': {'label': 'Ask question?', 'type': 'boolean', 'defaultValue': false}});

modeling.updateProperties(element, {
		customExtension: form

Can someone point me in the right direction?

Found this old forum post: Add extension elements with any type (i.e. camunda:inputOutput)

This is what I was looking for.

Solved with the following function:

window.updateFormField = function(elementID) {
	var element = elementRegistry.get(elementID);
	var extensionElements =	element.businessObject.get('extensionElements');
	if (!extensionElements) {
		extensionElements = moddle.create('bpmn:ExtensionElements');
	var form = extensionElements.get('values').filter(function(elem) {
		return elem.$type == 'camunda:FormData'}
	if (!form) {
		form = moddle.create('camunda:FormData');
	var formField = moddle.create('camunda:FormField', {'defaultValue': 'false', 'id': 'FormField_Test', 'label': 'Confirm?', 'type': 'boolean'});
	var existingFieldsWithID = form.get('fields').filter(function(elem) {
		return ==;
	for (var i = 0; i < existingFieldsWithID.length; i++) {
	modeling.updateProperties(element, {extensionElements: extensionElements});