User Tools

Site Tools


List Products

Summary

Below is an example demonstrating how to obtain a list of products in the database.

API Areas of Interest

Example

DB_List_Products.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	// Get the asset manager
	var oAssetMgr = App.getAssetMgr();
	// If the manager was not found
	if( !oAssetMgr ){
		// We are done...
		return;
	}
 
	// Get the top level asset container for products
	var oProductsTop = oAssetMgr.getProducts();
	// If we do not have the products container
	if( !oProductsTop ){
		// We are done...
		return;
	}
 
	// Define a variable for whether or not
	// we only want installed products
	var bInstalled = true;
 
	// Print the container name
	print( bInstalled ? "Installed" : "All", oProductsTop.getContainerName(), ":" );
 
	// Declare working variables
	var oIntermediate, oProduct;
	var nProducts;
 
	// Get the number of intermediate containers; alpha-numeric sorting
	var nIntermediates = oProductsTop.getNumChildContainers();
	// Iterate over all intermediate containers
	for( var i = 0; i < nIntermediates; i += 1 ){
		// Get the 'current' intermediate container
		oIntermediate = oProductsTop.getChildContainer( i );
		// Print the container name
		print( "+++++", oIntermediate.getContainerName(), "+++++" );
 
		// Get the number of product containers within the intermediate
		nProducts = oIntermediate.getNumChildContainers();
		// Iterate over all product containers
		for( var j = 0; j < nProducts; j += 1 ){
			// Get the 'current' product container
			oProduct = oIntermediate.getChildContainer( j );
			// If we only care about installed products,
			// and the 'current' one is not
			if( bInstalled && !oProduct.isInstalled ){
				// Next!!
				continue;
			}
 
			// Print the container name
			print( oProduct.getContainerName() );
		}		
	}
 
// Finalize the function and invoke
})();