Code Sample for a Custom Button That Creates a Record
The following code sample illustrates the use of the createRecord()
method to create an Account record with three fields, Location, Type,
and Description, when a button created with the createButton() method
and labeled Test Create
is clicked.
oraclecrmod.onReady(
function()
{
if(oraclecrmod.ctx.isObject("Account") && oraclecrmod.ctx.isDetailPage())
{
var callback = function(request,response)
{
var data = "Response Data: ";
var status = response.status;
var error = "Error message: "
if (status == "OK")
{
error += status;
}
else
{
error += response.errors;
}
var dataObj = response.data;
if (dataObj != null)
{
data += "Id = " + response.getRowId() + ", Mod Id = " + response.getModId();
}
else
{
data += "Data is Null";
}
alert(data + "\n" + status + "\n" + error);
};
var createRecord = function()
{
oraclecrmod.dataSvc.createRecord("Account", {Name : "Account Name Create123",Location : "Location Test", Type : "Customer", Description "Description Test"}, "", callback);
};
var tb = oraclecrmod.getTitleBar("AccountFormTB");
var bt = oraclecrmod.createButton({id:"TestCreateBtn",text:"Test
Create",parent:tb});
bt.on("click",createRecord);
}
}
);