private async _importOtherGroupsAndControls()

in src/Common/ProcessImporter.ts [261:353]


    private async _importOtherGroupsAndControls(
        witLayout: IWITLayout,
        page: WITProcessDefinitionsInterfaces.Page,
        payload: IProcessPayload
    ) {
        logger.logVerbose(`Start import custom groups and all controls`);
        for (const section of page.sections) {
            for (const group of section.groups) {
                let newGroup: WITProcessDefinitionsInterfaces.Group;

                if (group.isContribution === true && this._config.options.skipImportFormContributions === true) {
                    // skip import group contriubtion unless user explicitly asks so
                    continue;
                }

                if (group.controls.length !== 0 && group.controls[0].controlType === "HtmlFieldControl") {
                    //Handle groups with HTML Controls
                    if (group.inherited) {
                        if (group.overridden) {
                            // No handling on group update since we have done this already in 1st pass
                            const htmlControl = group.controls[0];
                            if (htmlControl.overridden) {
                                // If the HTML control is overriden, we must update that as well 
                                let updatedHtmlControl: WITProcessDefinitionsInterfaces.Control;
                                try {
                                    updatedHtmlControl = await Engine.Task(
                                        () => this._witProcessDefinitionApi.editControl(htmlControl, payload.process.typeId, witLayout.workItemTypeRefName, group.id, htmlControl.id),
                                        `Edit HTML control '${htmlControl.id} in group'${group.id}' in page '${page.id}'`);
                                }
                                catch (error) {
                                    logger.logException(error);
                                    throw new ImportError(`Failed to edit HTML control '${htmlControl.id} in group'${group.id}' in page '${page.id}', see logs for details.`)
                                }

                                if (!updatedHtmlControl || updatedHtmlControl.id !== htmlControl.id) {
                                    throw new ImportError(`Failed to edit group '${group.id}' in page '${page.id}', server returned empty result or non-matching id.`)
                                }
                            }
                        }
                        else {
                            // no-op since the group is not overriden
                        }
                    }
                    else {
                        // special handling for HTML control - we must create a group containing the HTML control at same time.
                        const createGroup: WITProcessDefinitionsInterfaces.Group = Utility.toCreateGroup(group);
                        createGroup.controls = group.controls;
                        await this._createGroup(createGroup, page, section, witLayout, payload);
                    }
                }
                else {
                    //Groups with no HTML Controls

                    if (!group.inherited) {
                        //create the group if it's not inherited
                        const createGroup = Utility.toCreateGroup(group);
                        newGroup = await this._createGroup(createGroup, page, section, witLayout, payload);
                        group.id = newGroup.id;
                    }

                    for (const control of group.controls) {
                        if (!control.inherited || control.overridden) {
                            try {
                                let createControl: WITProcessDefinitionsInterfaces.Control = Utility.toCreateControl(control);

                                if (control.controlType === "WebpageControl" || (control.isContribution === true && this._config.options.skipImportFormContributions === true)) {
                                    // Skip web page control for now since not supported in inherited process.
                                    continue;
                                }

                                if (control.inherited) {
                                    if (control.overridden) {
                                        //edit
                                        await Engine.Task(() => this._witProcessDefinitionApi.editControl(createControl, payload.process.typeId, witLayout.workItemTypeRefName, group.id, control.id),
                                            `Edit control '${control.id}' in group '${group.id}' in page '${page.id}' in work item type '${witLayout.workItemTypeRefName}'.`);
                                    }
                                }
                                else {
                                    //create
                                    await Engine.Task(() => this._witProcessDefinitionApi.addControlToGroup(createControl, payload.process.typeId, witLayout.workItemTypeRefName, group.id),
                                        `Create control '${control.id}' in group '${group.id}' in page '${page.id}' in work item type '${witLayout.workItemTypeRefName}'.`);
                                }
                            }
                            catch (error) {
                                Utility.handleKnownError(error);
                                throw new ImportError(`Unable to add '${control.id}' control to group '${group.id}' in page '${page.id}' in '${witLayout.workItemTypeRefName}'. ${error}`);
                            }
                        }
                    }
                }
            }
        }
    }