Code Sample 2 for Creating a Custom Button for Validation

The following sample code creates a custom button labeled Validate on the Opportunity Detail page. When the button is clicked, a validate function is called to validate the values of the Primary Revenue Amount field. The sample code also hides the Add button on the Contact related information applet.

// entry point for running custom code
oraclecrmod.onReady(function()
{

		// OPPORTUNITY VALIDATE EXAMPLE //
		// when on the Opportunity Detail page
		if(oraclecrmod.ctx.object == "Opportunity" && oraclecrmod.ctx.isDetailPage())
		{

				// define validate function
				function validate()
				{

					var revenue = oraclecrmod.getField("Primary Revenue Amount").getValue();
					// convert to currency string to number
					var number = Number(revenue.replace(/[^0-9\.]+/g, ""));
					// validate custom business logic goes here based on field values retrieved
					if (number > 0) {

						var alertStr = "Recommendation is to fill in the field(s):\n";
						alertStr += "Next Step\n\n";
						alertStr += "Based on the rule(s):\n";
						alertStr += "Revenue is greater than 0\n\n";
						alertStr += "For this record:\n";
						alertStr += "Revenue is: " + revenue;
						alert(alertStr); 

					}
				}

				// get the title bar
				titleBar = oraclecrmod.getTitleBar("OpportunityFormTB");
				// create the new Validate button
				button = oraclecrmod.createButton({
					id:"ValidateButton", 
					text:"Validate", 
					parent:titleBar

				});
				// associate the validate function with the button click event
				button.on("click", validate);
				// get the Add button and hide it
				oraclecrmod.getButton("BTN_TB_ContactRoleChildList_ContactRoleNewNav").hide();
		}

});