Problem with creating node with multiple inport / outport

I am creating a graph where each node can have multiple inport / outport. I am using same mechanism to create each type of node. But only outport is not creating for one type of node (Data) where other two type (Workflow, Service) is working fine.

var outport = 0;
var inport = 0;
var listOfInputPorts = [];
var listOfOutputPorts = [];

//create nodes using model data
self.nodes.forEach(function(node) {
	label = node.label;
	name =;
	switch(label) {
  	  case "Workflow":
  		color = 'CadetBlue';
  	  case "Data":
  		color = 'SteelBlue';
  	case "Service":
  		color = 'Teal';
  		color = 'SteelBlue';
	self.linkDataArray.forEach(function(link) {
  		//output port definition
  			if( == link.from){
  				outport_lable = 'OUT ' + outport;
  				link.frompid = outport_lable;
  				var aNewOutputPort = makePort(outport_lable,false);
	self.linkDataArray.forEach(function(link) {
  		//input port definition
  			if( =={
				inport_lable = 'IN ' + inport;
  					link.topid = inport_lable;
  					var aNewInputPort = makePort(inport_lable,true);
  		makeTemplate(label, color,
  		listOfInputPorts = [];
        listOfOutputPorts = [];
  		outport = 0; 
  		inport = 0;

What am I doing inappropriate?
Thanks for your time.

It appears that you are mixing changing the model with changing the diagram. The model should hold all of the data needed to construct the diagram. You should not need to build new templates or add port GraphObjects while you are modifying model data. And model data should never have references to GraphObjects or Diagrams or DOM elements or Model instances.

If you do that before assigning Diagram.model, it’s just a matter of setting up all of the JavaSctipt Objects for the nodeDataArray and the linkDataArray.

If you are modifying a model that is already being displayed by a Diagram, you have to call Model methods to modify the data. Methods such as Model.set and Model.addArrayItem.

Thanks @walter! That helps.