Share a javaScript function between 2 different modules


Sugar Version - 7.9

Have a custom JS function setDate in Products module and would want that to be shared in Quotes module. So that we can reuse the function. Tried with JS groupings and couldn't trigger the function from Quotes modules.

Call from Quotes modules:

this.model.on('change:field_c', this.setDate, this);


JS-Grouping: Tried with sugar_grp7.min.js:

$js_groupings[$key]['custom/Products/quote-list.js'] = 'include/javascript/sugar_grp7.min.js';
$js_groupings[$key]['custom/Quotes/record.js'] = 'include/javascript/sugar_grp7.min.js';


Tried creating new grouping.js file:

$js_groupings[$key]['custom/Products/quote-list.js'] = 'include/javascript/newGrouping.js';
$js_groupings[$key]['custom/Quotes/record.js'] = 'include/javascript/newGrouping.js';

Any idea would be highly appreciated.

Parents
  • Hello Venkatesh Babu,

    Use Below Code:

    $js_groupings[] = $sugar_grp1 = array_merge($sugar_grp1, array(
    'path/to/your.js' => 'include/javascript/sugar_grp1.js'
    )
    );

    Then you can use your JS Function on any page.

    After very much research JSGrouping worked this way, the official document never worked for me.

  • Thanks Hiren Darji

    This is how my Js grouping looks like in `src/custom/Extension/application/Ext/JSGroupings/customGrouping.php`

    $js_groupings[] = $sugar_grp7 = array_merge($sugar_grp7, array(
            'Path/to/js' => 'include/javascript/sugar_grp7.min.js',
        )
    );

    Firstly, I couldn't see the JS file included in sugar_grp7.min.js, while debugging via chrome browser Dev tools (sources tab)

    Secondly, I couldn't trigger the function which is available in `Path/to/js`. This is how my trigger looks to call the JS function. Should it be called differently?

    this.model.on('change:field_c', this.setDate, this);

    Thanks again for your time in sorting this out for me.

Reply
  • Thanks Hiren Darji

    This is how my Js grouping looks like in `src/custom/Extension/application/Ext/JSGroupings/customGrouping.php`

    $js_groupings[] = $sugar_grp7 = array_merge($sugar_grp7, array(
            'Path/to/js' => 'include/javascript/sugar_grp7.min.js',
        )
    );

    Firstly, I couldn't see the JS file included in sugar_grp7.min.js, while debugging via chrome browser Dev tools (sources tab)

    Secondly, I couldn't trigger the function which is available in `Path/to/js`. This is how my trigger looks to call the JS function. Should it be called differently?

    this.model.on('change:field_c', this.setDate, this);

    Thanks again for your time in sorting this out for me.

Children