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

Code Sample for a Custom Button That Creates a Task


The following sample code creates a custom button labeled Assign Next Step Task on the Opportunity Detail page. When the button is clicked, a function is called to open the Task Open page with appropriate values. The task can then be saved and used to follow up on the next step for the opportunity.

// entry point for running custom code

oraclecrmod.onReady(function()

{

// when on the Opportunity Detail page

if (oraclecrmod.ctx.object == "Opportunity" && oraclecrmod.ctx.isDetailPage()) {

// define createTask function

function createTask() {

var Id = oraclecrmod.getField("Id").getValue();

var oppName = oraclecrmod.getField("Name").getValue();

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

var desc = "Please follow up on the next step for this opportunity: " + nextstep;

var subject = "Follow up on next step for " + oppName;

var date1 = new Date();

date1.setDate(date1.getDate() + 2);

var dd = date1.getDate();

var mm = date1.getMonth()+1; // month starts at 0 e.g. Jan = 0

var y = date1.getFullYear();

var date1Formatted = mm + '/' + dd + '/' + y;

window.open("/OnDemand/user/TaskNew?OMRET0=OpportunityDetail%3fOpptyDetailForm.Id%3d" + Id + "&OMCR0=" + Id + "&OCTYPE=&OMTGT=TaskEditForm&OMTHD=ActivityNewNav&OMCBO=Opportunity&TaskEditForm.Due Date=" + encodeURIComponent(date1Formatted) + "&TaskEditForm.Comment=" + encodeURIComponent(desc) + "&TaskEditForm.Description=" + encodeURIComponent(subject), "_self");

} //createTask

// get the title bar

titleBar = oraclecrmod.getTitleBar("OpportunityFormTB");

// create the new TASK button

button = oraclecrmod.createButton({

id: "createTaskButton",

text: "Assign Next Step Task",

parent: titleBar

});

// associate the createTask function with the button click event

button.on("click", createTask);

}

});

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