3

I am trying to inject data into the correct fields when making a component. So far I am able to inject data into Text fields, Number fields, Date fields, Multi-value fields. I use this function to do this.

Utilities.PushValuesToField = function PushValuesToField(fieldId, values) {
    var p = this.properties;
    var item = $display.getItem();
    if (item) {
        if (item.getItemType() == "tcm:16") {
            var fieldBuilder = $display.getView().properties.controls.fieldBuilder;
            if (fieldBuilder.getField(fieldId)) {
                var field = fieldBuilder.getField(fieldId);
                var countOfValues = values.length;
                if (countOfValues > 0) {
                    field.setValues([values[0]]);
                    try{
                        for (var iValue = 1 ; iValue < countOfValues ; iValue++) {
                            var addedField = fieldBuilder.properties.input.insertField(field);
                            addedField.setValues([values[iValue]]);
                            field = addedField;
                        }
                    } catch (err) {
                        return 100;
                    }
                }
            }
        }
    }
};

Now I would like to be able to do the same but then for Embedded schemas. So making a function where I can give an id and a value and put that value in the correct field.

3

I found the solution.

EmbeddedSchemaFieldObject.getField("Name of child field");

So The function that I made to do this:

Utilities.PushValuesToEmbeddedField = function PushValuesToEmbeddedField(EmbeddedFieldId, fieldId, values) {
    var p = this.properties;
    var item = $display.getItem();
    if (item) {
        if (item.getItemType() == "tcm:16") {
            var fieldBuilder = $display.getView().properties.controls.fieldBuilder;
            if (fieldBuilder.getField(EmbeddedFieldId)) {
                var field = fieldBuilder.getField(EmbeddedFieldId);
                if (field.getField(fieldId)) {
                    var childField = field.getField(fieldId);
                    var countOfValues = values.length;
                    if (countOfValues > 0) {
                        childField.setValues([values[0]]);
                        try {
                            for (var iValue = 1 ; iValue < countOfValues ; iValue++) {
                                var addedField = fieldBuilder.properties.input.insertField(childField);
                                addedField.setValues([values[iValue]]);
                                childField = addedField;
                            }
                        } catch (err) {
                            return 100;
                        }
                    }
                }
            }
        }
    }
};
| improve this answer | |
  • Great that you could find it. Did you know you could do this with an Event as well, using TOM.NET/server side code? – Nuno Linhares Jul 28 '14 at 17:56
  • Yes but we were instructed to do as much as possible without the use of TOM.NET so I was determined to try and solve it this way. – Thomas Hendrickx Jul 29 '14 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.