Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Highlighted
Trusted Contributor.. Flavio Bianchi Trusted Contributor..
Trusted Contributor..
1098 views

Call Asset Manager 9.40 RESTful API from Service Manager 9.40

Hi,

I have created a Script Library in Service Manager to integrate with Asset Manager 9.40 through its backend RESTful API (RAQL)

 

Attached you can find the library where you need to configure at least your Asset Manager backend server address and a valid username and password.

 

Here are 3 example of use for (READ, UPDATE and INSERT) into AM from SM using my lib:

 

 

function testReadFromAM() {
	var table = "amAsset";
	var fields = "lAstId,Label,lModelId";
	var where = "Where AssetTag LIKE 'CPU00001%' AND lTenantId = 12345";
	
	var responseArray = lib.AmRestfulAPI.readFromAM(table, fields, where);
	var raLen = responseArray.length;
	print("Found " + raLen + " record(s)");
	
	// for every returned record
	for (i=0; i<raLen; ++i) {
		print("Record " + (i+1) );
		var record = responseArray[i];
		var recLen = record.length;

		// for every requested fields ( 3 in this example )
		for (u=0; u<recLen; ++u) {
			print("'"+record[u].name + "' = '" + record[u].value+"'");
		}
	}
}

testReadFromAM();
function testUpdateAM() {
	try {
		var table = "amAsset";
		var key = new Header("lAstId", "1234567");
		var fieldsToUpdate = new Array();
		
		fieldsToUpdate.push(new Header("Label", "myNewLabelValue"));
		
		print(lib.AmRestfulAPI.updateAM(table, key, fieldsToUpdate));
	} catch (ex ) {
		print("Error: " + ex);
	}
}

testUpdateAM();
function testInsertAM() {
	try {
		var table = "amAsset";
		var fieldToInsert = new Array();
	
		fieldToInsert.push(new Header("lModelId", "12345"));
		fieldToInsert.push(new Header("Label", "12345"));
		fieldToInsert.push(new Header("SerialNo", "ABC"));

		var lRecordId = lib.AmRestfulAPI.insertAM(table, fieldToInsert);
		print("Record created with id = " + lRecordId);
	} catch (ex ) {
		print("Error: " + ex);
	}	
}

testInsertAM();

 

Let me know if it helps and if you find any errors or improvements!

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.