Code Sample for a Custom Button That Updates a Record

The following code sample illustrates the use of the updateRecord() method to update an Account record when a button created with the createButton() method and labeled Test Update 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 updateRecord = function()
			{

				oraclecrmod.dataSvc.updateRecord("Account", {Name : "Account Name Update123"}, "AUDA-1HSXSB", callback);
			};
			var tb = oraclecrmod.getTitleBar("AccountFormTB");

			var bt = oraclecrmod.createButton({id:"TestUpdateBtn",text:"Test Update",parent:tb});


			bt.on("click",updateRecord);

		}

	}

);