Oracle CRM On Demand Desktop Customization Guide > Adding Custom Fields to Oracle CRM On Demand Desktop > Process of Adding Book Support to a New Top-Level Object >
Prefilling the Default Book on New Records
To set up default book prefilling on the form when a user creates a new record, complete the following procedure. For more information on book prefilling, see About Book Prefilling. To view a list of top-level objects that support books refer to Record Types That Support Books. After you complete this procedure, a default book for the object type is populated on the form when a user creates a new item. This task is a step in Process of Adding Book Support to a New Top-Level Object. To prefill the default book on new records
- Edit the business_logic.js file, and locate the create_ondemand_meta_scheme2() function.
- Insert the following code anywhere inside that function:
scheme.objects.get_object("TypeName").get_field("BookId")["initial_value_fn"] = prefill_book;
In this code, TypeName is the name of the object type for which you are setting up book prefilling, for example, Opportunity. After you add this code, a default book for the object type is populated on the form when a user creates a new item.
You can specify any top-level type name, such as Account, Contact, or Opportunity for TypeName. However, if you are defining book prefilling for an Activity type, then you must link the prefill_activity_book function and not the prefill_book function as follows:
scheme.objects.get_object("Activity").get_field("BookId")["initial_value_fn"] = prefill_activity_book;
- Add the prefill_book function and prefill_activity_owner functions inside the create_ondemand_meta_scheme2() function under the
//Defaulting comment:
function prefill_book(ctx, type_id) { type_id = type_id || ctx.item_ex.get_type(); var ownership_mode = od_helpers.get_ownership_mode(ctx, type_id); switch (ownership_mode) { case "book": var user_selected_book = od_helpers.get_ol_storage_rs_book(ctx, type_id); var book_id = user_selected_book != null ? user_selected_book.BookId : ""; if (!book_id) { var default_book = ctx.session.find_item("::DefaultsTypeDefaultBookPicklist", ctx.session.create_expression("Value", "eq", type_id)); book_id = default_book != null ? default_book.BookId : ""; } if(!book_id) { var defaults = helpers.get_defaults(ctx.session), user_default_book_name = defaults != null ? defaults.DefaultBookName : "", user_default_book = ctx.session.find_item("::DefaultsBookPicklist", ctx.session.create_expression("Label", "eq", user_default_book_name)); book_id = user_default_book != null ? user_default_book.Value : book_id; } if(od_helpers.book_can_contain_data(ctx, book_id)) return book_id; break; default: return ""; break; } } function prefill_activity_owner(ctx) { return prefill_owner(ctx, "Activity"); }
- Save the updated business_logic.js file.
.
|