Examples - Update Global Parameter

This Java code sample shows how to use the programmatic API to checkout and modify a MOVEit Automation global parameter.

Code Excerpts

The main body of the example defines a method called incrementCount() which utilizes the MOVEit Automation API to connect to an instance of MOVEit Automation, checkout the GlobalParameters section from the config, update the XML, and re-submit the section to MOVEit Automation using the modifyItem() method. The code below is looking for a global parameter called 'NumberSeq', which keeps track of a numeric sequence. The incrementCount() method should checkout the entire GlobalParameters section, load the XML into a DOM object, go to the 'NumberSeq' node within the XML, get the value of the node and increment it, update the XML with the new value, and finally update the MOVEit Automation config with the changes using modifyItem().

public boolean incrementCount() {
	MICentralAPI oAPI = new MICentralAPI();
	oAPI.setHost("localhost");
	oAPI.setUser("miadmin");
	oAPI.setPassword("password");
	if(!oAPI.connect()) {
		ShowMsg("Can't connect: " + oAPI.getErrorDescription());
		return false;
	}
      
	boolean bOK = false;
      
	ShowMsg("Central API Version: " + oAPI.getAPIVersion());
	ShowMsg("Central Version: " + oAPI.getCentralVersion());

	String ItemType = "GlobalParameters";
	String ItemID = "";
	// Checkout the entire GlobalParameters section
	String ItemXML = oAPI.checkoutItem(ItemType, ItemID);
	if(ItemXML!="") {
		// Parse the XML string into a Document object
		Document DocXML = MICUtils.parse_xml(ItemXML);
		// Get the node called NumberSeq
		NodeList Nodes = DocXML.getElementsByTagName("NumberSeq");
		if(Nodes.getLength()==1) {
			Node MyNode = Nodes.item(0);
			// Get the value of NumberSeq as an integer
			int Count = Integer.parseInt(MyNode.getTextContent());
			Count = Count + 1;
			// After incrementing the value, update the Document object
			MyNode.setTextContent(Integer.toString(Count));
			// Utility function to return the Document object as an XML string
			ItemXML = MICUtils.toString(DocXML);
			// Submit the modified XML back to MOVEit Automation
			bOK = oAPI.modifyItem(ItemType, ItemID, ItemXML);
			if(!bOK) {
				ShowMsg("Failed to modify item: " + oAPI.getErrorCode() + ": " + oAPI.getErrorDescription());
			}
		} else {
			ShowMsg("Couldn't find global parameter 'NumberSeq'.");
		}
	} else {
		ShowMsg("Failed to checkout global parameters: " + oAPI.getErrorCode() + ": " + oAPI.getErrorDescription());
	}
	
	return bOK;
	
}

We can call the method above from our Main() method. This assumes that the incrementCount method is defined within a Java Class called 'MICentralAPIExample'.

public static void main(String[] args) {
	MICentralAPIExample Central = new MICentralAPIExample();
	if(Central.incrementCount()) {
		Central.ShowMsg("Successfully updated global parameter 'NumberSeq'");
	}
}