You are on page 1of 62

include("sb_helpers.js", "sb_helpers"); include("form_helpers.js", "form_helpers"); include("raw_item_functions.js", "raw"); include("recurrence_processing.js", "recurrence_processing"); include("data_model.js", "data_model"); include("idle.js", "idle"); include("helpers.js", "helpers"); include("md5.

js", "md5"); var max_comments_length = 1500; var max_subject_length = 100; var max_body_length = 8000; var max_location_length = 100; var max_emailtoline_length = 1900; var max_attach_file_size = 3.5; //MB var archive_activity_days = 7; var long_mail_body_hex_string = "3C68746D6C3E3C686561643E3C6D65746120687474702D6 5717569763D22436F6E74656E742D547970652220636F6E74656E743D22746578742F68746D6C3B2 0636861727365743D7574662D38223E3C2F686561643E3C626F64793E202E2E2E3C2F626F64793E3 C2F68746D6C3E"; // Mail processing /** @class Helper class that resolves email addresses to items @constructor @param {session} session Session object provided by C++ @param {Array[String]} account_addresses Array of accounts addresses @param {Boolean} track_conversation_check If True, perform check by <b>T rackConversation</b> field @memberOf business_logic */ function mail_resolver(session, account_addresses, track_conversation_check) { /** Resolves email address to <b>Contact</b> @param {Array[String]} addresses Array of addresses to resolve @returns Resolved Contact, null if not resolved */ this.resolve_email_to_contact = function(addr) { var result = new Array(); if (addr != "" && addr != null) { var curr_user_id = helpers.get_current_user_id(session); var filter = session.create_criteria("and"); filter.add(session.create_expression("Email Address", "l ike", addr)); filter.add(session.create_expression("SiebelShared", "eq ", true)); helpers.for_each(session.find_items("Contact", filter), function(item) { if (track_conversation_check) { var filter = session.create_crit eria("and"); filter.add(session.create_expres sion("Contact Id", "eq", item.id)); filter.add(session.create_expres sion("Owner Id", "eq", curr_user_id)); filter.add(session.create_expres

sion("Save Email Flag", "eq", true)); if (session.find_item("Contact.C ontact_Sync_Owner", filter) == null) return; } result.push(item.id) }); } return result; } /** Resolves email addresses to <b>Contacts</b> @param {Array[String]} addresses Array of addresses to resolve @returns Array of resolved Contacts */ this.resolve_emails_to_contacts = function(addresses) { var result = new Array(); for (var index in addresses) result = result.concat(this.resolve_email_to_contact(add resses[index])); return helpers.stable_unique_id_array(session, result); } /** Resolves email addresses to <b>Employee</b> @param {String} addr Address to resolve @returns Resolved Employee, null if not resolved */ this.resolve_email_to_employee = function(addr) { var filter = session.create_criteria("and"); var result = new Array(); if (addr != "" && addr != null) { filter.add(session.create_expression("EMail Addr", "like ", addr)); helpers.for_each(session.find_items("Employee", filter), function(item) { result.push(item.id) }); if (result.length == 0 && account_addresses != null && i nclude.helpers.contains(account_addresses, addr)) result.push(include.helpers.get_current_user_id( session)); } return result; } /** Resolves <b>Contact</b> to IDs of <b>Accounts</b> @param contact Contact to resolve @param primary_only Resolve only primary Account @returns Array of resolved Contacts IDs */ this.resolve_contact_to_account_ids = function(contact_id, primary_only) { if (primary_only) { var contact = session.open_item(contact_id); return contact != null && contact["Account Id"] != null

? [contact["Account Id"]] : []; } else { var result = []; var c = session.create_criteria("and"); c.add(session.create_expression("ContactId", "eq", conta ct_id)); for (var enm = new Enumerator(session.find_items("Accoun t.Contact.Association", c)); !enm.atEnd(); enm.moveNext()) { result.push(enm.item().AccountId); } return result; } } /** Resolve email addresses to IDs of <b>Accounts</b> @param {Array[String]} addresses Array of addresses to resolve @returns Array of resolved Accounts IDs */ this.resolve_emails_to_account_ids = function(addresses) { var result = []; var contact_ids = this.resolve_emails_to_contacts(addresses); for (var key in contact_ids) result = result.concat(this.resolve_contact_to_account_i ds(contact_ids[key])); return include.helpers.stable_unique_id_array(session, result); } /** Resolve email addresses to IDs of <b>Opportunities</b> @param {Array[String]} addresses Array of addresses to resolve @returns Array of resolved Opportunities IDs */ this.resolve_emails_to_opportunity_ids = function(addresses) { var result = new Array(); var contact_ids = this.resolve_emails_to_contacts(addresses); for (var key in contact_ids) { var contact_id = contact_ids[key]; var assocs = session.find_items("Opportunity.Contact.Ass ociation", session.create_expression("ContactId", "eq", contact_id)); for (var enm = new Enumerator(assocs); !enm.atEnd(); enm .moveNext()) result.push(enm.item().OpportunityId); } return include.helpers.stable_unique_id_array(session, result); } } function employees_virtual_link(type) { this.type = type; this.link_to = "Employee"; this.tag = "mvg";

this.linked = function(ctx, spec_ctx) { var positions = ctx.linker.linked(helpers.merge_contexts(spec_ct x, { "link_to": "Position", "tag": "mvg" })); var result = { "values": [] } function f(id) { var position = ctx.session.open_item(id); if (position != null) { var primary_spec_ctx = { "item_ex": new data_mod el.std_item_ex(position), "link_to": "Employee", "tag": "direct", "submited": sp ec_ctx.submited }; var primary_employee = ctx.linker.linked(primary _spec_ctx); result.values = result.values.concat(primary_emp loyee.values); } } helpers.for_each(positions.values, f); return result; } } // GG: 7/2/13: SIA Upg: Replaced below function with SIA Vanilla file /* function create_contact_personal_address(mirrored) { var contact_link = mirrored ? new data_model.direct_link("Contact.Personal_Address", "Contac t", "BogusParentId") : new data_model.mirrored_direct_link("Contact", "Contact.Person al_Address", "BogusParentId", "Status", true); return contact_link; } */ function create_contact_personal_address(mirrored) { var contact_link = mirrored ? new data_model.mvg_link("Business_Address", "Contact", "Contac t.Business_Address.Association", "Business AddressId", "ContactId", null, "Statu s") : new data_model.mvg_link("Contact", "Business_Address", "Contac t.Business_Address.Association", "ContactId", "Business AddressId", "Status"); //contact_link.sales_book_ids = ["lookup:address"]; return contact_link; } /* function create_account_business_address_link(revert_statuses, mirrored) { var our_status = revert_statuses ? "StatusOnContact" : "Status"; var foreign_status = revert_statuses ? "Status" : "StatusOnContact"; var account_link = mirrored ? new data_model.direct_link("Account.Business_Address", "Accoun t", "BogusParentId") : new data_model.mirrored_direct_link("Account", "Account.Busine

ss_Address", "BogusParentId", our_status, true, foreign_status); return account_link; } */ function create_account_business_address_link(revert_statuses, mirrored) { var our_status = revert_statuses ? "StatusOnContact" : "Status"; var foreign_status = revert_statuses ? "Status" : "StatusOnContact"; var account_link = mirrored ? new data_model.mvg_link("Business_Address", "Account", "Accoun t.Business_Address.Association", "Business AddressId", "AccountId") : new data_model.mvg_link("Account", "Business_Address", "Accoun t.Business_Address.Association", "AccountId", "Business AddressId", our_status, foreign_status); //account_link.sales_book_ids = ["lookup:address"]; return account_link; } function contact_business_address_link() { var account_link = create_account_business_address_link(true); this.type = "Contact"; this.tag = "business"; helpers.merge_contexts(account_link, this); function stub_item_ex(id) { this.get_id = function() { return id; } } function create_stub_item_ex(ctx, spec_ctx) { var linked_account = ctx.linker.linked(helpers.merge_contexts(sp ec_ctx, { "link_to": "Account", "tag": "direct" })); return new stub_item_ex(linked_account.value); } function wrap_function(f) { function wrapper(ctx, spec_ctx) { var item_ex = create_stub_item_ex(ctx, spec_ctx); if (item_ex.get_id() != null) return f.call(this, ctx, helpers.merge_contexts( spec_ctx, { "item_ex": item_ex })); else return ({ "reason": "no_primary_account_selected " }); } return wrapper; } this.create this.remove this.linked this.submit = = = = wrap_function(this.create); wrap_function(this.remove); wrap_function(this.linked); wrap_function(this.submit);

this.revert = wrap_function(this.revert); this.revert_old_account = function(ctx, old_id) { return account_link.revert(ctx, { "item_ex": new stub_item_ex(ol d_id) }); } this.current_obj_filter = function(ctx, spec_ctx) { return this.filtering_support.get_filter(ctx, create_stub_item_e x(ctx, spec_ctx)); } } function update_primary_business_on_account_change(ctx, action_ctx) { var ra_ctx = helpers.get_restricted_context(action_ctx, ["item_ex", "sub mited"]); var new_ba = null; var account_id = action_ctx.with_id; var linked_business_addresses = ctx.linker.linked(helpers.merge_contexts (ra_ctx, helpers.get_restricted_context(ctx.data_model.contact_business_address_ link, ["link_to", "tag"]))); if (linked_business_addresses.count > 0 && account_id != null) { var account = ctx.session.open_item(action_ctx.with_id); if (account != null) { var primary_address = ctx.linker.linked(helpers.merge_co ntexts( helpers.get_restricted_context(ctx.data_model.ac count_business_address_primary_link, ["link_to", "tag"]), { "item_ex": new data_model.std_item_ex(account) , "submited": true })).value; if (helpers.contains_object_id(ctx.session, linked_busin ess_addresses.values, primary_address)) new_ba = primary_address; else new_ba = linked_business_addresses.values[0]; //GG: 7/2/13: SIA Upg - Inactivated Code /*if((ctx.form.company.value == null)||(ctx.form.company .value == "")) { ctx.form.company.value = account["Name"]; } */ } } ctx.linker.link(helpers.merge_contexts(ra_ctx, { "with_id": new_ba, "tag ": "primary-business" })); if (ctx.form != null) ctx.form.business_address_mvg.value = new_ba; } function revert_previous_business_on_account_change(ctx, action_ctx) { if (action_ctx.result.prev_value != null)

ctx.data_model.contact_business_address_link.revert_old_account( ctx, action_ctx.result.prev_value); } function update_account_to_related(ctx, action_ctx) { var static_ctx = { "item_ex": action_ctx.item_ex, "link_to": "Account", "tag": "direct", "submited": action_ctx.submited }; var account_id = null; if (action_ctx.with_id != null) { var with_item = ctx.session.open_item(action_ctx.with_id); var with_item_ex = new data_model.std_item_ex(with_item, { "use_ snapshot": false }); account_id = ctx.linker.linked(helpers.merge_contexts(static_ctx , { "item_ex": with_item_ex, "submited": true })).value; if (account_id != null && ctx.session.open_item(account_id) == n ull) account_id = null; } ctx.linker.link(helpers.merge_contexts(static_ctx, { "with_id": account_ id })); } function update_account_to_related_if_blank(ctx, action_ctx) { if (action_ctx.with_id != null && ctx.linker.linked({ "item_ex": action_ ctx.item_ex, "link_to": "Account", "tag": "direct", "submited": action_ctx.submi ted }).value == null) update_account_to_related(ctx, action_ctx); } function business_address_created_deleted_submited_trigger(ctx, action_ctx) { var account_ex; if (action_ctx.type == "Account") { account_ex = action_ctx.item_ex; } else { var primary_account = ctx.linker.linked(helpers.merge_contexts(a ction_ctx, { "link_to": "Account", "tag": "direct" })); var account_ex = { "get_id": function() { return primary_account.value }, "get_type": function() { return "Account" } } } var contacts; var contact_params = { "link_to": ctx.data_model.contact_business_address_link.link_to, "primary_tag": ctx.data_model.contact_business_address_primary_l ink.tag, "mvg_tag": ctx.data_model.contact_business_address_link.tag } var account_params = { "link_to": ctx.data_model.account_business_address_link.link_to, "primary_tag": ctx.data_model.account_business_address_primary_l ink.tag,

"mvg_tag": ctx.data_model.account_business_address_link.tag } function add(operation) { if (contacts == null) contacts = ctx.linker.linked(helpers.merge_contexts(acti on_ctx, { "item_ex": account_ex, "link_to": "Contact", "tag": "direct-mirrored" })); ctx.primary_updater.add(contacts.values, helpers.merge_contexts( contact_params, { "operation": operation })); ctx.primary_updater.add([account_ex.get_id()], helpers.merge_con texts(account_params, { "operation": operation })); } switch (action_ctx.operation) { case "created": case "removed": if (action_ctx.submited) add(action_ctx.operation); break; case "submit": if (action_ctx.notification_params.created.length) add("created"); if (action_ctx.notification_params.removed.length) add("removed"); break; } } function create_siebel_meta_scheme2() { // VT: dialog show triggers require form handlers in options include("forms.js", "forms"); var scheme = new data_model.data_model(); scheme.dasl_field_product_prefix = "sbl%20"; var open_left = true; var open_right = false; function add_mvg_link(left_type, right_type, left_obj_primary, right_obj _primary, assoc_type, left_link, right_link, left_assoc_status, right_assoc_status, left_objs_view_ids, right_objs_view_ids, left_primary_refresh_required, right_primary_refre sh_required, assoc_left_link_refresh_required, assoc_right_link _refresh_required, open_where) { var result = {}; result.mvg1 = new data_model.mvg_link(left_type, right_type, ass oc_type, left_link, right_link, right_assoc_status, left_assoc_status); result.mvg2 = new data_model.mvg_link(right_type, left_type, ass oc_type, right_link, left_link, left_assoc_status, right_assoc_status); scheme.links.add_link(result.mvg1); scheme.links.add_link(result.mvg2);

scheme.objects.get_object(assoc_type).get_field(left_link).set_l ink(left_type, assoc_left_link_refresh_required); scheme.objects.get_object(assoc_type).get_field(right_link).set_ link(right_type, assoc_right_link_refresh_required); result.mvg1.sales_book_ids = right_objs_view_ids; result.mvg2.sales_book_ids = left_objs_view_ids; if (open_where == open_left) scheme.triggers.add_trigger(new data_model.show_mvg_on_f orm_trigger(result.mvg1)); else if (open_where == open_right) scheme.triggers.add_trigger(new data_model.show_mvg_on_f orm_trigger(result.mvg2)); if (left_obj_primary != null) { result.primary1 = new data_model.direct_link(left_type, right_type, left_obj_primary); result.primary1.sales_book_ids = right_objs_view_ids; scheme.links.add_link(result.primary1); scheme.triggers.add_simple_trigger(data_model.update_pri mary_trigger, left_type, right_type, result.mvg1.tag, "created"); scheme.triggers.add_simple_trigger(data_model.update_pri mary_trigger, left_type, right_type, result.mvg1.tag, "removed"); scheme.objects.get_object(left_type).get_field(left_obj_ primary).set_link(right_type, left_primary_refresh_required); scheme.triggers.add_simple_trigger(idle.update_primary_o n_submit_trigger, right_type, left_type, result.mvg2.tag, "submit"); scheme.triggers.add_simple_trigger(idle.update_primary_o n_created_removed_trigger, right_type, left_type, result.mvg2.tag, "created"); scheme.triggers.add_simple_trigger(idle.update_primary_o n_created_removed_trigger, right_type, left_type, result.mvg2.tag, "removed"); } if (right_obj_primary != null) { result.primary2 = new data_model.direct_link(right_type, left_type, right_obj_primary); result.primary2.sales_book_ids = left_objs_view_ids; scheme.links.add_link(result.primary2); scheme.triggers.add_simple_trigger(data_model.update_pri mary_trigger, right_type, left_type, result.mvg2.tag, "created"); scheme.triggers.add_simple_trigger(data_model.update_pri mary_trigger, right_type, left_type, result.mvg2.tag, "removed"); scheme.objects.get_object(right_type).get_field(right_ob j_primary).set_link(left_type, right_primary_refresh_required); scheme.triggers.add_simple_trigger(idle.update_primary_o n_submit_trigger, left_type, right_type, result.mvg1.tag, "submit"); scheme.triggers.add_simple_trigger(idle.update_primary_o n_created_removed_trigger, left_type, right_type, result.mvg1.tag, "created"); scheme.triggers.add_simple_trigger(idle.update_primary_o n_created_removed_trigger, left_type, right_type, result.mvg1.tag, "removed"); } return result;

} function add_direct_link(from_type, to_type, link_field, required_link, view_ids, refresh_required, status, primary_on_parent, cp_open_on_parent) { var result = {}; result.direct = new data_model.direct_link(from_type, to_type, l ink_field); result.direct.sales_book_ids = view_ids; scheme.links.add_link(result.direct); scheme.objects.get_object(from_type).get_field(link_field).set_l ink(to_type, refresh_required); if (status != null) { result.mvg = new data_model.mirrored_direct_link(to_type , from_type, link_field, status, required_link); scheme.links.add_link(result.mvg); } if (primary_on_parent != null) { //result.primary_link = new data_model.direct_link(to_ty pe, from_type, link_field); //scheme.links.add_link(result.primary_link); result.primary1 = new data_model.direct_link(to_type, fr om_type, primary_on_parent); scheme.links.add_link(result.primary1); scheme.triggers.add_simple_trigger(data_model.update_pri mary_trigger, to_type, from_type, "mvg", "created"); scheme.triggers.add_simple_trigger(data_model.update_pri mary_trigger, to_type, from_type, "mvg", "removed"); } if (cp_open_on_parent) scheme.triggers.add_trigger(new data_model.show_child_on _form_trigger(result.direct)); return result; } function deny_primary_delete(mvg_link) { scheme.triggers.add_simple_trigger(data_model.deny_primary_delet e_trigger, mvg_link.type, mvg_link.link_to, mvg_link.tag, "removing"); } // Common scheme.triggers.add_simple_trigger(data_model.perform_operation_from_not ification_trigger, null, null, null, "link"); scheme.triggers.add_simple_trigger(data_model.perform_operation_from_not ification_trigger, null, null, null, "unlink"); function on_new_created(ctx, action_ctx) { with (action_ctx.notification_params) { if (created_from_ctx_type == "std") { initial_links.push({ "with_id": action_ctx.item_

ex.get_id(), "tag": "mvg" }); initial_links.push({ "with_id": action_ctx.item_ ex.get_id(), "tag": "direct" }); } } } scheme.triggers.add_simple_trigger(on_new_created, null, null, null, "ne w_created"); function prefill_account(ctx, action_ctx) { var account = ctx.linker.linked({ "item_ex": action_ctx.item_ex, "link_to": "Account", "tag": "direct", "submited": action_ctx.submited }); if (account.count > 0) { with (action_ctx.notification_params["initial_links"]) { push({ "with_id": account.values[0], "tag": "dir ect" }); push({ "with_id": account.values[0], "tag": "mvg " }); } } } scheme.triggers.add_simple_trigger(prefill_account, "Opportunity", "Acti on", null, "new_created"); scheme.triggers.add_simple_trigger(prefill_account, "Opportunity", "Cont act", null, "new_created"); scheme.triggers.add_simple_trigger(prefill_account, "Contact", "Opportun ity", null, "new_created"); function prefill_currency(ctx, action_ctx) { var currency = ctx.linker.linked({ "item_ex": action_ctx.item_ex , "link_to": "Currency", "tag": "direct", "submited": action_ctx.submited }); if (currency.count > 0) action_ctx.notification_params["initial_links"].push({ " with_id": currency.values[0], "tag": "direct" }); } scheme.triggers.add_simple_trigger(prefill_currency, "Account", "Opportu nity", null, "new_created"); scheme.triggers.add_simple_trigger(prefill_currency, "Opportunity", "Opp ortunity.Opportunity_Product", null, "new_created"); //GG : 7/21/2011: Added for Default Currency scheme.triggers.add_simple_trigger(prefill_currency, "Opportunity", "Opp ortunity.Revenue", null, "new_created"); //MVG Links var account_territory = add_mvg_link("Account", "Assignment_Group", "Primary Territory I d", null, "Account.Assignment_Group.Association", "AccountId" , "Assignment GroupId", null, "AssignmentGroupStatus", null, null, false, false, false, false, open_left); deny_primary_delete(account_territory.mvg1); account_territory.mvg1.dialog_template_params = { "dialog_caption": "#obj_account_territory_plural", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "#head_associations_territories",

"associations_view_id": "territories:mvg", "primary_selector_display_format": ":[:(Name):]" } var account_contact = add_mvg_link("Account", "Contact", null, "Account Id", "Account.Contact.Association", "AccountId", "ContactId", "AccountStatus", "ContactAssocStatus", ["lookup:accounts"], ["lookup:contacts"], false, true, false, false, open_right); account_contact.mvg2.dialog_template_params = { "dialog_caption": "#obj_contact_account_plural", "autocomplete_display_format": ":[:(Name):] - :[:(Location):]", "associations_view_caption": "#head_associations_accounts", "associations_view_id": "accounts:mvg", "associations_view_source_type": "joint", "associations_view_source_name": "AccountJointContact", "primary_selector_display_format": ":[:(Name):] - :[:(Location): ]" } // AKY, 28060211, Addind this for Making Account field required on Conta ct form as suggestted by Artem //account_contact.primary2.sales_book_ids = ["lookup:accounts"]; var account_to_contact_direct_mirrored = new data_model.mirrored_direct_ link(account_contact.primary2.link_to, account_contact.primary2.type, account_co ntact.primary2.field); account_to_contact_direct_mirrored.tag = "direct-mirrored"; scheme.links.add_link(account_to_contact_direct_mirrored); var account_industry = add_mvg_link("Account", "Industry", "Primary Industry Id", null, "Account.Industry.Association", "AccountId", "IndustryId", null, "IndustryStatus", null, null, false, false, false, false, open_left); account_industry.mvg1.dialog_template_params = { "dialog_caption": "#obj_account_industry_plural", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "#head_associations_industry", "associations_view_id": "industries:mvg", "primary_selector_display_format": ":[:(Name):]" } var account_position = add_mvg_link("Account", "Position", "Primary Position Id", null, "Account.Position.Association", "AccountId", "PositionId", null, "PositionStatus", null, null, false, false, false, false, open_left); deny_primary_delete(account_position.mvg1); account_position.mvg1.dialog_template_params = { "dialog_caption": "#obj_mvg_account_team_caption", "autocomplete_display_format": ":[:(First Name) :]:[:(Last Name) :]", "associations_view_caption": "#head_associations_positions", "associations_view_id": "positions:mvg", "primary_selector_display_format": ":[:(First Name) :]:[:(Last N ame):]" } var contact_position =

add_mvg_link("Contact", "Position", "Primary Position Id", null, "Contact.Position.Association", "Contac tId", "PositionId", null, "PositionStatus", null, null, false, false, false, false, open_left); deny_primary_delete(contact_position.mvg1); contact_position.mvg1.dialog_template_params = { "dialog_caption": "#obj_mvg_contact_team_caption", "autocomplete_display_format": ":[:(First Name) :]:[:(Last Name) :]", "associations_view_caption": "#head_associations_positions", "associations_view_id": "positions:mvg", "primary_selector_display_format": ":[:(First Name) :]:[:(Last N ame):]" } var activity_contacts = add_mvg_link("Action", "Contact", "Primary Contact Id", null, "Action.Contact.Association", "ActionId", "ContactI d", "ActionAssocStatus", "ContactStatus", null, ["lookup:contacts"], false, false, false, false, open_left); activity_contacts.mvg1.dialog_template_params = { "dialog_caption": "#obj_activity_contact_plural", "autocomplete_display_format": ":[:(DisplayName):]", "associations_view_caption": "#head_associations_contacts", "associations_view_id": "contacts:mvg", "associations_view_source_type": "joint", "associations_view_source_name": "ActionJointContact", "primary_selector_display_format": ":[:(DisplayName):]" } var activity_employee = add_mvg_link("Action", "Employee", "Primary Owner Id", null, "Action.Employee.Association", "ActionId", "Employe eId", null, "EmployeeStatus", null, null, true, false, false, false, open_left); deny_primary_delete(activity_employee.mvg1); activity_employee.mvg1.dialog_template_params = { "dialog_caption": "#obj_activity_employee_plural", "autocomplete_display_format": ":[:(First Name) :]:[:(Last Name) :]", "associations_view_caption": "#head_associations_employees", "associations_view_id": "users:mvg", "primary_selector_display_format": ":[:(First Name) :]:[:(Last N ame):]" } var opportunity_territiry = add_mvg_link("Opportunity", "Assignment_Group", "Primary Territo ry Id", null, "Opportunity.Assignment_Group.Association", "Opp ortunityId", "Assignment GroupId", null, "AssignmentGroupStatus", null, null, false, false, false, false, open_left); deny_primary_delete(opportunity_territiry.mvg1); opportunity_territiry.mvg1.dialog_template_params = { "dialog_caption": "#obj_opportunity_territory_plural",

"autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "#head_associations_territories", "associations_view_id": "territories:mvg", "primary_selector_display_format": ":[:(Name):]" } var opportunity_contact = add_mvg_link("Opportunity", "Contact", null, null, "Opportunity.Contact.Association", "OpportunityI d", "ContactId", "OpportunityStatus", "ContactAssocStatus", null, null, false, false, false, false, open_left); opportunity_contact.mvg1.dialog_template_params = { "dialog_caption": "#obj_opportunity_contact_plural", "autocomplete_display_format": ":[:(DisplayName):]", "associations_view_caption": "#head_associations_contacts", "associations_view_id": "contacts:mvg", "associations_view_source_type": "joint", "associations_view_source_name": "OpportunityJointContact", "primary_selector_display_format": ":[:(DisplayName):]" } opportunity_contact.mvg2.dialog_template_params = { "dialog_caption": "#obj_contact_opportunity_plural", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "#head_associations_opportunities", "associations_view_id": "opportunities:mvg", "associations_view_source_type": "joint", "associations_view_source_name": "OpportunityJointContact" } var opportunity_organization = add_mvg_link("Opportunity", "Internal_Division", "Primary Organi zation Id", null, "Opportunity.Internal_Division.Association", "Op portunityId", "Internal DivisionId", null, "InternalDivisionStatus", null, null, false, false, false, false, open_left); deny_primary_delete(opportunity_organization.mvg1); opportunity_organization.mvg1.dialog_template_params = { "dialog_caption": "#obj_opportunity_organization_plural", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "#head_associations_organizations", "associations_view_id": "organizations:mvg", "primary_selector_display_format": ":[:(Name):]" } var opportunity_sales_team = add_mvg_link("Opportunity", "Position", "Primary Position Id", n ull, "Opportunity.Position.Association", "Opportunity Id", "PositionId", null, "PositionStatus", null, null, false, false, false, false, open_left); deny_primary_delete(opportunity_sales_team.mvg1); opportunity_sales_team.mvg1.dialog_template_params = { "dialog_caption": "#obj_mvg_sales_team_caption", "autocomplete_display_format": ":[:(First Name) :]:[:(Last Name) :]", "associations_view_caption": "#head_associations_positions", "associations_view_id": "positions:mvg",

"primary_selector_display_format": ":[:(First Name) :]:[:(Last N ame):]" } add_mvg_link("Employee", "Position", "Primary Position Id", "Primary Emp loyee Id", "Employee.Position.Association", "EmployeeId", " PositionId", null, null, null, null, false, false, false, false); //new MVGs - Jan-2013 var opportunity_channel_partner = add_mvg_link("Opportunity", "Account", "Partner Id", null, "Opportunity_CP.Account.Association", "OpportunityId", "ChannelPa rtnerId", null, "ChannelPartnerStatus", null, null, false, false, false, false, null); deny_primary_delete(opportunity_channel_partner.mvg1);//optional opportunity_channel_partner.mvg1.tag = "mvg_channel" opportunity_channel_partner.mvg2.tag = "mvg_channel" opportunity_channel_partner.primary1.tag = "direct_channel" opportunity_channel_partner.mvg1.dialog_template_params = { "dialog_caption": "Contractors/Partners", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "Related Contractors/Partners", "associations_view_id": "channel_partner:mvg", "primary_selector_display_format": ":[:(Name):]", "associations_view_source_type": "joint", "associations_view_source_name": "OpportunityJointAccount" } */ /* //Beginning of the block Partners MVG var opportunity_channel_partner = {}; opportunity_channel_partner.mvg1 = new data_model.mvg_link("Opportunity" , "Account", "Opportunity_CP.Account.Association", "OpportunityId", "ChannelPart nerId", "ChannelPartnerStatus", null); opportunity_channel_partner.mvg2 = new data_model.mvg_link("Account", "O pportunity", "Opportunity_CP.Account.Association", "ChannelPartnerId", "Opportun ityId", null, "ChannelPartnerStatus"); scheme.links.add_link(opportunity_channel_partner.mvg1); scheme.links.add_link(opportunity_channel_partner.mvg2); scheme.objects.get_object("Opportunity_CP.Account.Association").get_fiel d("OpportunityId").set_link("Opportunity", false); scheme.objects.get_object("Opportunity_CP.Account.Association").get_fiel d("ChannelPartnerId").set_link("Account", false); opportunity_channel_partner.mvg1.tag = "mvg_channel" opportunity_channel_partner.mvg2.tag = "mvg_channel" opportunity_channel_partner.mvg1.dialog_template_params = { "dialog_caption": "Contractors/Partners", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "Related Contractors/Partners", "associations_view_id": "channel_partner:mvg", "primary_selector_display_format": ":[:(Name):]", "associations_view_source_type": "joint", "associations_view_source_name": "OpportunityJointAccount" }

opportunity_channel_partner.primary1 = new data_model.direct_link("Oppor tunity", "Account", "Partner Id"); scheme.links.add_link(opportunity_channel_partner.primary1); opportunity_channel_partner.primary1.tag = "direct_channel" scheme.triggers.add_simple_trigger(data_model.create_update_primary_trig ger({ "primary_tag": opportunity_channel_partner.primary1.tag }), "Opportunity", "Account", opportunity_channel_partner.mvg1.tag, "created"); scheme.triggers.add_simple_trigger(data_model.create_update_primary_trig ger({ "primary_tag": opportunity_channel_partner.primary1.tag }), "Opportunity", "Account", opportunity_channel_partner.mvg1.tag, "removed"); scheme.triggers.add_simple_trigger(idle.update_primary_on_submit_trigger , "Account", "Opportunity", opportunity_channel_partner.mvg2.tag, "submit"); scheme.triggers.add_simple_trigger(idle.update_primary_on_created_remove d_trigger, "Account", "Opportunity", opportunity_channel_partner.mvg2.tag, "crea ted"); scheme.triggers.add_simple_trigger(idle.update_primary_on_created_remove d_trigger, "Account", "Opportunity", opportunity_channel_partner.mvg2.tag, "remo ved"); deny_primary_delete(opportunity_channel_partner.mvg1); //End of the block Partners MVG /* var opportunity_competitor = add_mvg_link("Opportunity", "Account", "Primary Competitor Id", null, "Opportunity_C.Account.Association", "OpportunityId", "Competitor Id", null, "CompetitorStatus", null, null, false, false, false, false, null); deny_primary_delete(opportunity_competitor.mvg1);//optional opportunity_competitor.mvg1.tag = "mvg_compet" opportunity_competitor.mvg2.tag = "mvg_compet" opportunity_competitor.primary1.tag = "direct_compet" opportunity_competitor.mvg1.dialog_template_params = { "dialog_caption": "Competitors", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "Related Competitors", "associations_view_id": "competitor:mvg", "primary_selector_display_format": ":[:(Name):]", "associations_view_source_type": "joint", "associations_view_source_name": "OpportunityJointAccount_C" } */ //Beginning of the block Competitor MVG var opportunity_competitor = {}; opportunity_competitor.mvg1 = new data_model.mvg_link("Opportunity", "Ac count", "Opportunity_C.Account.Association", "OpportunityId", "CompetitorId", "C ompetitorStatus", null); opportunity_competitor.mvg2 = new data_model.mvg_link("Account", "Opport unity", "Opportunity_C.Account.Association", "CompetitorId", "OpportunityId", nu ll, "CompetitorStatus"); scheme.links.add_link(opportunity_competitor.mvg1); scheme.links.add_link(opportunity_competitor.mvg2); scheme.objects.get_object("Opportunity_C.Account.Association").get_field ("OpportunityId").set_link("Opportunity", false); scheme.objects.get_object("Opportunity_C.Account.Association").get_field ("CompetitorId").set_link("Account", false); opportunity_competitor.mvg1.tag = "mvg_compet"

opportunity_competitor.mvg2.tag = "mvg_compet" opportunity_competitor.mvg1.dialog_template_params = { "dialog_caption": "Competitors", "autocomplete_display_format": ":[:(Name):]", "associations_view_caption": "Related Competitors", "associations_view_id": "competitor:mvg", "primary_selector_display_format": ":[:(Name):]", "associations_view_source_type": "joint", "associations_view_source_name": "OpportunityJointAccount_C" } opportunity_competitor.primary1 = new data_model.direct_link("Opportunit y", "Account", "Primary Competitor Id"); scheme.links.add_link(opportunity_competitor.primary1); opportunity_competitor.primary1.tag = "direct_compet" scheme.triggers.add_simple_trigger(data_model.create_update_primary_trig ger({ "primary_tag": opportunity_competitor.primary1.tag }), "Opportunity", "Acc ount", opportunity_competitor.mvg1.tag, "created"); scheme.triggers.add_simple_trigger(data_model.create_update_primary_trig ger({ "primary_tag": opportunity_competitor.primary1.tag }), "Opportunity", "Acc ount", opportunity_competitor.mvg1.tag, "removed"); scheme.triggers.add_simple_trigger(idle.update_primary_on_submit_trigger , "Account", "Opportunity", opportunity_competitor.mvg2.tag, "submit"); scheme.triggers.add_simple_trigger(idle.update_primary_on_created_remove d_trigger, "Account", "Opportunity", opportunity_competitor.mvg2.tag, "created") ; scheme.triggers.add_simple_trigger(idle.update_primary_on_created_remove d_trigger, "Account", "Opportunity", opportunity_competitor.mvg2.tag, "removed") ; deny_primary_delete(opportunity_competitor.mvg1); //End of the block Competitor MVG //Direct Links var currency = add_direct_link("Account", "Currency", "Currency Code", f alse, ["lookup:currencies"], true); add_direct_link("Account.Account_Note", "Account", "Account Id", true, n ull, false, "NoteStatus", null, true); add_direct_link("Account.Account_Note", "Employee", "Created By", true, null, false); add_direct_link("Contact.Contact_Note", "Contact", "Contact Id", true, n ull, false, "NoteStatus", null, true); add_direct_link("Contact.Contact_Note", "Employee", "Created By", true, null, false); add_direct_link("Action", "Account", "Account Id", false, ["lookup:accou nts"], true, "ActionStatus"); add_direct_link("Action", "Opportunity", "Opportunity Id", false, ["look up:opportunities"], true, "ActionStatus"); add_direct_link("Attachment", DUStatus") add_direct_link("Attachment", se, "DUStatus") add_direct_link("Attachment", "DUStatus") add_direct_link("Attachment", "Action", "ParentId", true, null, false, " "Opportunity", "ParentId", true, null, fal "Account", "ParentId", true, null, false, "Contact", "ParentId", true, null, false,

"DUStatus") add_direct_link("Opportunity", "Account", "Account Id", false, ["lookup: accounts"], true, "OpportunityStatus"); add_direct_link("Opportunity", "Currency", "Currency Code", false, null, true); add_direct_link("Opportunity.Opportunity_Product", "Internal_Product", " Product Id", true, ["lookup:products"], false, null); add_direct_link("Opportunity.Opportunity_Product", "Opportunity", "Bogus ParentId", true, null, false, "ProductStatus", null, true); add_direct_link("Opportunity.Opportunity_Product", "Currency", "Currency Code", false, null, false); add_direct_link("Opportunity.Opportunity_Note", "Opportunity", "Opportun ity Id", true, null, false, "NoteStatus", null, true); add_direct_link("Opportunity.Opportunity_Note", "Employee", "Created By" , true, null, false); //ArtemP added on 6/24 add_direct_link("Opportunity.Revenue", "Opportunity", "BogusParentId", t rue, null, false, "RevenueStatus"); add_direct_link("Opportunity.Revenue", "Admin_Product_Line", "Product Li ne Id", true, null, false, null); // GG 7/21/2011 : Added for Default Currency add_direct_link("Opportunity.Revenue", "Currency", "Currency Code", fals e, null, false); // Selectors options var online_min_input_pattern = function(value) { return value.replace(/[* ]/g, ''); }; scheme.objects.get_object("Account").selectors_options = { "source": { "caption": "obj_account_plural", "view_id": "accounts:salesbook", "search_by": ["Name"], "online": { "like_template": "*{keyword}*", 'min_input_length': 3, 'min_input_pattern': online_min_input_pattern, 'min_input_message': 'msg_onlookup_less_kw_lengt h_only_letters_or_digits' } } }; scheme.objects.get_object("Assignment_Group").selectors_options = { "source": { "caption": "obj_territory_plural", "view_id": "territories:salesbook", "search_by": ["Name"], "allow_new": false } }; scheme.objects.get_object("Contact").selectors_options = { "source": { "caption": "obj_contact_plural", "view_id": "contacts:salesbook", "image": "type_image:Contact:16", "and_filter_fn": function(ctx) { return ctx.session.crea te_expression("SiebelShared", "eq", true); }, "search_by": ["First Name", "Last Name"],

"keywords_to_field": "DisplayName", "online": { "view_id": "contacts:salesbook", "like_template": "*{keyword}*", "and_filter_fn": function(ctx) { return ctx.sess ion.empty_criteria; }, "fields": [ { "name": "SiebelShared", "initial_value": true } ], 'min_input_length': 3, 'min_input_pattern': online_min_input_pattern, 'min_input_message': 'msg_onlookup_less_kw_lengt h_only_letters_or_digits' } } }; scheme.objects.get_object("Currency").selectors_options = { "source": { "caption": "obj_Currency_plural", "view_id": "currencies:salesbook", "search_by": ["ShortName", "Name"], "allow_new": false } }; scheme.objects.get_object("Employee").selectors_options = { "source": { "caption": "obj_employee_plural", "view_id": "employees:salesbook", "search_by": ["First Name", "Last Name"], "display_format": ":[:(Login Name):]", "allow_new": false } }; scheme.objects.get_object("Industry").selectors_options = { "source": { "caption": "obj_industry_plural", "view_id": "industries:salesbook", "search_by": ["Name"], "allow_new": false } }; scheme.objects.get_object("Internal_Division").selectors_options = { "source": { "caption": "obj_organization_plural", "view_id": "organizations:salesbook", "search_by": ["Name"], "allow_new": false } }; scheme.objects.get_object("Admin_Product_Line").selectors_options = { "source": { "caption": "obj_admin_product_line_plural", "view_id": "product_line:salesbook", "search_by": ["Name"], "allow_new": false } };

scheme.objects.get_object("Internal_Product").selectors_options = { "source": { "caption": "obj_internal_product_plural", "view_id": "products:salesbook", "search_by": ["Name"], "allow_new": false, "online": { "like_template": "*{keyword}*", 'min_input_length': 3, 'min_input_pattern': online_min_input_pattern, 'min_input_message': 'msg_onlookup_less_kw_lengt h_only_letters_or_digits' } } }; scheme.objects.get_object("Opportunity").selectors_options = { "source": { "caption": "obj_opportunity_plural", "view_id": "opportunities:salesbook", "search_by": ["Name"], "online": { "like_template": "*{keyword}*", 'min_input_length': 3, 'min_input_pattern': online_min_input_pattern, 'min_input_message': 'msg_onlookup_less_kw_lengt h_only_letters_or_digits' } } }; scheme.objects.get_object("Position").selectors_options = { "source": { "caption": "obj_position_plural", "view_id": "positions:salesbook", "search_by": ["Name", "First Name", "Last Name"], "display_format": ":[:(First Name) :]:[:(Last Name):]", "allow_new": false } }; //Triggers helpers.for_each(["Opportunity", "Account", "Contact", "Action", "Mail", "Event", "Task"], function(type){ scheme.triggers.add_simple_trigger(form_helpers.native_show, nul l, type, null, "show"); scheme.triggers.add_simple_trigger(form_helpers.native_show, nul l, type, null, "cp_show"); }); with (scheme.triggers) { add_simple_trigger(form_helpers.create_dialog_show("General Ad dress Details Dlg", { "form_handler": forms.address_form, "dialog_cache_key_form at": "{dialog_id}/{link_to}/{tag}" }), null, "Business_Address", null, "show"); //add_simple_trigger(form_helpers.create_dialog_show("General Ad dress Details Dlg", { "form_handler": forms.address_form }), null, "Account.Busi ness_Address", null, "show"); //add_simple_trigger(form_helpers.create_dialog_show("Contact Pe rsonal Address Details Dlg", { "form_handler": forms.address_form }), null, "Con tact.Personal_Address", null, "show");

add_simple_trigger(form_helpers.create_dialog_show("Products Dlg ", { "form_handler": forms.opportunity_product_dlg }), null, "Opportunity.Opport unity_Product", null, "show"); //ArtemP added on 6/24 add_simple_trigger(form_helpers.create_dialog_show("Revenue Dlg" , { "form_handler": forms.revenue_dlg }), null, "Opportunity.Revenue", null, "s how"); add_simple_trigger(form_helpers.create_dialog_show("Note Dlg", { "form_handler": forms.notes_dialog, "dialog_template_params": { "picklist_type" : "Contact.Contact_NoteNote TypePicklist" } }), null, "Contact.Contact_Note", nu ll, "show"); add_simple_trigger(form_helpers.create_dialog_show("Note Dlg", { "form_handler": forms.notes_dialog, "dialog_template_params": { "picklist_type" : "Opportunity.Opportunity_NoteNote TypePicklist" } }), null, "Opportunity.Oppor tunity_Note", null, "show"); add_simple_trigger(form_helpers.create_dialog_show("Note Dlg", { "form_handler": forms.notes_dialog, "dialog_template_params": { "picklist_type" : "Account.Account_NoteNote TypePicklist" } }), null, "Account.Account_Note", nu ll, "show"); add_simple_trigger(form_helpers.create_attachment_trigger(), nul l, "Attachment", null, "new"); //add_simple_trigger(form_helpers.native_show, null, "Attachment ", null, "show"); add_simple_trigger(attachment_on_crm_only, null, "Attachment", n ull, "show");

function attachment_on_crm_only(ctx) { var item_wrapper = { "id": function () { try { return ctx.form.attachments_view.selected.id; } catch (e) { return null; } } } sb_helpers.open_remote(ctx, item_wrapper); } //{ //debugger; //sb_helpers.open_remote(ctx, ctx.form.attachments_view. selected) //} scheme.objects.get_object("Attachment").attachment_options = { " filename": "CombinedFileName", "body": "Body", "duplicate": "numerate", "max_siz e": max_attach_file_size }; add_simple_trigger(update_account_to_related, "Action", "Opportu nity", "direct", "created"); add_simple_trigger(update_account_to_related_if_blank, "Action", "Contact", "direct", "created");

} //Defaulting function prefill_owner(ctx) { var current_user_id = helpers.get_current_user_id(ctx.session); if (current_user_id != null) { return ([ { "with_id": current_user_id, "tag": "mvg" }, { "with_id": current_user_id, "tag": "direct" } ]); } else return []; } function prefill_team(ctx) { var current_user_position_id ry_position(ctx.session); if (current_user_position_id { return ([ { "with_id": vg" }, { "with_id": irect" } ]); } else return []; }

= sb_helpers.get_current_user_prima != null) current_user_position_id, "tag": "m current_user_position_id, "tag": "d

function prefill_organization(ctx) { var current_user_organization_id = sb_helpers.get_current_user_p rimary_organization(ctx.session); if (current_user_organization_id != null) { return ([ { "with_id": current_user_organization_id, "tag" : "mvg" }, { "with_id": current_user_organization_id, "tag" : "direct" } ]); } else return []; } function get_default_currency_code(ctx) { var defaults = helpers.get_defaults(ctx.session); var currency_id = null; if ((defaults != null) && (defaults["CurrencySymbol"] != null)) { var currency = ctx.session.open_item(defaults["CurrencyS ymbol"]); if (currency != null) { currency_id = currency.id(); }

} return currency_id; } function get_default_opportunity_sales_method(ctx) { var pick_value = ctx.session.find_item("OpportunitySales MethodP icklist", ctx.session.create_criteria("and")); return pick_value != null ? pick_value.Value : ""; } function get_current_user_login(ctx) { var user_login = ""; var defaults = include.helpers.get_defaults(ctx.session); if (defaults != null) { user_login = ctx.session.open_item(defaults.CurrentUser) ["Login Name"]; } return user_login; } function prefill_opportunity_links(ctx) { var team = prefill_team(ctx); var organization = prefill_organization(ctx); return team.concat(organization); } function date_today_plus(date_shift) { var today = new Date(); return util.local_to_utc((new Date(today.getFullYear(), today.ge tMonth(), today.getDate() + date_shift, 12)).getVarDate()); } function calculate_rev_item_num() { var newDate = new Date; var uniqid = newDate.getTime(); return ("1-"+uniqid); } function prefill_suppress_file_as(ctx) { return ctx.form.item.SuppressFileAs != null ? ctx.form.item.Supp ressFileAs : ctx.session.res_string("lang_general_initial_fileas"); } function get_current_date(ctx) { return util.local_to_utc((new Date()).getVarDate()); } scheme.objects.get_object("Action").get_field("Appt PIM Flag")["initial_ value"] = true; scheme.objects.get_object("Action").get_field("Display")["initial_value_ res"] = "lang_action_display_activities_only"; scheme.objects.get_object("Action").get_field("Repeating")["initial_valu

e"] = false; scheme.objects.get_object("Action").get_field("Repeating Type")["initial _value"] = ""; scheme.objects.get_object("Action").get_field("ObjectState")["initial_va lue"] = 0; scheme.objects.get_object("Action").get_field("SiebelShared")["initial_v alue"] = true; scheme.objects.get_object("Action").get_field("SuppressFileAs")["initial _value_res"] = "lang_general_initial_fileas"; scheme.objects.get_object("Action").get_field("Type")["initial_value_res "] = "lang_action_initial_type"; scheme.objects.get_object("Action").get_field("Status")["initial_value_r es"] = "lang_action_initial_status"; scheme.objects.get_object("Action").get_field("Percent Complete")["initi al_value_fn"] = function() { return null; }; scheme.objects.get_object("Action")["initial_links_fn"] = prefill_owner; scheme.objects.get_object("Contact").get_field("Protect Internal Employe e Flag")["initial_value_res"] = "lang_contact_initial_protect_internal_employee_ flag"; scheme.objects.get_object("Contact").get_field("ObjectState")["initial_v alue"] = 0; scheme.objects.get_object("Contact").get_field("Status")["initial_value_ res"] = "lang_contact_initial_status"; scheme.objects.get_object("Contact").get_field("SuppressFileAs")["initia l_value_fn"] = prefill_suppress_file_as; scheme.objects.get_object("Contact")["initial_links_fn"] = prefill_team; scheme.objects.get_object("Account").get_field("SuppressFileAs")["initia l_value_res"] = "lang_general_initial_fileas"; scheme.objects.get_object("Account").get_field("Account Status")["initia l_value_res"] = "lang_account_initial_status"; scheme.objects.get_object("Account").get_field("ObjectState")["initial_v alue"] = 0; scheme.objects.get_object("Account").get_field("Currency Code")["initial _value_fn"] = get_default_currency_code; scheme.objects.get_object("Account")["initial_links_fn"] = prefill_team; scheme.objects.get_object("Opportunity").get_field("Status")["initial_va lue_res"] = "lang_opportunity_initial_status"; scheme.objects.get_object("Opportunity").get_field("ObjectState")["initi al_value"] = 0; scheme.objects.get_object("Opportunity").get_field("SuppressFileAs")["in itial_value_res"] = "lang_general_initial_fileas"; scheme.objects.get_object("Opportunity").get_field("Name Read Only Flg") ["initial_value_res"] = "lang_opportunity_initial_name_read_only_flg"; scheme.objects.get_object("Opportunity").get_field("Currency Code")["ini tial_value_fn"] = get_default_currency_code; scheme.objects.get_object("Opportunity").get_field("Sales Method")["init ial_value_fn"] = get_default_opportunity_sales_method; scheme.objects.get_object("Opportunity").get_field("Primary Revenue Clos e Date")["initial_value_fn"] = function() { return date_today_plus(30)}; scheme.objects.get_object("Opportunity")["initial_links_fn"] = prefill_o pportunity_links; scheme.objects.get_object("Opportunity").get_field("HW Win Probability D escription")["initial_value"] = "20% - Qualified Opportunity"; scheme.objects.get_object("Opportunity").get_field("HW Project Go Descri ption")["initial_value"] = "10% - Interest Identified"; scheme.objects.get_object("Opportunity").get_field("Sales Stage")["initi al_value"] = "2-Opportunity Development";

scheme.objects.get_object("Opportunity.Position").get_field("Opportunity Rep %")["initial_value"] = 0; scheme.objects.get_object("Opportunity.Opportunity_Product").get_field(" Currency Code")["initial_value_fn"] = get_default_currency_code; scheme.objects.get_object("Opportunity.Opportunity_Product").get_field(" Revenue Item Number")["initial_value_res"] = "lang_opportunity_product_initial_r evenue_item_number"; scheme.objects.get_object("Opportunity.Opportunity_Product").get_field(" Sales Rep Organization")["initial_value_res"] = "lang_opportunity_product_initia l_sales_rep_organization"; //scheme.objects.get_object("Opportunity.Revenue").get_field("Date")["in itial_value_fn"] = function() { return date_today_plus(30)}; scheme.objects.get_object("Opportunity.Revenue").get_field("Revenue Type ")["initial_value"] = "Projected"; scheme.objects.get_object("Opportunity.Revenue").get_field("HW CRMD Reve nue Item Number")["initial_value_fn"] = function() { return calculate_rev_item_n um()}; scheme.objects.get_object("Opportunity.Revenue").get_field("Currency Cod e")["initial_value_fn"] = get_default_currency_code; scheme.objects.get_object("Opportunity.Opportunity_Note").get_field("Not e Type")["initial_value_res"] = "lang_opportunity_note_initial_type" scheme.objects.get_object("Opportunity.Opportunity_Note").get_field("Cre ated")["initial_value_fn"] = get_current_date; scheme.objects.get_object("Opportunity.Opportunity_Note").get_field("Cre ated By Name")["initial_value_fn"] = get_current_user_login; scheme.objects.get_object("Opportunity.Opportunity_Note")["initial_links _fn"] = prefill_owner; scheme.objects.get_object("Contact.Contact_Note").get_field("Note Type") ["initial_value_res"] = "lang_contact_note_initial_type" scheme.objects.get_object("Contact.Contact_Note").get_field("Created")[" initial_value_fn"] = get_current_date; scheme.objects.get_object("Contact.Contact_Note").get_field("Created By Name")["initial_value_fn"] = get_current_user_login; scheme.objects.get_object("Contact.Contact_Note")["initial_links_fn"] = prefill_owner; scheme.objects.get_object("Account.Account_Note").get_field("Note Type") ["initial_value_res"] = "lang_account_note_initial_type" scheme.objects.get_object("Account.Account_Note").get_field("Created")[" initial_value_fn"] = get_current_date; scheme.objects.get_object("Account.Account_Note").get_field("Created By Name")["initial_value_fn"] = get_current_user_login; scheme.objects.get_object("Account.Account_Note")["initial_links_fn"] = prefill_owner; // Activity processing and related with (scheme.objects) { get_object("Action").get_field("Description")["restrictions"] = { "max_length": max_subject_length }; get_object("Action").get_field("MeetingLocation")["restrictions" ] = { "max_length": max_location_length }; get_object("Action").get_field("Comment")["restrictions"] = { "m ax_length": max_comments_length }; // get_object("Action").get_field("Email To Line")["restrictions"]

= { "max_length": max_emailtoline_length }; // get_object("Action").get_field("Email CC Line")["restrictions"] = { "max_length": max_emailtoline_length }; get_object("Attachment")["restrictions"] = {"max_length": 1500}; get_object("Contact").extract_emails = function(ctx, item_ex) { return [item_ex.get_property("Email Address")]; } get_object("Employee").extract_emails = function(ctx, item_ex) { return [item_ex.get_property("EMail Addr")]; } /** Resolves email address to <b>Contact</b> @param {Array[String]} addresses Array of addresses to r esolve @returns Resolved Contact, null if not resolved */ get_object("Contact").resolve_by_email = function(addr, ctx, tra ck_conversation_check) { var session = ctx.session; var result = new Array(); if (addr != "" && addr != null) { var curr_user_id = helpers.get_current_user_id(s ession); var filter = session.create_criteria("and"); filter.add(session.create_expression("Email Addr ess", "like", addr)); filter.add(session.create_expression("SiebelShar ed", "eq", true)); helpers.for_each(session.find_items("Contact", f ilter), function(item) { if (track_conversation_check) { var filter = session.cre ate_criteria("and"); filter.add(session.creat e_expression("Contact Id", "eq", item.id)); filter.add(session.creat e_expression("Owner Id", "eq", curr_user_id)); filter.add(session.creat e_expression("Save Email Flag", "eq", true)); if (session.find_item("C ontact.Contact_Sync_Owner", filter) == null) return; } result.push(item.id) }); } return result; } /** Resolves email addresses to <b>Contacts</b> @param {Array[String]} addresses Array of addresses to r esolve @returns Array of resolved Contacts */ get_object("Contact").resolve_by_emails = function(addresses, ct x, track_conversation_check) { var result = new Array();

for (var index in addresses) result = result.concat(this.resolve_by_email(add resses[index], ctx, track_conversation_check)); return helpers.stable_unique_id_array(ctx.session, resul t); } /** Resolves email addresses to <b>Employee</b> @param {String} addr Address to resolve @returns Resolved Employee, null if not resolved */ get_object("Employee").resolve_by_email = function(addr, ctx) { var session = ctx.session; var account_addresses = include.helpers.safe_get_account _addresses(ctx.application); var filter = session.create_criteria("and"); var result = new Array(); if (addr != "" && addr != null) { filter.add(session.create_expression("EMail Addr ", "like", addr)); helpers.for_each(session.find_items("Employee", filter), function(item) { result.push(item.id) }); if (result.length == 0 && account_addresses != n ull && include.helpers.contains(account_addresses, addr)) result.push(include.helpers.get_current_ user_id(session)); } return result; } get_object("Mail").proxy_type = "Action"; get_object("Event").proxy_type = "Action"; get_object("Task").proxy_type = "Action"; function set_dirty(ctx) { raw.set_item_dirty(ctx.item_ex.fcd_ite m); } get_object("Mail").set_form_dirty = set_dirty; get_object("Event").set_form_dirty = set_dirty; get_object("Task").set_form_dirty = set_dirty; } with (scheme.links) { add_link(new employees_virtual_link("Account")); add_link(new employees_virtual_link("Opportunity")); add_link(new employees_virtual_link("Contact")); } // Addresses handling scheme.account_business_address_link = create_account_business_address_l ink(); scheme.account_business_address_link_mr = create_account_business_addres s_link(false, true); scheme.links.add_link(scheme.account_business_address_link); scheme.links.add_link(scheme.account_business_address_link_mr);

scheme.account_business_address_primary_link = new data_model.direct_lin k("Account", scheme.account_business_address_link.link_to, "Primary Address Id") ; scheme.links.add_link(scheme.account_business_address_primary_link); scheme.contact_personal_address_link = create_contact_personal_address() ; scheme.contact_personal_address_link_mr = create_contact_personal_addres s(true); scheme.links.add_link(scheme.contact_personal_address_link); scheme.links.add_link(scheme.contact_personal_address_link_mr); scheme.contact_personal_address_primary_link = new data_model.direct_lin k("Contact", scheme.contact_personal_address_link.link_to, "Primary Personal Add ress Id"); scheme.links.add_link(scheme.contact_personal_address_primary_link); helpers.for_each([scheme.account_business_address_link, scheme.contact_p ersonal_address_link], function(link) { scheme.triggers.add_simple_trigger(data_model.update_primary_tri gger, link.type, link.link_to, link.tag, "created"); scheme.triggers.add_simple_trigger(data_model.update_primary_tri gger, link.type, link.link_to, link.tag, "removed"); }); scheme.contact_business_address_link = new contact_business_address_link (); scheme.links.add_link(scheme.contact_business_address_link); scheme.contact_business_address_primary_link = new data_model.direct_lin k("Contact", scheme.contact_business_address_link.link_to, "Primary Address Id") ; scheme.contact_business_address_primary_link.tag = "primary-business"; scheme.links.add_link(scheme.contact_business_address_primary_link); scheme.triggers.add_simple_trigger(data_model.create_update_primary_trig ger({ "primary_tag": "primary-business" }), "Contact", scheme.contact_business_a ddress_link.link_to, scheme.contact_business_address_link.tag, "created"); scheme.triggers.add_simple_trigger(data_model.create_update_primary_trig ger({ "primary_tag": "primary-business" }), "Contact", scheme.contact_business_a ddress_link.link_to, scheme.contact_business_address_link.tag, "removed"); scheme.triggers.add_simple_trigger(update_primary_business_on_account_ch ange, "Contact", "Account", "direct", "created"); helpers.for_each(["created", "removed", "submit"], function(operation) { scheme.triggers.add_simple_trigger(business_address_created_dele ted_submited_trigger, "Account", scheme.account_business_address_link.link_to, s cheme.account_business_address_link.tag, operation); scheme.triggers.add_simple_trigger(business_address_created_dele ted_submited_trigger, "Contact", scheme.contact_business_address_link.link_to, s cheme.contact_business_address_link.tag, operation); }); // GG 7/2/13: SIA Upg: Added Code from SIA Vanilla scheme.objects.get_object(scheme.account_business_address_link.associati on_type).get_field(scheme.account_business_address_link.right_link).set_link(sch eme.account_business_address_link.link_to, false); scheme.objects.get_object(scheme.contact_personal_address_link.associati on_type).get_field(scheme.contact_personal_address_link.right_link).set_link(sch eme.contact_personal_address_link.link_to, false);

scheme.objects.get_object(scheme.account_business_address_link.link_to). selectors_options = { "sb_custom_view": true, "source": { "caption": "obj_personal_address_plural", "view_id": "business_address:salesbook", "search_by": ["Street Address", "Postal Code", "City", " State", "Country"] } } scheme.triggers.add_trigger(new data_model.show_mvg_on_form_trigger(sche me.account_business_address_link)); scheme.triggers.add_trigger(new data_model.show_mvg_on_form_trigger(sche me.contact_personal_address_link)); scheme.triggers.add_trigger(new data_model.show_child_on_form_trigger(sc heme.account_business_address_link_mr)); scheme.triggers.add_trigger(new data_model.show_child_on_form_trigger(sc heme.contact_personal_address_link_mr)); // UI resources scheme.mvg_link_result_options = { "resources_map": { "Account": "msg_account", "Contact": "msg_contact", "Position": "msg_position", "Opportunity": "msg_opportunity", "Employee": "msg_employee", "Assignment_Group": "msg_territory", "Industry": "msg_industry", "Internal_Division": "msg_organization" } } scheme.mvg_link_result_options.resources_map["Business_Address"] = "msg_ address"; for (var key in scheme.mvg_link_result_options.resources_map) { var prefix = scheme.mvg_link_result_options.resources_map[key]; scheme.mvg_link_result_options.resources_map[key] = { "already_exists_caption": prefix + "_add_caption", "already_exists": prefix + "_present", "primary_delete_denied": prefix + "_is_primary" }; } return scheme; } function safe_get_sender_address(item) { try { return item["SenderAddress"]; } catch (e) {

return null; } } function get_mail_recipients_by_priority(ctx, mail) { var sender = safe_get_sender_address(mail); sender = sender != null ? [sender] : []; var to = raw.get_recipints_of_type(ctx.application, mail, raw.olTo); var cc = raw.get_recipints_of_type(ctx.application, mail, raw.olCC); var recipients = to.concat(cc); var all_mails = mail["Inbound"] ? sender.concat(recipients) : recipients .concat(sender); return helpers.stable_unique_array(all_mails); } var util_get_proxy_from_association = function(ctx, association) { var employee_reverse_link = ctx.data_model.links.get_link({ "type": "Emp loyee", "link_to": "Action", "tag": "mvg" }).link; var proxy_id = employee_reverse_link.resolve_association(ctx, associatio n.fcd_item); var pr_item = null; if(proxy_id != null) pr_item = ctx.session.open_item(proxy_id); return pr_item != null ? ctx.activity_processor.item_wrapper(pr_item).it em_ex() : null; } /* GG: 7/2/13: SIA Upg: Inactivated below Code function ignore_event(ctx, operation_ctx) { var ol = operation_ctx.ol; // Ignore holiday events if (sb_helpers.has_holiday_category(ol.fcd_item["Categories"])) return true; // Ignore strange items from Outlook hidden internal folders with other mapping if (!helpers.safe_call(function() { ol.get_property("MeetingStatus"); ol.get_property("StartDate"); ol.get_property("Percent Complete"); }).success) return true; // Ignore private items if (ol.get_property("Private") == true) return true; return false; } */ var product_activity_descriptor = function() { // private section var priority_mapping = { "ol": "Importance", "proxy": "Priority", "mapping": [ // Array of Priority values mapp

ing {"ol": 0, "proxy": "#lang_action_priority_low" } , { "ol": 1, "proxy": "#lang_action_priority_mediu m" }, { "ol": 2, "proxy": "#lang_action_priority_high" }, { "ol": 2, "proxy": "#lang_action_priority_asap" } ], "proxy_writer_fn": function(ctx, proxy, ol_value, ol) { var proxy_old = this.proxy_reader_fn(ctx, proxy); for (var key in this.mapping) { var mapping = this.mapping[key]; if (mapping.ol == ol_value && proxy_old != ol_va lue) return proxy.set_property(this.proxy, ct x.activity_processor.res_str(mapping.proxy)); } }, "ol_writer_fn": function(ctx, ol, value, proxy) { var ol_old = ol.get_property(this.ol); if (value != ol_old) return ol.set_property(this.ol, value); }, "proxy_reader_fn": function(ctx, proxy) { var proxy_value = proxy.get_property(this.proxy); if (proxy_value === "" || proxy_value == null) return null; for (var key in this.mapping) { var mapping = this.mapping[key]; if (ctx.activity_processor.res_str(mapping.proxy ) == proxy_value) return mapping.ol; } } } var get_exception_object = function(ctx, proxy, create) { return proxy.fcd_item; } var get_owner_for_ol_item = function(ctx, operation_ctx) // uses std_get_owner_for_ol_item() { var addresses; var ol = operation_ctx.ol; var that = ctx.activity_processor; if (ol.get_type() == that.get_ol_type("Event") || ol.get_type() == that.get_ol_type("Mail")) { var sender = that.safe_get_sender_address(ol.fcd_item); addresses = (sender == null || sender == "") ? false : [ sender]

} else if (ol.get_type() == that.get_ol_type("Task")) { addresses = raw.get_attendees(ctx.application, ol.fcd_it em); } var resolved = that.std_resolve_emails(addresses, true); var result = that.std_get_owner_for_ol_item(ol, "Employee", reso lved) if (addresses != false && result.external_organizer) { if (resolved.Contact.length > 0) result.contact = resolved.Contact[0]; if (ol.get_type() == that.get_ol_type("Event") || ol.get _type() == that.get_ol_type("Mail")) { var general_owner = sb_helpers.get_general_owner _id(ctx.session); if (general_owner != null) result.owner = general_owner; } } return result; } var create_initial_associations = function(ctx, operation_ctx) { var owner_result = get_owner_for_ol_item(ctx, operation_ctx); ctx.activity_processor.add_association_description(owner_result. owner, null, null, "direct"); if (owner_result.contact != null) ctx.activity_processor.add_association_description(owner _result.contact, null, null, "direct"); return owner_result; } var ol_recipients_to_associations = function(ctx, operation_ctx) { var that = ctx.activity_processor; var au = new that.addr_utils(ctx, operation_ctx) var proxy = operation_ctx.proxy; var ol = operation_ctx.ol; helpers.merge_contexts({ "all": [] }, operation_ctx.prev_recipie nts); var calculate_event_associations = function(prev_addresses, curr ent_addresses) { var add_array = au.get_addresses_difference(current_addr esses, prev_addresses); var remove_array = au.get_addresses_difference(prev_addr esses, current_addresses); var resolved = that.std_resolve_emails(add_array, true); helpers.for_each(resolved.all, that.add_association_desc ription, null); au.remove_associations_by_emails(remove_array); var to_line_addresses = au.addresses_csv_to_array(proxy. get_property("Email To Line"));

to_line_addresses = au.get_addresses_difference(to_line_ addresses, remove_array); to_line_addresses = to_line_addresses.concat(resolved.un resolved); //that.std_write_limited(proxy, "Email To Line", au.addr esses_array_to_csv(helpers.stable_unique_array(to_line_addresses))); proxy.set_property("Email To Line", au.addresses_array_t o_csv(helpers.stable_unique_array(to_line_addresses))); } var recipients = raw.get_attendees(ctx.application, ol.fcd_item) ; var owner_result = get_owner_for_ol_item(ctx, operation_ctx); if (ol.get_type() == that.get_ol_type("Event")) { if (operation_ctx.operation == "ol_created") // ol.creat ed { that.add_association_description(owner_result.ow ner, null) that.add_association_description(that.current_us er_id(), null) if (owner_result.contact != null) that.add_association_description(owner_r esult.contact, null) calculate_event_associations([], recipients); } else calculate_event_associations(operation_ctx.prev_ recipients.all.concat(raw.get_attendees(ctx.application, ol.fcd_item, true)), re cipients); } else if (ol.get_type() == that.get_ol_type("Task")) { that.add_association_description(that.current_user_id(), null); that.add_association_description(owner_result.owner, nul l) if (operation_ctx.operation == "ol_created" && owner_res ult.contact != null) that.add_association_description(owner_result.co ntact, null) var resolved = that.std_resolve_emails(recipients, true) ; if (ol.fcd_item["Ownership"] == that.task_ownership_dele gated && resolved.Employee.length > 1) resolved.Employee = [resolved.Employee[0], that. current_user_id()]; helpers.for_each(resolved.Employee, that.add_association _description, null); helpers.for_each(resolved.Contact, that.add_association_ description, null); // Attendee parsing task specific if (ol.fcd_item["Ownership"] != that.task_ownership_new) create_initial_associations(ctx, operation_ctx); } else if (ol.get_type() == that.get_ol_type("Mail")) {

that.add_association_description(owner_result.owner, nul l) that.add_association_description(that.current_user_id(), null) if (owner_result.contact != null) that.add_association_description(owner_result.co ntact, null) } } var find_ol_item = function(ctx, operation_ctx) { var that = ctx.activity_processor; var proxy = operation_ctx.proxy; var ol_type = that.proxy_display2ol_type(proxy); var owner = ctx.linker.linked({ "item_ex": proxy, "link_to": "Em ployee", "tag": "direct", "submited": true }); // SenderAddress == e-mail of primary owner Employee if (owner.count != null) { if (proxy.get_property("CRMD Integration Id") != null) { var conv_id_filter = ctx.session.create_expressi on("ConversationId", "like", proxy.get_property("CRMD Integration Id")); var ol = that.item_wrapper(ctx.session.find_item (ol_type, conv_id_filter)); if (ol != null) { operation_ctx.ol = ol.item_ex(); if (helpers.ids_equal(ctx.session, owner .value, get_owner_for_ol_item(ctx, operation_ctx).owner) && that.get_proxy_item(ol, null, operation_ctx) == null) { operation_ctx.proxy = proxy; operation_ctx.ol = ol.item_ex(); return; } } } var filter = ctx.session.create_criteria("and"); filter.add(ctx.session.create_expression("Subject", "eq" , proxy.get_property("Description"))); /* GG: 7/2/13: Inactivated Below code as per SIA Vanilla File and replace it with above One line code var subject_complex_filter = ctx.session.create_criteria ("or"); subject_complex_filter.add(ctx.session.create_expression ("Subject", "eq", proxy.get_property("Description"))); subject_complex_filter.add(ctx.session.create_expression ("NormalizedSubject", "eq", proxy.get_property("Description"))); filter.add(subject_complex_filter); */ var ol_items = ctx.session.find_items(ol_type, filter); for (var enm = new Enumerator(ol_items); !enm.atEnd(); e nm.moveNext()) {

var ol = that.item_wrapper(enm.item()); // Check if dates are equal var ol_start_date = ol.item()["StartDate"]; var proxy_start_date = proxy.get_property("Plann ed"); var dates_equal = ol_start_date + 0 == proxy_sta rt_date + 0; if (!dates_equal && ol_type == that.get_ol_type( "Task") && ol_start_date != null && proxy_start_date != null) { ol_start_date = util.utc_to_local(ol_sta rt_date); proxy_start_date = util.utc_to_local(pro xy_start_date); proxy_start_date = include.helpers.get_d ate_without_time(proxy_start_date); dates_equal = ol_start_date + 0 == proxy _start_date + 0; } operation_ctx.ol = ol.item_ex(); if (dates_equal && helpers.ids_equal(ctx.session, owner. value, get_owner_for_ol_item(ctx, operation_ctx).owner) && that.get_proxy_item(ol, null, operati on_ctx) == null) { operation_ctx.proxy = proxy; operation_ctx.ol = ol.item_ex(); return; } } } operation_ctx.proxy = proxy; operation_ctx.ol = null; } var delete_proxy_or_remove_current_user = function(ctx, operation_ctx) { var ol_id = operation_ctx.result.deleted_id; var proxy = operation_ctx.proxy; var that = ctx.activity_processor; if (proxy == null) proxy = that.get_proxy_item(null, ol_id, operation_ctx); if (proxy != null) { var current_user = that.current_user_id(); var security_descriptor = ctx.security_manager.create(ct x, proxy); var object_is_not_sync = !security_descriptor.is_synced( ); function unshare() { proxy.set_property(that.descriptor.common.proxy_ link_field, null); ctx.save_helper.save_and_disable_events(proxy.fc d_item, true); }

if (!object_is_not_sync && that.is_proxy_archive(proxy)) { unshare(); } else { var primary_employee = ctx.linker.linked({ "item _ex": proxy, "link_to": "Employee", "tag": "direct", "submited": true }); if (that.is_current_user(primary_employee.value) || object_is_not_sync) proxy.fcd_item.remove(); else { if (that.proxy_display2ol_type(proxy) == that.get_ol_type("Event")) ctx.linker.unlink({ "item_ex": p roxy, "with_id": current_user, "tag": "mvg", "submited": true }); unshare(); } } } } /* function read_mail_subject(ctx, ol) { var value = ol.get_property("Subject"); if (value == null || value == "") { var date = new Date(util.utc_to_local(ol.get_property("R eceivedTime"))); var values = { "datetime": helpers.format_date(date, ctx.sessio n.res_string("lang_action_empty_subject_date_format")) }; value = helpers.format(ctx.session.res_string("lang_acti on_empty_subject_format"), values); } return value; } function body_read_fn(ctx, ol) { var value = ol.fcd_item[this.ol]; value = helpers.cleanup_description(value); var restrictions = ctx.data_model.objects.get_object("Action").r estrictions; var limit = restrictions && restrictions.max_length; var suffix = "..."; if (value != null && value.length > limit) value = value.substr(0, limit - suffix.length) + suffix; var fake_item = ctx.session.create_item("Action"); try { var old_value = undefined; for (var i = 0; i < 5 && old_value !== value; i++) {

fake_item["Comment"] = value; fake_item.save(); old_value = value; value = fake_item["Comment"]; } } finally { fake_item.remove(); } return value; } function read_event_subject(ctx, ol) { var value = ol.get_property("NormalizedSubject"); if (value == null || value == "") value = ol.get_property("Subject"); return value; } */ this.common = { // Common section for all types // all properties from here will be copied to missing field in s pecific descriptor /*REQUIRED*/ "proxy_link_field": "PIMObjectId", // Proxy field name, tha t stores Object Id of related OL item "resolved_types": ["Employee", "Contact"], "recipient_to_links_fn": ol_recipients_to_associations, // opera tion_ctx - proxy, links, addition info "links_to_recipients_fn": function(ctx, operation_ctx) { }, // o peration_ctx - proxy, links, addition info "get_proxy_type_fn": function(ctx, operation_ctx) { return strin g; }, //use "proxy_type", "proxy_type_field", "proxy_type_field_value" "proxy_type": "Action", // Proxy Object type_id "proxy_type_field": "Display", // Activity type field "proxy_type_field_copy": "DisplayCopy", // Activity type field copy "proxy_auto_creation_flag": "CreatedByAutoProcessing", "set_proxy_by_correlation_fn": function(ctx, operation_ctx) { // ex find_proxy() var that = ctx.activity_processor; var ol = operation_ctx.ol; // No correlation defined for "Mail" if (ol.get_type() == that.get_ol_type("Mail")) return null; var pd_key = that.get_pd_key(ol.get_type()); var proxy_type = that.descriptor[pd_key].proxy_type; var proxy = null; var displ_filter = ctx.session.create_expression("Displa y", "eq", that.res_str(that.descriptor[pd_key].proxy_type_field_value)); var owner = get_owner_for_ol_item(ctx, operation_ctx).ow ner; if (owner != null) {

var owner_filter = ctx.session.create_expression ("Primary Owner Id", "eq", owner); var conv_id_mapping = that.get_field_mapping(pd_ key, "ConversationId"); var conv_id = conv_id_mapping.ol_reader_fn(ctx, ol); if (conv_id != null) { var conversation_id_filter = ctx.session .create_criteria("and"); conversation_id_filter.add(displ_filter) ; conversation_id_filter.add(owner_filter) ; conversation_id_filter.add(ctx.session.c reate_expression("CRMD Integration Id", "eq", conv_id)); proxy = that.item_wrapper(ctx.session.fi nd_item(proxy_type, conversation_id_filter)); } if (proxy == null) { // Try to find by natural key var filter = ctx.session.create_criteria ("and"); filter.add(displ_filter); filter.add(ctx.session.create_expression ("Description", "eq", that.std_read_limited(ol, "Subject"))); filter.add(owner_filter); for (var enm = new Enumerator(ctx.sessio n.find_items(proxy_type, filter)); proxy == null && !enm.atEnd(); enm.moveNext() ) { var current_proxy = that.item_wr apper(enm.item()); // Check if dates are equal var ol_start_date = ol.get_prope rty("StartDate"); var proxy_start_date = current_p roxy.item()["Planned"]; var dates_equal = ol_start_date + 0 == proxy_start_date + 0; if (!dates_equal && ol.get_type( ) == that.get_ol_type("Task") && ol_start_date != null && proxy_start_date != nu ll) { ol_start_date = util.utc _to_local(ol_start_date); proxy_start_date = util. utc_to_local(proxy_start_date); proxy_start_date = inclu de.helpers.get_date_without_time(proxy_start_date); dates_equal = ol_start_d ate + 0 == proxy_start_date + 0; } if (dates_equal) proxy = current_proxy; }

} } if (proxy != null) operation_ctx.proxy = proxy.item_ex(); }, "proxy_type_field_value": "#lang_action_display_activities_only" , "is_proxy_crm_originated_fn": function(ctx, operation_ctx) {// Detect if Proxy Objects is CRM originated, returns bool return (operation_ctx.proxy.get_property("Appt PIM Flag" ) != true || operation_ctx.proxy.get_property("CRMD Integration Id") == null); }, // optional "check_online": false, // if to check online state before item change processing "set_new_proxy_fn": function(ctx, operation_ctx) { operation_cxt .proxy = new proxy; }, // ex create_proxy() // "set_proxy_by_link_fn": function(ctx, operation_ ctx){ operation_cxt.proxy = proxy;}, // ex get_proxy() "process_ol_changes_fn": function(ctx, operation_ctx) // proce ssing of OL item changes, modifies proxy property in operation_ctx (Proxy Object ) { var proxy = operation_ctx.proxy; var ol = operation_ctx.ol; if (operation_ctx.operation == "item_deleted") return; // "item_deleted" handled in pr ocess_proxy_changes_fn() var fields_result = operation_ctx.result; //if (fields_result.exceptions != null) //{ //ctx.save_helper.save_and_disable_events(fields_result. exceptions); //proxy.set_property("SqueezzedExceptionId", fields_resu lt.exceptions.id); //} // if (proxy.get_id() == null || proxy.dirty || fields_resu lt.exceptions != null) { ctx.save_helper.save_and_disable_events(proxy.fc d_item); proxy.reset(); } ctx.activity_processor.std_process_ol_item_changes(ctx, operation_ctx) //required call //if (fields_result.exceptions != null && fields_result. exceptions["Orig Appt Id"] == null) //{ //fields_result.exceptions["Orig Appt Id"] = proxy.get_i d(); //ctx.save_helper.save_and_disable_events(fields_result. exceptions); //} },

"process_proxy_changes_fn": function(ctx, operation_ctx) { // processing of Proxy item changes, modifies proxy prop erty of operation_ctx switch (operation_ctx.operation) { case "item_deleted": delete_proxy_or_remove_current_user(ctx, operation_ctx); break; case "before_item_deleted": var association = operation_ctx.proxy; var employee_link = ctx.data_model.links .get_link({ "type": "Action", "link_to": "Employee", "tag": "mvg" }).link; if (association && association.get_type( ) == employee_link.association_type && ctx.activity_processor.is_current_user(em ployee_link.resolve_association(ctx, association.fcd_item))) operation_ctx.proxy = util_get_p roxy_from_association(ctx, association); else operation_ctx.proxy = null; break; } }, "map_proxy_to_ol_fn": function(ctx, operation_ctx) // proxy_fields_to_ol { var ol = operation_ctx.ol; var proxy = operation_ctx.proxy; var that = ctx.activity_processor; var link_updated = false; var pd_key = that.proxy_display2ol_type(proxy, true) || "common"; var is_proxy_crm_originated = that.descriptor[pd_key].is _proxy_crm_originated_fn(ctx, operation_ctx); var old_display_copy = proxy.get_property("DisplayCopy") ; var new_display_copy = old_display_copy; var is_proxy_ol_compatible = function(proxy) { var result = false; var ol_type = that.proxy_display2ol_type(proxy); if (ol_type == that.get_ol_type("Event")) result = proxy.get_property("Planned") ! = null && proxy.get_property("Planned Completion") != null; if (ol_type == that.get_ol_type("Task")) result = true; if (result) { if (!ctx.security_manager.create(ctx, pr oxy).modify_access()) { var employees = ctx.linker.linke d({ "item_ex": operation_ctx.proxy, "link_to": "Employee", "tag": "mvg" }); if (!helpers.contains_object_id( ctx.session, employees.values, that.current_user_id())) result = false; } } return result;

} var additional_updates = 0; var proxy_fields_to_ol = function(ctx, operation_ctx) { var ol = operation_ctx.ol; var proxy = operation_ctx.proxy; ctx.activity_processor.std_map_proxy_to_ol(proxy , ol); // required call that processes fields_mapping if (ol.get_type() == "Event") { // Recurrence var outlook_pattern; function update_recurrence() { var exception_object = get_excep tion_object(ctx, proxy); outlook_pattern = ctx.session.op en_recurrent_pattern(ol.fcd_item, "RecurrencePattern", false); if (exception_object != null) { var result_pattern = inc lude.recurrence_processing.sync_outlook_pattern_with_siebel(ctx, outlook_pattern , proxy.fcd_item, exception_object); if (result_pattern != nu ll) { additional_updat es = result_pattern.exception_list.toArray().length; if (additional_u pdates) addition al_updates++; result_pattern.s ave(); that.log(that.ol _to_string(ol) + "RecurrencePattern modified."); outlook_pattern = result_pattern; ol.dirty = true; } } } try { update_recurrence(); } catch (e) { var temp_pattern = ctx.session.o pen_recurrent_pattern(ol.fcd_item, "RecurrencePattern", false); temp_pattern.type = recurrence_p rocessing.rp_type_none; temp_pattern.save(); ctx.save_helper.save_and_disable _events(ol.fcd_item); that.log(that.ol_to_string(ol) + "RecurrencePattern modified and saved."); update_recurrence(); } if (outlook_pattern.type == include.recu

rrence_processing.rp_type_none) { ol.set_property("StartDate", pro xy.get_property("Planned")); ol.set_property("EndDate", proxy .get_property("Planned Completion")); } ol.set_property("Duration", proxy.get_pr operty("Duration Minutes")); if ((operation_ctx.operation == "pr_crea ted" || operation_ctx.operation == "ol_created") && proxy.get_property("Planned" ) < util.local_to_utc(new Date().getVarDate())) ol.set_property("ReminderSet", f alse); } } var ol_compatible = is_proxy_ol_compatible(proxy); if (operation_ctx.operation != "pr_created") // !prox y.created { if (proxy.get_property("Display") != old_display _copy || !ol_compatible) { if (ol != null) { if (is_proxy_crm_originated) { that.log(that.ol_to_stri ng(ol) + "removed on proxy changed."); ol.fcd_item.remove(); } ol = null; new_display_copy = that.res_str( that.descriptor.common.proxy_type_field_value); link_updated = true; } operation_ctx.operation = "pr_created"; } } if (operation_ctx.operation == "pr_created" && ol_compat ible) { if (ol == null) { find_ol_item(ctx, operation_ctx); ol = operation_ctx.ol; if (ol == null && is_proxy_crm_originate d && !that.is_proxy_archive(proxy)) { ol = that.create_ol_item(proxy, operation_ctx); that.log(that.ol_to_string(ol) + "created.") } link_updated = link_updated || ol != nul l; } }

if (ol != null) { new_display_copy = proxy.get_property("Display") ; operation_ctx.ol = ol; proxy_fields_to_ol(ctx, operation_ctx); ol = operation_ctx.ol; if (ol.dirty) { ctx.save_helper.save_and_disable_events( ol.fcd_item, false, null, 1 + additional_updates); that.log(that.ol_to_string(ol) + "modifi ed and saved.") ol.reset(); } } if (link_updated || old_display_copy != new_display_copy ) { that.link_proxy_item(proxy, ol); proxy.set_property("DisplayCopy", new_display_co py); that.std_process_proxy_changes(ctx, operation_ct x); // required call } }, "map_ol_to_proxy_fn": function(ctx, operation_ctx) // ol_fields_to_proxy { var proxy_update_required = function() { var owner = get_owner_for_ol_item(ctx, operation _ctx); if (owner.current_user_organizer || owner.extern al_organizer) return true; var proxy_owner = ctx.linker.linked({ "item_ex": operation_ctx.proxy, "link_to": "Employee", "tag": "direct" }); return proxy_owner.count > 0 && ctx.activity_pro cessor.is_current_user(proxy_owner.values[0]); } if (operation_ctx.operation == "ol_created" || proxy_upd ate_required() || (operation_ctx.links && operation_ctx.links.length > 0)) { ctx.activity_processor.std_map_ol_to_proxy(opera tion_ctx.proxy, operation_ctx.ol); // required call that processes fields_mappin g if (operation_ctx.ol.get_type() == "Event") { // Recurrence var recurrent_pattern = ctx.session.open _recurrent_pattern(operation_ctx.ol.fcd_item, "RecurrencePattern", false); var exceptions = get_exception_object(ct x, operation_ctx.proxy); if (exceptions == null) { exceptions = get_exception_objec t(ctx, operation_ctx.proxy, true); operation_ctx.result = { "except ions": exceptions };

} var mock_exceptions = {}; mock_exceptions[recurrence_processing.ex cluded_dates_list_name] = exceptions[recurrence_processing.excluded_dates_list_n ame]; recurrence_processing.sync_siebel_patter n_with_outlook(ctx, operation_ctx.proxy.fcd_item, recurrent_pattern, mock_except ions); if (exceptions[recurrence_processing.exc luded_dates_list_name] != mock_exceptions[recurrence_processing.excluded_dates_l ist_name]) { exceptions[recurrence_processing .excluded_dates_list_name] = mock_exceptions[recurrence_processing.excluded_date s_list_name]; operation_ctx.result = { "except ions": exceptions }; } } ol_recipients_to_associations(ctx, operation_ctx ); } } }; this.Event = { /* REQUIRED */ "proxy_type_field_value": "#lang_action_display_calendar_and_act ivities", // Proxy Object type field value, if null - proxy_type property must be declared for each OL type section "set_new_proxy_fn": function(ctx, operation_ctx) { // ex create_proxy() operation_ctx.proxy.set_property("Type", ctx.session.res _string("lang_action_calendar_initial_type")); operation_ctx.proxy.set_property("Status", ctx.session.r es_string("lang_action_calendar_initial_status")); operation_ctx.proxy.set_property("CRMD Integration Id", operation_ctx.ol.get_property("SearchKey")); create_initial_associations(ctx, operation_ctx); }, // optional "ol_type": "Event", // OL item type_ id, if not defined descriptor key is used "archive_activity_days": archive_activity_days, // No OL objects will be creatd for older Proxy Objects (used in is_proxy_archiv e()), if null - no archive functionality // "archive_activity_start_field": "Planned", "is_proxy_archive_fn": function(ctx, operation_ctx) { // Detects if Proxy Objects is archived, returns bool var result = false; var proxy = operation_ctx.proxy; if (!proxy.get_property("Repeating")) { var archive_time = new Date(); archive_time.setDate(archive_time.getDate() - ct x.activity_processor.descriptor.Event.archive_activity_days); result = proxy.get_property("Planned Completion" ) < util.local_to_utc(archive_time.getVarDate()); } return result;

}, //"ignore_ol_item": ignore_event, "fields_mapping": [ // Array of fields names mapping {"ol": "ConversationId", "proxy": "CRMD Integration Id", // Global Id of related OL item "ol_reader_fn": function(ctx, ol) { var value = ol.fcd_item[this.ol]; return value != null ? ctx.session.hexstring_to_ id(ctx.session.id_to_hexstring(value).substr(0, 100 * 2)) : null; }, "proxy_writer_fn": function(ctx, proxy, value) { if (!ctx.activity_processor.descriptor.common.is _proxy_crm_originated_fn(ctx, { "proxy": proxy })) return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); }, "ol_writer_fn": function(ctx, ol, value) { } // write to OL is prohibited }, { "ol": "Subject", "proxy": "Description", // "ol_reader_fn": read_event_subject, "ol_writer_fn": function(ctx, ol, value) { var ol_ltd = ctx.activity_processor.std_ read_limited(ol, this.ol); if (value != ol_ltd) return ol.set_property(this.ol, value); }, "proxy_writer_fn": function(ctx, proxy, value) { return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } }, { "ol": "Description", "proxy": "Comment", "ol_writer_fn": function(ctx, ol, value) { //var ol_ltd = this.ol_reader_fn(ctx, ol ); var ol_ltd = ctx.activity_processor.std_ read_limited(ol, this.ol); if (value != ol_ltd) return ol.set_property(this.ol, value); }, //"ol_reader_fn": body_read_fn "proxy_writer_fn": function(ctx, proxy, value) { value = helpers.cleanup_description(valu e); return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } },

priority_mapping, { "ol": "Private", "proxy": "Private", "ol_writer_fn": function(ctx, ol, value) { } // write to OL is prohibited }, { "ol": "Location", "proxy": "MeetingLocation", "ol_writer_fn": function(ctx, ol, value) { var ol_ltd = ctx.activity_processor.std_ read_limited(ol, this.ol); if (value != ol_ltd) return ol.set_property(this.ol, value); }, "proxy_writer_fn": function(ctx, proxy, value) { return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } }, { "ol": "StartDate", "proxy": "Planned", "ol_writer_fn": function(ctx, ol, value) { } // will be written in map_proxy_to_ol_fn }, { "ol": "EndDate", "proxy": "Planned Completion", "ol_writer_fn": function(ctx, ol, value) { } // will be written in map_proxy_to_ol_fn }, { "ol": "Duration", "proxy": "Duration Minutes", "ol_writer_fn": function(ctx, ol, value) { }, // will be written in map_proxy_to_ol_fn "proxy_writer_fn": function(ctx, proxy, value, o l) { var start = ol.get_property("StartDate") ; var end = ol.get_property("EndDate"); value = sb_helpers.get_local_difference( start, end) / 60000; return proxy.set_property(this.proxy, va lue); } } ], "shared_by_default_key": "SharedByDefault:NewItems" // Registry key for sharing OL item by default // "shared_by_default_fn": function(ctx, operation_ ctx){return bool;} // has lower priority than "shared_by_default_key" }; /* var task_status_mapping = { "ol": "Status", "proxy": "Status", "mapping": [

// Array of task status values m

apping {"ol": "Not Started", "proxy": "#lang_action_status_not_ started" }, { "ol": "Not Started", "proxy": "#lang_action_status_ack nowledged" }, { "ol": "In Progress", "proxy": "#lang_action_status_in_

progress" }, { "ol": "Completed", "proxy": "#lang_action_status_done" }, { "ol": "Waiting on someone else", "proxy": "#lang_actio n_status_on_hold" }, { "ol": "Deferred", "proxy": "#lang_action_status_cancel led" }, { "ol": "Deferred", "proxy": "#lang_action_status_declin ed" } ], "proxy_writer_fn": function(ctx, proxy, ol_value) { var result = null; var proxy_status = proxy.get_property(this.proxy) for (var key in this.mapping) { var mapping = this.mapping[key]; if (mapping.ol == ol_value) { if (result == null) result = ctx.activity_processor. res_str(mapping.proxy); if (ctx.activity_processor.res_str(mappi ng.proxy) == proxy_status) result = proxy_status; } } return proxy.set_property(this.proxy, result); }, "proxy_reader_fn": function(ctx, proxy) // returns OL va lue { var proxy_value = proxy.get_property(this.proxy); for (var key in this.mapping) { var mapping = this.mapping[key]; if (ctx.activity_processor.res_str(mapping.proxy ) == proxy_value) return mapping.ol; } var percent_complete = Math.round(proxy.get_property("Pe rcent Complete")); if (percent_complete == 0) return ctx.activity_processor.status_not_started ; else if (percent_complete < 100) return ctx.activity_processor.status_in_progress ; else return ctx.activity_processor.status_completed; } }; */ this.Task = { /* REQUIRED */ "proxy_type_field_value": "#lang_action_display_todo_and_activit ies", // Proxy Object type field value, if null - proxy_type property must be de clared for each OL type section

"set_new_proxy_fn": function(ctx, operation_ctx) { // ex create_proxy() operation_ctx.proxy.set_property("Type", ctx.session.res _string("lang_action_todo_initial_type")); operation_ctx.proxy.set_property("CRMD Integration Id", operation_ctx.ol.get_property("SearchKey")); create_initial_associations(ctx, operation_ctx); }, "shared_by_default_key": "SharedByDefault:NewItems", // Registry key for sharing OL item by default // "archive_activity_days": archive_activity_days, // No OL objects will be creatd for older Proxy Objects (used in is_proxy_archiv e()), if null - no archive functionality // "archive_activity_start_field": "Planned", "is_proxy_archive_fn": function(ctx, operation_ctx) { // Detects if Proxy Objects is archived, returns bool var proxy = operation_ctx.proxy; return proxy.get_property("Done") != null; /* var result = false; var proxy = operation_ctx.proxy; if (proxy.get_property("Done") != null) { result = true; if (proxy.get_property("Planned") != null) { var archive_time = new Date(); archive_time.setDate(archive_time.getDat e() - ctx.activity_processor.descriptor.Event.archive_activity_days); result = proxy.get_property("Planned") < util.local_to_utc(archive_time.getVarDate()); } } return result;*/ }, "fields_mapping": [ // Array of fields names mapping {"ol": "ConversationId", "proxy": "CRMD Integration Id", // Global Id of related OL item "ol_reader_fn": function(ctx, ol) { var value = ol.fcd_item[this.ol]; return value != null ? ctx.session.hexstring_to_ id(ctx.session.id_to_hexstring(value).substr(0, 22 * 2)) : null; }, "proxy_writer_fn": function(ctx, proxy, value) { if (!ctx.activity_processor.descriptor.common.is _proxy_crm_originated_fn(ctx, { "proxy": proxy })) return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); }, "ol_writer_fn": function(ctx, ol, value) { } // write to OL is prohibited }, { "ol": "Subject", "proxy": "Description", // "ol_reader_fn": read_event_subject, "ol_writer_fn": function(ctx, ol, value) { var ol_ltd = ctx.activity_processor.std_ read_limited(ol, this.ol);

if (value != ol_ltd) return ol.set_property(this.ol, value); }, "proxy_writer_fn": function(ctx, proxy, value) { return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } }, { "ol": "Description", "proxy": "Comment", "ol_writer_fn": function(ctx, ol, value) { var ol_ltd = ctx.activity_processor.std_ read_limited(ol, this.ol); if (value != ol_ltd) return ol.set_property(this.ol, value); }, "proxy_writer_fn": function(ctx, proxy, value) { value = helpers.cleanup_description(valu e); return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } // ,"ol_reader_fn": body_read_fn }, { "ol": "Private", "proxy": "Private", "ol_writer_fn": function(ctx, ol, value) { } // write to OL is prohibited }, priority_mapping, { "ol": "Percent Complete", "proxy": "Percent Complete", "proxy_writer_fn": function(ctx, proxy, value, o l) { value = util.convert_to_double(value * 1 00); return proxy.set_property(this.proxy, va lue); }, "proxy_reader_fn": function(ctx, proxy) // returns OL value { return Math.round(proxy.get_property(thi s.proxy)); // var value = Math.round(proxy.get_propert y(this.proxy)); /* var status = ctx.activity_processor.read _pr_field(proxy, task_status_mapping); if (status == ctx.activity_processor.sta tus_not_started) value = 0; if (status == ctx.activity_processor.sta tus_completed) value = 100; return value; */ }, "ol_writer_fn": function(ctx, ol, value)

{ var ol_old = ol.get_property(this.ol); if (value != ol_old) return ol.set_property(this.ol, value); // } }, task_status_mapping, { "ol": "Status", "proxy": "Status", "mapping": [

// Array of task

status values mapping {"ol": "Not Started", "proxy": "#lang_ac tion_status_not_started" }, { "ol": "Not Started", "proxy": "#lang_a ction_status_acknowledged" }, { "ol": "In Progress", "proxy": "#lang_a ction_status_in_progress" }, { "ol": "Completed", "proxy": "#lang_act ion_status_done" }, { "ol": "Waiting on someone else", "prox y": "#lang_action_status_on_hold" }, { "ol": "Deferred", "proxy": "#lang_acti on_status_cancelled" }, { "ol": "Deferred", "proxy": "#lang_acti on_status_declined" } ], "proxy_writer_fn": function(ctx, proxy, ol_value ) { var result = null; var proxy_status = proxy.get_property(th is.proxy) for (var key in this.mapping) { var mapping = this.mapping[key]; if (mapping.ol == ol_value) { if (result == null) result = ctx.act ivity_processor.res_str(mapping.proxy); if (ctx.activity_process or.res_str(mapping.proxy) == proxy_status) result = proxy_s tatus; } } return proxy.set_property(this.proxy, re sult); }, "proxy_reader_fn": function(ctx, proxy) // returns OL value { var proxy_value = proxy.get_property(thi s.proxy); for (var key in this.mapping) { var mapping = this.mapping[key]; if (ctx.activity_processor.res_s tr(mapping.proxy) == proxy_value)

return mapping.ol; } var percent_complete = Math.round(proxy. get_property("Percent Complete")); if (percent_complete == 0) return ctx.activity_processor.st atus_not_started; else if (percent_complete < 100) return ctx.activity_processor.st atus_in_progress; else return ctx.activity_processor.st atus_completed; } }, { "ol": "StartDate", "proxy": "Planned Completion", "proxy_writer_fn": function(ctx, proxy, value, o l) { return ctx.activity_processor.set_task_d ate(proxy, this.proxy, value); }, "ol_writer_fn": function(ctx, ol, value) { } // write to OL is prohibited }, { "ol": "StartDate", "proxy": "Planned", "proxy_writer_fn": function(ctx, proxy, value, o l) { return ctx.activity_processor.set_task_d ate(proxy, this.proxy, value); }, "ol_writer_fn": function(ctx, ol, value) { ol.force_due_date_update = ctx.activity_ processor.set_task_date(ol, this.ol, value); } }, { "ol": "ActivityDate", "proxy": "Due", "proxy_writer_fn": function(ctx, proxy, value, o l) { var start = ol.get_property("StartDate") ; value = value + 0 >= start + 0 ? value : start; return ctx.activity_processor.set_task_d ate(proxy, this.proxy, value); }, "ol_writer_fn": function(ctx, ol, value, proxy) { var start = proxy.get_property("Planned" ); if (start != null && (value == null || v alue + 0 < start + 0)) value = start; return ctx.activity_processor.set_task_d ate(ol, this.ol, value, ol.force_due_date_update);

} }, { "ol": "DateCompleted", "proxy": "Done", "ol_writer_fn": function(ctx, ol, value, proxy) { var status = ctx.activity_processor.read _pr_field(proxy, "Status"); // var status = ctx.activity_processor.read_pr_ field(proxy, task_status_mapping); if (status == ctx.activity_processor.sta tus_completed) { if (value != null) return ol.set_property(t his.ol, value); } else { return ol.set_property(this.ol, null); } } } ] }; this.Mail = { /* REQUIRED */ "proxy_type_field_value": "#lang_action_display_communication_an d_activities", // Proxy Object type field value, if null - proxy_type property m ust be declared for each OL type section "set_new_proxy_fn": function(ctx, operation_ctx) { // ex create_proxy() create_initial_associations(ctx, operation_ctx); var is_inbound = operation_ctx.ol.get_property("Inbound" ) == true && get_owner_for_ol_item(ctx, operation_ctx).external_organizer; operation_ctx.proxy.set_property("Type", ctx.session.res _string(is_inbound ? "lang_action_inbound_mail_initial_type" : "lang_action_outb ound_mail_initial_type")); operation_ctx.proxy.set_property("SiebelShared", operati on_ctx.ol.get_property("Sent")); }, "create_attachment_fn": function(ctx, operation_ctx) { // Create CRM attachment for shared email var ol = operation_ctx.ol; var proxy = operation_ctx.proxy; var AttachmentsHandling = ctx.application.settings.get(" MailProcessing:AttachmentsHandling"); function create_or_update(attachment, params) { if (params.prefill_from_attach || params.name == null) params.name = attachment.Name; if (params.prefill_from_attach || params.filter == null) params.filter = ctx.session.create_expre ssion("CombinedFileName", "like", params.name); var existent = ctx.linker.linked({ "item_ex": proxy, "link_to": "Attachment",

"submited": true, "params": { "additional_filter": params. filter } }); var attach_object = null; if (params.remove_existent) { if (existent.count > 0) ctx.session.open_item(existent.v alue).remove(); if (params.create_from_field) { var file_path = helpers.get_temp _path(params.name); ctx.session.save_content_to_file (ol.fcd_item, params.create_from_field, file_path); attach_object = ctx.session.crea te_document(file_path, "Attachment", "CombinedFileName", "Body"); } } else { var attach_object = existent.count > 0 ? ctx.session.open_item(existent.value) : data_model.prefill_item(ctx, { "type": "Attachment" }).item; attach_object.CombinedFileName = params. name; attach_object.assign_property("Body", at tachment, "Body"); } if (attach_object != null) { ctx.linker.link({ "item_ex": new data_mo del.std_item_ex(attach_object), "with_id": proxy.get_id(), "submited": true }); attach_object.save(); } } if (AttachmentsHandling == 1) // attach-mail-attachmen ts-as-separate-attachments { var attachemnts = ol.get_property("Attachments") ; helpers.for_each(attachemnts != null ? attachemn ts.toArray() : [], create_or_update, { "prefill_from_attach": true }); } else if (AttachmentsHandling == 0 || AttachmentsHandling == null) // attach-mail-as-msg-file { var msg_content = ol.get_property("MsgFileConten t"); var file_name = helpers.crear_filename(msg_conte nt.Name); if (file_name.toLowerCase() == ".msg") file_name = "Untitled.msg"; create_or_update(msg_content, { "name": file_nam e, "filter": ctx.session.create_expression("CombinedFileName", "like", "%.msg%") }); } var long_body_params = {

"name": "SiebelLongEmailBody.htm", "remove_existent": true }; if (ol.long_body_detected) long_body_params["create_from_field"] = "HTMLBod y"; create_or_update(null, long_body_params); }, "track_correspondence": true, // Associate contacts with track correspondence checked "is_track_correspondence_fn": function(ctx, operation_ctx) { var ol = operation_ctx.ol; var proxy = operation_ctx.proxy; var that = ctx.activity_processor; var sender = operation_ctx.recipients.sender != null ? [ operation_ctx.recipients.sender] : []; var all_mails = ol.fcd_item["Inbound"] ? sender.concat(o peration_ctx.recipients.all) : operation_ctx.recipients.all.concat(sender); var cont_obj_descr = ctx.data_model.objects.get_object(" Contact"); var contacts_with_track_correspondence = cont_obj_descr. resolve_by_emails(all_mails, ctx, true); var all_contacts = []; if (proxy == null && contacts_with_track_correspondence. length > 0) { proxy = that.create_proxy_item(ol); all_contacts.push(contacts_with_track_correspond ence[0]); } if (proxy != null) { all_contacts = all_contacts.concat(cont_obj_desc r.resolve_by_emails(all_mails, ctx)); proxy.set_property("SiebelShared", true); operation_ctx.result.all_contacts = all_contacts ; // used in map_ol_to_proxy_fn() operation_ctx.proxy = proxy; } }, "fields_mapping": [ // Array of fields names mapping {"ol": "ConversationId", "proxy": "CRMD Integration Id", // Global Id of related OL item (required to be the first element in "fi elds_mapping" by set_proxy_by_link_fn()) "ol_reader_fn": function(ctx, ol, version) { var ol_val = ol.fcd_item[this.ol]; var value = ol_val != null ? ctx.session.id_to_h exstring(ol_val) : ""; var result = value.substr(0, 22 * 2); if (version == undefined || version > 1) result += md5.hex_md5(value); return ctx.session.hexstring_to_id(result); }, "proxy_writer_fn": function(ctx, proxy, value) { return ctx.activity_processor.std_write_limited(

proxy, this.proxy, value); }, "ol_writer_fn": function(ctx, ol, value) { } // write to OL is prohibited }, { "ol": "Subject", "proxy": "Description", // "ol_reader_fn": read_mail_subject, "ol_writer_fn": function(ctx, ol, value) { var ol_ltd = ctx.activity_processor.std_ read_limited(ol, this.ol); if (value != ol_ltd) return ol.set_property(this.ol, value); }, "proxy_writer_fn": function(ctx, proxy, value) { return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } }, // { "ol": "MapiBody", "proxy": "Comment", { "ol": "Body", "proxy": "Comment", "proxy_writer_fn": function(ctx, proxy, value) { value = helpers.cleanup_description(valu e); return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } // "ol_reader_fn": body_read_fn }, { "ol": "HTMLBody", "proxy": "Email Body", "ol_reader_fn": function(ctx, ol) { ol.long_body_detected = false; var value = ol.fcd_item[this.ol]; if (value != null) { var hex_value = ctx.session.id_t o_hexstring(value); if (hex_value.length > max_body_ length * 2) { value = ctx.session.hexs tring_to_id(long_mail_body_hex_string); // binary " ..." ol.long_body_detected = true; } } return value; } }, priority_mapping, { "ol": "ReceivedTime", "proxy": "Planned Completion" }, { "ol": "ReceivedTime", "proxy": "Planned" }, { "ol": null, "proxy": "Duration Minutes", "proxy_writer_fn": function(ctx, proxy, value, o l)

{ return proxy.set_property(this.proxy, 0) ; } }, { "ol": null, "proxy": "Email To Line", "proxy_writer_fn": function(ctx, proxy, value, o l) { var au = new ctx.activity_processor.addr _utils(ctx); value = au.addresses_array_to_csv(raw.ge t_recipints_of_type(ctx.application, ol.fcd_item, raw.olTo)) return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } }, { "ol": null, "proxy": "Email CC Line", "proxy_writer_fn": function(ctx, proxy, value, o l) { var au = new ctx.activity_processor.addr _utils(ctx); value = au.addresses_array_to_csv(raw.ge t_recipints_of_type(ctx.application, ol.fcd_item, raw.olCC)) return ctx.activity_processor.std_write_ limited(proxy, this.proxy, value); } }, { "ol": null, "proxy": "Email Sender Address", "proxy_writer_fn": function(ctx, proxy, value, o l) { var sender_address = sb_helpers.resolve_ empty_address(ctx.session, ctx.activity_processor.safe_get_sender_address(ol.fcd _item)); return proxy.set_property(this.proxy, se nder_address); } }, { "ol": null, "proxy": "Email Sender Name", "proxy_writer_fn": function(ctx, proxy, value, o l) { var sender_address = sb_helpers.resolve_ empty_address(ctx.session, ctx.activity_processor.safe_get_sender_address(ol.fcd _item)); var sender_name = ""; var resolved = ctx.activity_processor.st d_resolve_emails([sender_address], true) if (resolved.all.length) { var sender = ctx.session.open_it em(resolved.all[0]); switch (sender.type_id) { case "Contact": sender_name = se nder["DisplayName"]; break;

case "Employee": sender_name = se nder["First Name"] + " " + sender["Last Name"]; break; } } return proxy.set_property(this.proxy, se nder_name); } } ], "set_proxy_by_link_fn": function(ctx, operation_ctx) { // ex get_proxy() var ol = operation_ctx.ol; var proxy = operation_ctx.proxy; if (ol != null && proxy == null) { var ap = ctx.activity_processor; var conv_id_mapping = ap.get_field_mapping("Mail ", "ConversationId") var conv_index1 = conv_id_mapping.ol_reader_fn(c tx, ol, 1); var conv_index2 = conv_id_mapping.ol_reader_fn(c tx, ol, 2); var received_time = ol.fcd_item["ReceivedTime"]; var current_user = ap.current_user_id(); if (received_time != null && current_user != nul l && ctx.session.id_to_hexstring(conv_inde x1) != "" && ctx.session.id_to_hexstring(conv_index2) != "") { received_time = new Date(received_time); received_time.setSeconds(received_time.g etSeconds() < 30 ? 0 : 60); received_time.setMilliseconds(0); received_time = received_time.getVarDate (); var additional_filter = ctx.session.crea te_criteria("and"); additional_filter.add(ctx.session.create _expression("Display", "eq", ap.res_str(ap.descriptor.Mail.proxy_type_field_valu e))); additional_filter.add(ctx.session.create _expression("Primary Owner Id", "eq", current_user)); additional_filter.add(ctx.session.create _expression("CRMD Integration Id", "eq", conv_index1)); additional_filter.add(ctx.session.create _expression("Planned", "eq", received_time)); var or_filter = ctx.session.create_crite ria("or"); or_filter.add(ctx.session.create_express ion("CRMD Integration Id", "eq", conv_index2)); or_filter.add(additional_filter); proxy = ctx.session.find_item(ap.descrip tor.Mail.proxy_type, or_filter); if (proxy != null) operation_ctx.proxy = ap.item_wr apper(proxy).item_ex();

} } }, "map_ol_to_proxy_fn": function(ctx, operation_ctx) // ol_fields_to_proxy { ctx.activity_processor.std_map_ol_to_proxy(operation_ctx .proxy, operation_ctx.ol); // required call that processes fields_mapping ctx.save_helper.save_and_disable_events(operation_ctx.pr oxy.fcd_item, true); operation_ctx.proxy.reset(); ol_recipients_to_associations(ctx, operation_ctx); var contacts = operation_ctx.result.all_contacts; if (contacts != null && contacts.length > 0) helpers.for_each(contacts, ctx.activity_processo r.add_association_description, null); } } } var process_event_modifications = function(ctx, ap, modification_ctx) { if (ap.has_defaults_and_online()) { var proxy = ap.get_proxy_item(null, modification_ctx.series_id, {}); if (proxy != null) { function find_similar(ol) { var filter = ctx.session.create_criteria("and"); filter.add(ctx.session.create_expression("Subjec t", "eq", ol.item_ex().get_property("Subject"))); filter.add(ctx.session.create_expression("StartD ate", "eq", ol.item_ex().get_property("StartDate"))); var result = null; function f(item, prm, for_each_ctx) { if (!helpers.ids_equal(ctx.session, ol.i tem_ex().get_id(), item.id) && !helpers.ids_equal(ctx.sessio n, modification_ctx.series_id, item.id)) { var addr1 = ap.safe_get_sender_a ddress(item); var addr2 = ap.safe_get_sender_a ddress(ol.item()); if (addr1 != null && addr1 == ad dr2) { result = ap.item_wrapper (item); for_each_ctx.interrupted = true; } } }

helpers.for_each(ctx.session.find_items(ap.get_o l_type("Event"), filter), f); return result; } var new_ol_ids = modification_ctx.replace_modified_occur rences().toArray(); var links = []; function get_associated(link_to, tag) { var const_spec_ctx = { "link_to": link_to, "tag" : tag, "submited": true }; var linked = ctx.linker.linked(helpers.merge_con texts(const_spec_ctx, { "item_ex": proxy })); helpers.for_each(linked.values, function(id) { links.push(helpers.merge_contexts(const_ spec_ctx, { "with_id": id })); ap.add_association_description(id, null, null, tag); }); } get_associated("Contact", "direct"); get_associated("Employee", "direct"); get_associated("Account", "direct"); get_associated("Opportunity", "direct"); get_associated("Contact", "mvg"); get_associated("Employee", "mvg"); var fields_to_copy = { "Type": null, "Priority": null, "Status": null, "Due": null } for (var field in fields_to_copy) fields_to_copy[field] = proxy.get_property(field ); for (var key in new_ol_ids) { var new_ol = ap.item_wrapper(ctx.session.open_it em(new_ol_ids[key])); var similar = find_similar(new_ol); var new_proxy = similar != null ? ap.get_proxy_i tem(similar, null, {}) : null; if (new_proxy != null) { ap.log(ap.ol_to_string(similar.item_ex() ) + "removed as similar event modification."); similar.item().remove(); } else new_proxy = ap.create_proxy_item(new_ol. item_ex()); for (var field in fields_to_copy) new_proxy.set_property(field, fields_to_ copy[field]); // operation_ctx.pr oxy = new_proxy;

// = new_ol.item_ex(); m_ex());

operation_ctx.ol

ap.process_ol_item_changes(new_proxy, new_ol.ite ctx.save_helper.save_and_disable_events(new_prox y.fcd_item); ctx.save_helper.disable_events(new_ol.item(), 2) ; } } } } var activity_processor_extention = function(ctx, ap){ var employee_link = ctx.data_model.links.get_link({ "type": "Action", "l ink_to": "Employee", "tag": "mvg" }).link; this.process_association = function(item_ex, created){ var type_id = item_ex.get_type(); if(created && type_id == employee_link.association_type && ap.is _current_user(employee_link.resolve_association(ctx, item_ex.fcd_item))) { var proxy = util_get_proxy_from_association(ctx, item_ex ); if(proxy != null) ap.process_changes(proxy, created); } } } function contact_conversion_helper() { function personal_address_type(ctx) { return ctx.data_model.contact_personal_address_link.link_to; } function null_to_empty(value) { return value == null ? "" : value; } function find_address(ctx, item_ex, country, state, city, address) { var filter = ctx.session.create_criteria("and"); filter.add(ctx.session.create_expression("Country", "eq", null_t o_empty(country))); filter.add(ctx.session.create_expression("State", "eq", null_to_ empty(state))); filter.add(ctx.session.create_expression("City", "eq", null_to_e mpty(city))); filter.add(ctx.session.create_expression("Street Address", "eq", null_to_empty(address))); // filter.add(ctx.session.create_expression("BogusParentId", "eq", item_ex.get_id())); return ctx.session.find_item(personal_address_type(ctx), filter) ; } this.converted_to_platform = function(ctx, options, item_ex) {

function find_and_save(country, state, city, address, postal_cod e) { country = item_ex.get_property(country); state = item_ex.get_property(state); city = item_ex.get_property(city); address = item_ex.get_property(address); postal_code = item_ex.get_property(postal_code); var primary = ctx.linker.linked({"item_ex": item_ex, "li nk_to": personal_address_type(ctx), "tag": "direct" }).value; if (null_to_empty(country) + null_to_empty(state) + null _to_empty(city) + null_to_empty(address) != "") { var address_item = find_address(ctx, item_ex, co untry, state, city, address); if (address_item == null) { address_item = ctx.session.create_item(p ersonal_address_type(ctx)); address_item["Country"] = country; address_item["State"] = state; address_item["City"] = city; address_item["Street Address"] = address ; address_item["Postal Code"] = postal_cod e; address_item["SiebelShared"] = false; address_item.save(); } ctx.linker.link({ "item_ex": item_ex, "with_id": address_item.id(), "tag": "mvg", "submited": true }); if (primary == null) primary = address_item.id(); } if (primary != null) ctx.linker.link({ "item_ex": item_ex, "link_to": personal_address_type(ctx), "with_id": primary, "tag": "direct", "submited": tr ue }); //if (item_ex.get_property("Parent Account Name") == nul l) // } find_and_save("Home Address Country", "Home Address State", "Hom e Address City", "Home Address Street", "Home Address Postal Code"); find_and_save("Business Address Country", "Business Address Stat e", "Business Address City", "Business Address Street", "Business Address Postal Code"); } this.converting_to_native = function(ctx, options, item_ex) { var primary_personal_id = item_ex.get_property("Primary Personal Address Id"); var primary_business_id = item_ex.get_property("Primary Address Id"); if (primary_personal_id != null) { item_ex.set_property("Parent Account Name", "");

var address_item = ctx.session.open_item(primary_persona l_id); if (address_item != null) { item_ex.set_property("Home Address City", addres s_item["City"]); item_ex.set_property("Home Address Country", add ress_item["Country"]); item_ex.set_property("Home Address Postal Code", address_item["Postal Code"]); item_ex.set_property("Home Address State", addre ss_item["State"]); item_ex.set_property("Home Address Street", addr ess_item["Street Address"]); } } if (primary_business_id != null) { var address_item = ctx.session.open_item(primary_busines s_id); if (address_item != null) { item_ex.set_property("Business Address City", ad dress_item["City"]); item_ex.set_property("Business Address Country", address_item["Country"]); item_ex.set_property("Business Address Postal Co de", address_item["Postal Code"]); item_ex.set_property("Business Address State", a ddress_item["State"]); item_ex.set_property("Business Address Street", address_item["Street Address"]); } } } this.set_visible = function(ctx, options, item_ex, visible) { item_ex.set_property("InvisibleOnGrids", visible ? null : "true" ); } } /* GG 7/2/13: SIA Upg: Inactivated Code function item_already_synched(item) { var FLAG_SYNCHRONIZED = 0x20000000; return (item != null && !helpers.is_new_item(item) && item["ObjectState" ] != undefined && ((item["ObjectState"] & FLAG_SYNCHRONIZED) != 0)); } */

You might also like