Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature set from related record logic #396

Open
wants to merge 2 commits into
base: hotfix
Choose a base branch
from

Conversation

mpuyosa91
Copy link
Contributor

@mpuyosa91 mpuyosa91 commented Nov 16, 2023

Sometimes it is needed to hold a specific value from a related record. This is similar to #394 but copying the value of a field of the related record. This PR also needs #395

Caution

DO NOT MERGE BEFORE #395

Description

  • ESLint fixes on modified files.
  • core/app/common/src/lib/record/field.model.ts new assignation approach for value, valueList, valueObject.
  • core/app/core/src/lib/fields/field-logic/actionable-field-logic/actionable-field-logic.action.ts Abstract class ActionableFieldLogicActionHandler that can hold general and reusable functions across field logic actions.
  • core/app/core/src/lib/fields/field-logic/set-field-from-related/set-field-from-related.action.ts Actual SetFieldFromRelatedAction class that holds the logic.
  • core/app/core/src/lib/fields/field-logic/field-logic.manager.ts:[40, 66, 78] Registration of the SetFieldFromRelatedAction as Field Logic Action.
  • core/app/core/src/lib/services/logic/active-logic-checker.service.ts: Creation of ActiveLogicChecker class that holds the routine for checking if a logic is active or not.
  • core/app/core/src/lib/core.ts:364 Export created classes

Motivation and Context

A client needed to copy the value of a related record into the Cases module each time that related record changed, but this was not possible.

How To Test This

  1. Create all files in Test Environment
  2. Rebuild the whole project, Quick Repair & Rebuild, executing database scripts if needed.
  3. Go to any or Create a new Case, but open in Edit Mode
  4. Check the current value of the ASSIGNED TO JOB TITLE field
  5. Change the field ASSIGNED TO to any other user.
  6. Check again the value of the ASSIGNED TO JOB TITLE field, should hold the Job Title of the selected User

Test Environment

public/legacy/custom/Extension/modules/Cases/Ext/Vardefs/assigned_to_job_title.php

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$dictionary['Case']['fields']['assigned_to_job_title'] = [
    'name' => 'assigned_to_job_title',
    'vname' => 'LBL_ASSIGNED_TO_JOB_TITLE',
    'type' => 'varchar',
    'len' => '50',
    'readonly' => true,
    'logic' => [
        'setFromRelated' => [
            'key' => 'setFromRelated',
            'modes' => ['edit', 'create'],
            'params' => [
                'fieldDependencies' => [
                    'assigned_user_name',
                ],
                'activeOnFields' => [
                    'assigned_user_name' => ['operator' => 'not-empty'],
                ],
                'activeState' => [
                    'linkFieldName' => 'assigned_user_name',
                    'toCopyFromFieldName' => 'title'
                ],
            ]
        ],
    ]
];

public/legacy/custom/Extension/modules/Cases/Ext/Language/en_us.assigned_to_job_title.php

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$mod_strings['LBL_ASSIGNED_TO_JOB_TITLE'] = 'Assigned To Job Title';

public/legacy/custom/modules/Cases/metadata/detailviewdefs.php

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$viewdefs["Cases"] = [
    "DetailView" => [
        "templateMeta" => [
            "form" => [
                "buttons" => [
                    0 => "EDIT",
                    1 => "DUPLICATE",
                    2 => "DELETE",
                    3 => "FIND_DUPLICATES",
                ],
            ],
            "maxColumns" => "2",
            "widths" => [
                0 => [
                    "label" => "10",
                    "field" => "30",
                ],
                1 => [
                    "label" => "10",
                    "field" => "30",
                ],
            ],
            "useTabs" => true,
            "tabDefs" => [
                "LBL_CASE_INFORMATION" => [
                    "newTab" => true,
                    "panelDefault" => "expanded",
                ],
            ],
        ],
        "topWidget" => [
            "type" => "statistics",
            "options" => [
                "statistics" => [
                    [
                        "labelKey" => "",
                        "type" => "case-days-open",
                        "endLabelKey" => "LBL_STAT_DAYS",
                        "hideValueIfEmpty" => true,
                    ],
                ],
            ],
        ],
        "sidebarWidgets" => [
            [
                "type" => "record-thread",
                "labelKey" => "LBL_CASE_UPDATES",
                "options" => [
                    "recordThread" => [
                        "module" => "case-updates",
                        "class" => "case-updates",
                        "filters" => [
                            "parentFilters" => [
                                "id" => "case_id",
                            ],
                            "orderBy" => "date_entered",
                            "sortOrder" => "DESC",
                        ],
                        "item" => [
                            "itemClass" => "case-updates-item pt-2 pb-2",
                            "collapsible" => true,
                            "dynamicClass" => ["source", "internal"],
                            "layout" => [
                                "header" => ["rows" => []],
                                "body" => [
                                    "rows" => [
                                        [
                                            "align" => "end",
                                            "justify" => "between",
                                            "cols" => [
                                                [
                                                    "field" => "author",
                                                    "labelDisplay" => "none",
                                                    "hideIfEmpty" => true,
                                                    "class" =>
                                                        "font-weight-bold item-title",
                                                ],
                                                [
                                                    "field" => "internal",
                                                    "labelDisplay" => "inline",
                                                    "labelClass" => "m-0",
                                                    "display" => "none",
                                                    "hideIfEmpty" => true,
                                                    "class" =>
                                                        "small ml-auto font-weight-light",
                                                ],
                                            ],
                                        ],
                                        [
                                            "align" => "start",
                                            "justify" => "start",
                                            "class" =>
                                                "flex-grow-1 item-content",
                                            "cols" => [
                                                [
                                                    "field" => [
                                                        "name" => "description",
                                                        "type" => "html",
                                                    ],
                                                    "labelDisplay" => "none",
                                                ],
                                            ],
                                        ],
                                        [
                                            "justify" => "left",
                                            "class" =>
                                                "flex-grow-1 item-content-extra",
                                            "cols" => [
                                                [
                                                    "field" => [
                                                        "name" => "notes",
                                                        "type" => "line-items",
                                                        "lineItems" => [
                                                            "labelOnFirstLine" => true,
                                                            "definition" => [
                                                                "name" =>
                                                                    "notes_fields",
                                                                "vname" =>
                                                                    "LBL_FILENAME",
                                                                "type" =>
                                                                    "composite",
                                                                "layout" => [
                                                                    "filename",
                                                                ],
                                                                "display" =>
                                                                    "inline",
                                                                "attributeFields" => [
                                                                    "filename" => [
                                                                        "name" =>
                                                                            "filename",
                                                                        "type" =>
                                                                            "file",
                                                                        "vname" =>
                                                                            "LBL_FILENAME",
                                                                        "labelKey" =>
                                                                            "LBL_FILENAME",
                                                                        "required" => true,
                                                                        "valueParent" =>
                                                                            "record",
                                                                        "showLabel" => [
                                                                            "*",
                                                                        ],
                                                                    ],
                                                                ],
                                                            ],
                                                        ],
                                                    ],
                                                    "labelDisplay" => "none",
                                                    "hideIfEmpty" => false,
                                                    "class" =>
                                                        "small ml-auto font-weight-light",
                                                ],
                                            ],
                                        ],
                                        [
                                            "justify" => "end",
                                            "class" => "flex-grow-1",
                                            "cols" => [
                                                [
                                                    "field" => "date_entered",
                                                    "labelDisplay" => "none",
                                                    "hideIfEmpty" => true,
                                                    "class" =>
                                                        "small ml-auto font-weight-light",
                                                ],
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                        ],
                        "create" => [
                            "presetFields" => [
                                "parentValues" => [
                                    "id" => "case_id",
                                ],
                            ],
                            "layout" => [
                                "header" => ["rows" => []],
                                "body" => [
                                    "rows" => [
                                        [
                                            "justify" => "start",
                                            "class" => "flex-grow-1",
                                            "cols" => [
                                                [
                                                    "field" => [
                                                        "name" => "description",
                                                        "metadata" => [
                                                            "rows" => 3,
                                                        ],
                                                    ],
                                                    "labelDisplay" => "top",
                                                    "class" => "flex-grow-1",
                                                ],
                                            ],
                                        ],
                                        [
                                            "align" => "end",
                                            "justify" => "start",
                                            "class" => "flex-grow-1",
                                            "cols" => [
                                                [
                                                    "field" => "internal",
                                                    "labelDisplay" => "inline",
                                                ],
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
                "acls" => [
                    "Cases" => ["view", "list"],
                ],
            ],
            [
                "type" => "statistics",
                "labelKey" => "LBL_NUMBER_OF_CASES_PER_ACCOUNT",
                "options" => [
                    "sidebarStatistic" => [
                        "rows" => [
                            [
                                "align" => "start",
                                "cols" => [
                                    [
                                        "labelKey" =>
                                            "LBL_TOTAL_CASES_FOR_THIS_ACCOUNT",
                                        "size" => "medium",
                                    ],
                                ],
                            ],
                            [
                                "align" => "start",
                                "cols" => [
                                    [
                                        "statistic" => "cases-per-account",
                                        "size" => "xx-large",
                                        "bold" => true,
                                        "color" => "green",
                                    ],
                                ],
                            ],
                            [
                                "align" => "start",
                                "cols" => [
                                    [
                                        "labelKey" => "LBL_SINCE",
                                        "size" => "regular",
                                    ],
                                    [
                                        "statistic" =>
                                            "get-account-date-entered",
                                        "size" => "regular",
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
                "acls" => [
                    "Cases" => ["view", "list"],
                    "Accounts" => ["view", "list"],
                ],
            ],
        ],
        "panels" => [
            "lbl_case_information" => [
                0 => [
                    0 => [
                        "name" => "case_number",
                        "label" => "LBL_CASE_NUMBER",
                    ],
                    1 => "priority",
                ],
                1 => [
                    0 => [
                        "name" => "state",
                        "comment" => "The state of the case (i.e. open/closed)",
                        "label" => "LBL_STATE",
                    ],
                    1 => "status",
                ],
                2 => [
                    0 => "type",
                    1 => "assigned_to_job_title",
                ],
                3 => [
                    0 => [
                        "name" => "name",
                        "label" => "LBL_SUBJECT",
                    ],
                ],
                4 => [
                    0 => "description",
                ],
                5 => [
                    0 => "resolution",
                ],
                6 => [
                    0 => [
                        "name" => "assigned_user_name",
                        "label" => "LBL_ASSIGNED_TO",
                    ],
                ],
                7 => [
                    0 => [
                        "name" => "date_entered",
                        "customCode" =>
                            '{$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}',
                    ],
                    1 => [
                        "name" => "date_modified",
                        "label" => "LBL_DATE_MODIFIED",
                        "customCode" =>
                            '{$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}',
                    ],
                ],
            ],
        ],
    ],
];

public/legacy/custom/modules/Cases/metadata/editviewdefs.php

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$viewdefs["Cases"] = [
    "EditView" => [
        "templateMeta" => [
            "maxColumns" => "2",
            "widths" => [
                0 => [
                    "label" => "10",
                    "field" => "30",
                ],
                1 => [
                    "label" => "10",
                    "field" => "30",
                ],
            ],
            "includes" => [
                0 => [
                    "file" => "include/javascript/bindWithDelay.js",
                ],
                1 => [
                    "file" =>
                        "modules/AOK_KnowledgeBase/AOK_KnowledgeBase_SuggestionBox.js",
                ],
                2 => [
                    "file" => "include/javascript/qtip/jquery.qtip.min.js",
                ],
            ],
            "useTabs" => false,
            "tabDefs" => [
                "LBL_CASE_INFORMATION" => [
                    "newTab" => false,
                    "panelDefault" => "expanded",
                ],
            ],
            "form" => [
                "enctype" => "multipart/form-data",
            ],
        ],
        "panels" => [
            "lbl_case_information" => [
                0 => [
                    0 => [
                        "name" => "case_number",
                        "type" => "readonly",
                    ],
                    1 => "priority",
                ],
                1 => [
                    0 => [
                        "name" => "state",
                        "comment" => "The state of the case (i.e. open/closed)",
                        "label" => "LBL_STATE",
                    ],
                    1 => "status",
                ],
                2 => [
                    0 => "type",
                    1 => "assigned_to_job_title",
                ],
                3 => [
                    0 => [
                        "name" => "name",
                        "displayParams" => [
                            //'size' => 75,
                        ],
                    ],
                    1 => [
                        "name" => "suggestion_box",
                        //'studio' => 'visible',
                        "label" => "LBL_SUGGESTION_BOX",
                    ],
                ],
                4 => [
                    0 => [
                        "name" => "description",
                    ],
                ],
                5 => [
                    0 => [
                        "name" => "resolution",
                        "nl2br" => true,
                    ],
                ],
                6 => [
                    0 => [
                        "name" => "update_text",
                        "studio" => "visible",
                        "label" => "LBL_UPDATE_TEXT",
                    ],
                ],
                7 => [
                    0 => [
                        "name" => "internal",
                        "studio" => "visible",
                        "label" => "LBL_INTERNAL",
                    ],
                ],
                8 => [
                    0 => [
                        "name" => "case_update_form",
                        "studio" => "visible",
                    ],
                ],
                9 => [
                    0 => "assigned_user_name",
                ],
            ],
        ],
    ],
];

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • I have read the How to Contribute guidelines.

@mpuyosa91 mpuyosa91 changed the title Feature set from related record logic Closes #396 Feature set from related record logic Dec 6, 2023
@mpuyosa91 mpuyosa91 changed the title Closes #396 Feature set from related record logic Closes #396 - Feature set from related record logic Dec 6, 2023
mpuyosa91 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 6, 2023
@mpuyosa91 mpuyosa91 force-pushed the feature/set_from_related_record_logic branch from c9f7119 to 5d0879d Compare December 6, 2023 13:21
@mpuyosa91 mpuyosa91 changed the title Closes #396 - Feature set from related record logic Feature set from related record logic Dec 6, 2023
@clemente-raposo clemente-raposo added Status:Assessed PRs that have been tested and confirmed to resolve an issue by a core team member Status: Requires Code Review Status:Requires Updates Issues & PRs which requires input or update from the author labels Dec 7, 2023
mpuyosa91 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 8, 2023
@mpuyosa91 mpuyosa91 force-pushed the feature/set_from_related_record_logic branch from 5d0879d to 347ad32 Compare December 8, 2023 11:20
@mpuyosa91 mpuyosa91 force-pushed the feature/set_from_related_record_logic branch from 347ad32 to 2f6c808 Compare December 8, 2023 11:22
@mpuyosa91 mpuyosa91 added Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution and removed Status:Requires Updates Issues & PRs which requires input or update from the author labels Dec 8, 2023
@clemente-raposo clemente-raposo added Status: Passed Code Review and removed Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution Status: Requires Code Review labels Dec 14, 2023
Copy link

@johnM2401 johnM2401 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be pulling the User's Job Title as expected, with given test steps.
Record saving doesn't seem negatively affected.

I had noticed that if the logic condition is met via Workflow
(ie a Workflow that sets the Assigned User)
The Logic is not fired.

If this is expected at this time, then this LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status:Assessed PRs that have been tested and confirmed to resolve an issue by a core team member Status: Passed Code Review Status: Passed Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants