Problem with creating node with multiple inport / outport

Hello,
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 = node.name;
	
	switch(label) {
  	  case "Workflow":
  		color = 'CadetBlue';
  	    break;
  	  case "Data":
  		color = 'SteelBlue';
  	    break;
  	case "Service":
  		color = 'Teal';
  		break;
  	default:
  		color = 'SteelBlue';
  	}
	
	self.linkDataArray.forEach(function(link) {
  		//output port definition
  			if(node.id == link.from){
  				outport++;
  				outport_lable = 'OUT ' + outport;
  				link.frompid = outport_lable;
  				var aNewOutputPort = makePort(outport_lable,false);
                listOfOutputPorts.push(aNewOutputPort);
  			}
  		});
	self.linkDataArray.forEach(function(link) {
  		//input port definition
  			if(node.id == link.to){
				inport++;
				inport_lable = 'IN ' + inport;
  					link.topid = inport_lable;
  					var aNewInputPort = makePort(inport_lable,true);
  	                listOfInputPorts.push(aNewInputPort);
  				}
      		});
  		
  		makeTemplate(label, color,
  				listOfInputPorts,
                listOfOutputPorts);
  		
  		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.

https://gojs.net/latest/intro/usingModels.html

Thanks @walter! That helps.