How do I create a label field that shows a warning or not?

I have an API that returns true or false based on if the id is associated with a course that has been billed.  I needed to create a API, because the billed value is in a  parent module.

How do a create a custom field that is a label that displays a warning message based on a true value?

Thank you

  • Hi

    Perhaps you may prefer to apply the custom Dependency SetColor.

    Save the code bellow in the file custom/include/Expressions/Actions/SetColorAction.php

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?php
    /*
    * Your installation or use of this SugarCRM file is subject to the applicable
    * terms available at
    * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
    * If you do not agree to all of the applicable terms or do not have the
    * authority to bind the entity as an authorized representative, then do not
    * install or use this SugarCRM file.
    *
    * Copyright (C) SugarCRM Inc. All rights reserved.
    */
    /**
    * Class SetColorAction
    *
    * SugarLogic Action to set a color to a field
    */
    require_once("include/Expressions/Actions/AbstractAction.php");
    class SetColorAction extends AbstractAction
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Create the file custom/Extension/<module>/Ext/Dependencies/SetColor.php with content bellow, obviously update it accordingly:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <?php
    $dependencies['Products']['setcolor'] = [
    'hooks' => ["edit", "view"],
    'trigger' => 'equal($the_field_c, true)',
    'triggerFields' => ['the_field_c'],
    'onload' => true,
    'actions' => [
    [
    'name' => 'SetColor',
    'params' => [
    'target' => 'the_field_c',
    'value' => '"label red"',
    'colors' => 'createList("label red")',
    'errorValue' => '"label red"',
    ],
    ],
    ],
    ];
    ?>
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Run the following repair actions:

    • Quick Repair and Rebuild
    • Rebuild Sugar Logic Functions
    • Rebuild Javascript Languages
    • Rebuild JS Grouping Files
    • Clear Additional Cache

    Finally clear browser cache and enjoy it.

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • You can use the "related" Sugar Logic function in the trigger line of André's code to get the value of the field in the parent module.

  • I just want it to return a message to the screen saying this course has been billed.

    Sorry, I am having trouble understanding what the code is doing in order to translate it to what I need.

    Where would you add the Action to a field?

  • What about having e checkox field for the true and false value of "billed"?

    Then you could create a message text field which is calculated and dependent.

    The formula for the calculated value of the text could be: ifElse($billed_c,"BILLED","")

    The dependency formula for visibility could be: $billed_c

    Now if the billed flag is set the textfield will be shown with the text BILLED.

    Everything can be done in Studio resp. Modulebuilder

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • The answer to whether the course has been billed or not is on a parent module.  The problem is I can't access that from studio, so I need to write code to do it.

  • "I needed to create a api because the billed value is on a parent module" 
    Is there a direct relationship between the two? Which you could retrieve with load_relationship() on either side of the relationship? If so you can work with a computed value using the related property where you pick up the 'billed' property from the parent (if that is available). And if that is the case you can create addvalidationtask on the child that does the check and shows an warning (https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.0/Cookbook/Adding_Field_Validation_to_the_Record_View/)

    Another aproach would be to have an validationtask on the child that loads data using your api and depending on that throws the error or not. Here is some information you can use to start with: https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/1340/record-js---addvalidationtask---fetch-data

    Be aware that the save function of create and record are a bit different. I don't know if this is still the case for 10.x branch but in previous branches the difference would cause validationtasks to be ignored on the create view becuase the way save waterfall function was implemented.

  • In the formular editor of the studio you can address related fields too.

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH