Oracle CRM On Demand Desktop Administration Guide > Code Listing for Updates to the Customization Package from Version 2.0 >

JavaScript Code Addition for the forms.js File


Insert the register_book_control(ctx, owner_ctrl) function at the end of the file, as described in Step a:

function register_book_control(ctx, owner_ctrl)
{
   var ownership_mode = ctx.security_descriptor.ownership_mode(),
      form = ctx.form,
      type = form.item.type_id,
      current_user_link = { "item_ex": ctx.item_ex, "with_id": helpers.get_current_user_id(ctx.session), "tag": "direct" },
      current_user_link_mvg = helpers.merge_contexts(current_user_link, { "tag": "mvg", "params": {"is_manual_operation": false} });

   if(!is_activity_subform(type))
   {
      ctx.validator.add_custom(util_validate_book_fab(ctx, ownership_mode), ["book_of_business"], "msg_book_is_required");
      if(owner_ctrl)
      {
         ctx.validator.add_custom(util_validate_owner_fab(ownership_mode), [owner_ctrl], "msg_owner_must_be_empty");
         ctx.validator.add_custom(util_validate_owner_and_book_fab(ctx, ownership_mode), [owner_ctrl, "book_of_business"], "msg_Specifying_both_Book_and_Owner_is_prohibited");
      }
   }
   var bs = new od_helpers.book_selector(ctx, {ctrl_edit: form.book_of_business, ctrl_btn: form.btn_book_select, mode: ownership_mode, context: "inspector"});   

   if(owner_ctrl)
      ctx.triggers.add_simple_trigger(on_owner_changed, ctx.item_ex.get_type(), "User", "direct", "created");   

   ctx.events.connect(form, "on_saving", function() {
      // clean-up fields
      switch(ownership_mode)
      {
         case "owner":
            if(ctx.item_ex.get_property("OwnerId") == null)
               ctx.linker.link(current_user_link);
            ctx.linker.link(current_user_link_mvg);
            book_clean_up();
         break;
         case "book":
            ctx.item_ex.set_property("OwnerId", null);
//            ctx.linker.unlink(current_user_link_mvg);
         break;      

      }
   });   

   ctx.events.connect(bs, "on_changed", function(book_id) {
      // populate/clean-up Owner
      if(ownership_mode == "mixed")
         if(book_id != "")
         {
            ctx.item_ex.set_property("OwnerId", null);
            ctx.linker.unlink(current_user_link_mvg);
         }
         else
         {
            if(!owner_ctrl)   // no link to User
               ctx.item_ex.set_property("OwnerId", current_user_link.with_id);
            else
            {
               ctx.linker.link(current_user_link);
               ctx.linker.link(current_user_link_mvg);
            }
         }
   });   

   function is_activity_subform(type)
   {
      return type == "Event" || type == "Task" || type == "Mail";
   }   

   function on_owner_changed(ctx, action_ctx)
   {
      var owner_id = action_ctx.with_id;
      if(ownership_mode == "mixed" && owner_id != null)
         book_clean_up();
   }   

   function book_clean_up()
   {
      ctx.item_ex.set_property("BookId", "");
      bs.refresh();
   }

   function util_validate_book_fab(ctx, ownership_mode)
   {
      return function(validation_ctx)
      {
         var book = validation_ctx.snapshot()["BookId"];
         if(ownership_mode == "book" && (book == null || book == ""))
         {
            return false;
         }
         else if(ownership_mode != "owner" && !od_helpers.book_can_contain_data(ctx, book))
         {
            validation_ctx.set_message("msg_book_cannot_contain_data", true);
            return false;
         }
         else if(ownership_mode == "book" && od_helpers.book_is_userbook(ctx, book))
         {
            validation_ctx.set_message("msg_book_must_be_custom", true);
            return false;
         }
         else
            return true;
      }
   }

   function util_validate_owner_fab(ownership_mode)
   {
      return function(validation_ctx)
      {
         var owner = validation_ctx.snapshot()["OwnerId"];
         return !(ownership_mode == "book" && owner != null)
      }
   }

   function util_validate_owner_and_book_fab(ctx, ownership_mode)
   {
      return function(validation_ctx)
      {
         var owner = validation_ctx.snapshot()["OwnerId"];
         if(ownership_mode == "mixed")
         {
            var book = validation_ctx.snapshot()["BookId"];
            if(owner != null && book != "" && book != null && !od_helpers.book_is_userbook(ctx, book))
               return false;
         }
         return true;
      }
   }}

Oracle CRM On Demand Desktop Administration Guide, Version 5.2 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Legal Notices.