SuiteCRM PopUps (journey)

Hey Hey

Shout out to pgr and p.konetskiy - massive help so far in getting me where i am! :smiley:

What iā€™m trying to achieve is a Pop up message to appear when a Contact record is opened up and thereā€™s an active ā€˜Safety Alertā€™ present within the personā€™s record. (My last quest relating to this was to color the fields to highlight them just so and now iā€™m wanting to take it further)

So what Iā€™ve tried so far (unsuccessfully i may add) - just hoping to get a nudge in the right direction.

What Iā€™ve got so far is the directory tree.

SugarPopUp(folder)
manifest.php(file)
-custom(folder)
-include(folder)
-custompop(folder)
custom_popup_js_include.js(file)
customPopUpContacts.js(file)

Iā€™ve got this in my manifest.php

<?php
    $manifest = array(
                array(
                        'acceptable_sugar_versions' => array()
                ),
                array(
                        'acceptable_sugar_flavors' => array()
                ),
                'readme' => 'Please consult the operating manual for detailed installation instructions.',
                'key' => 'customSugarMod1',
                'author' => 'Mark G',
                'description' => 'Adds pop-up Message when a contact has a safety alert.',
                'icon' => '',
                'is_uninstallable' => true,
                'name' => 'Pop-Up Dialog if Safety Alert',
                'published_date' => '2023-01-30 12:00:00',
                'type' => 'module',
                'version' => 'v1.7',
                'remove_tables' => 'prompt'
        );

        $installdefs = array(
                'id' => 'customSugarMod1',
                'copy' => array(
                        array(
                                'from' => '<basepath>/custom/',
                                'to' => 'custom/'
                        )
                ),
                'logic_hooks' => array(
                        array(
                                'module' => 'Contacts',
                                'hook' => 'after_ui_frame',
                                'order' => 1,
                                'description' => 'Creates pop-up message on load if user inactive',
                                'file' => 'custom/include/customPopUps/custom_popup_js_include.php',
                                'class' => 'CustomPopJs',
                                'function' => 'getContactJs'
                        )
                )
        );

And iā€™ve got this in the include php file

<?php
if (! defined('sugarEntry') || ! sugarEntry) {
    die('Not a valid entry point.');
}
class CustomPopJs {
    function getContactJs($event, $arguments) {
        if ($_REQUEST['action'] != 'EditView') {
            return;
        }
        echo '<script type="text/javascript" src="custom/include/customPopUps/customPopUpContacts.js"></script>';
    }
}

And this is in the javascript thatā€™s called.

document.addEventListener('DOMContentLoaded', function() {
    checkUserStatus();
}, false);


function checkUserStatus()
{
    if($("#safetyalert_c").val() != "YES" )
    {   
        YAHOO.SUGAR.MessageBox.show({msg: 'There is an active safety alert present! ', title: 'Safety Alert!'} );
    }

}

The database field exactly is ā€˜safetyalert_cā€™ in contacts_cstm and thatā€™s a field setup in studio as a dropdown ā€˜YESā€™ or ā€˜NOā€™ value - thatā€™s what it looks like in the DB (field & value)

image

Am i going down the right train tracks?
image

Many thanks for your continued support! <3

2 Likes

This would be a nice Addon for someone to create :wink:

True, we have several add-on developers in this forum :crazy_face:

If it was me Iā€™d approach this by adding a ā€œnon-dbā€ field on the front end (assuming this is SuiteCRM 7),

Then use a function to calculate what the message shoudl be like:

 'function' => array(
        'name' => 'custom_message_c, 
        'returns' => 'html', 
        'onListView' => 'true',
         'include' => 'custom/modules/Contacts/Contacts_fields_functions.php'
    ),

Then just use PHP to output whatever you want based on whatever conditions you want.

Then I would use smarty templates to output the field as you like ie: ā€œredā€ color.

'customCode'=> <span style="color:red;">{$fields.custom_message_c.value}</span>

I think thatā€™s how I did it last time I had to do this.

1 Like