- work in progress -

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
titleConnect
'use strict';

// This function is registered on direct execution
api.registerExecution(onDirectExecute);

function onDirectExecute() {
    // Get the information system and the technical component by id
     var is = api.datamodel.findByTypeAndId('InformationSystem', 174);
    var tc = api.datamodel.findByTypeAndId('TechnicalComponent', 311);

      // Create a relation building block
    var relation = api.datamodel.create('Is2TcAssociation');
    
      //Connect Add both elements withto the relation object, this way they are connected to each other
      relation.connect(is, "informationSystem");
    relation.connect(tc, "technicalComponent");
} 
Code Block
titleDisconnect
'use strict';

// This function is registered on direct execution
api.registerExecution(onDirectExecute);
 
function onDirectExecute() {

	// The ids of the two elements to be disconnected
    var bfId = 24;
    var boId = 51;
  
	// We get all BMs related to the business function so we dondo not have to check all BMs
    var bf = api.datamodel.findByTypeAndId('BusinessFunction', bfId);
    var allBMs = bf.getRelatedObjects('businessMappings');
  
	// Print information to the log
    api.printLog('The business function is related to '+ allBMs.length + ' business mappings');
 
	// Loop over all BMs to find the one to delete 
    for (var index=0; index < allBMs.length; index++) {
        if(allBMs[index].getRelatedObject('businessFunction') &&
            allBMs[index].getRelatedObject('businessFunction').getId()== bfId &&
            allBMs[index].getRelatedObject('businessObject') &&
            allBMs[index].getRelatedObject('businessObject').getId()== boId &&
            !allBMs[index].getRelatedObject('informationSystem')&&
            !allBMs[index].getRelatedObject('businessUnit')&&
            !allBMs[index].getRelatedObject('businessProcess')&&
            !allBMs[index].getRelatedObject('product') &&
            !allBMs[index].getRelatedObject('itService')){

          		// When the BM is found its id is printed to the log and the element is removed
                api.printLog(allBMs[index].getId());          
                allBMs[index].remove();
        }
    }
}

...