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

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

}

}

});

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