Code Sample for a Read Operation on an Account Record

The following sample code is for a read operation to get details of an account and display them in the Description field on the Contact Edit page. A call is made to the readRecord() method to get the values for the Type and Location fields of the associated account.

// entry point for running custom code - only before the page loads
oraclecrmod.onLoad(function () {
	// CONTACT EXAMPLE //
	var contactCallback = function (request, response) {
		if (response.status == "OK") {
			var type = response.getFieldValue("Type");
			var location = response.getFieldValue("Location");
			//update the description field with account record info
			oraclecrmod.getField('Comment').setValue("This contact is created by the 
			account with type " + type + " and located at " + location);
		}
	}

	// when on the Contact new page
	if (oraclecrmod.ctx.object == "Contact" && oraclecrmod.ctx.isNewPage()) {
		//get the Account Id
		var acctId = oraclecrmod.getField("Account Id").getValue();
		if (acctId != null) {
			oraclecrmod.dataSvc.readRecord("Account", "Location,Type", {
 			  searchType: "rowId",
    				"rowId": acctId
			}, contactCallback);
		}
	}
});