Oracle CRM On Demand JavaScript API Developer's Guide > JavaScript API Code Samples >

Code Sample 1 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 and Next Step fields. The sample code also hides the Add button on the Contact related information applet.

// entry point for running custom code

oraclecrmod.onReady(function()

{

// 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();

var nextstep = oraclecrmod.getField("Next Step").getValue();

// validate custom business logic goes here based on field values retrieved

}

// 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();

}

});

Oracle CRM On Demand JavaScript API Developer's Guide, Release 38 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Legal Notices.