4

I would like to use AJAX to update records' Status in a SugarCRM SubPanel. Below is an image of the project management modules I am working on.

In the image you can get a better idea to what I would like to achieve. On the left column I would like to add a new button that will allow a User to quickly mark a Project Task record as completed. This would be done by changing the Status field on that record to "Complete".

I can figure out how to add my new button but I am not sure how to update the record's status in this manner. I can figure out the JavaScript to make the AJAX call and update the UI but I don't really know where to have my AJAX POST to and stuff like that to update the record.

Would I need to make a new Controller so that I have a URL to post to? I'm hoping for a simple solution but if not maybe someone who is familiar with SugarCRM could point me in the right direction?

I would appreciate any help in this matter to get me closer to completion.

enter image description here

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
JasonDavis
  • 48,204
  • 100
  • 318
  • 537
  • Have you Googled it? If yes, then what's the difference between the Googled results vs the ones you want? – Jonast92 Aug 20 '13 at 15:22
  • 1
    @Jonast92 of course I have. The difference is there is no solid solution. I am hoping one of the SugarCRM gurus can point me in the right direction. There is only 1 article I have found through Google and it is the same article from 2008 re-published over and over and it requires the use of a paid plugin and is more of a hack then a real solution like I am trying to do. I believe the answer might be to build my own custom controller with which I could then make POST requests to using AJAX but I would prefer to get some input from others before wasting half a day on the wrong solution – JasonDavis Aug 20 '13 at 15:28
  • Fair enough, just really felt like asking this "simple" question even though you have 10 grand points, sometimes I just feel that the "what have I tried" and "what do I know about what's out there and why doesn't it fit my needs" part is missing :) – Jonast92 Aug 20 '13 at 15:43
  • There isn't a whole lot of SugarCRM information out there and I am new to the system – JasonDavis Aug 20 '13 at 16:04

1 Answers1

4

You can create your AJAX in a JS file in the custom directory...

custom/modules/Project/javascript/ajax.js

function updateStatus(project_task_id) {
    if (project_task_id) {
        $.ajax({
            url: 'index.php?to_pdf=true&module=Project&action=ChangeProjectTaskStatus&id=' + project_task_id,
            success: function() {

            // Reload subpanel
            showSubPanel('projects_project_tasks', null, true);
        }
    });
}

Then create a new PHP file with the action matching the file name…

custom/modules/Project/ChangeProjectTaskStatus.php

<?php
    if (!defined('sugarEntry') || !sugarEntry)
        die('Not A Valid Entry Point');

    $project_task = BeanFactory::getBean('ProjectTask');
    $project_task->retrieve($_GET['project_task_id']);

    // Update status logic goes here

    $project_task->save();

    exit();
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
  • 1
    I ended up using this method, on success callback from my AJAX request, I update several items in the page and it works great. The 1 issue I have not overcome yet is when I use the quickcreate form to add a new item, t reloads the subpanel and I lose all my formatting that is currently added in from a `process_record` Hook. Perhaps you have an idea for a solution to that? I am going to post a new question – JasonDavis Aug 25 '13 at 02:57
  • 2
    I added a edit to Karl's answer, but I guess it's not approved yet. You should be able use the following to reload the subpanel: showSubPanel('projects_project_tasks',null,true); And replace the project_project_tasks with whatever the relationship name is of the subpanel. It'll reload the subpanel from the server, so it should handle the formatting you already have in place. – Chad Hutchins Aug 25 '13 at 15:03
  • @ChadHutchins thanks for sharing that I was curious how to do that. I have done some testing but it seems this is not the solution that I need after-all. Unfortunately it seems when I run `showSubPanel()` it does not fire off the Hook `$hook_array['process_record']` so it does reload the Subpanel with my Updated record but I loses all my formatting that is applied to the records through that Hook. I have searched everywhere for a solution to this one but it appears it is a flaw in the Sugar platform. If you have any ideas on an alternative to that would love to hear it – JasonDavis Aug 25 '13 at 20:13
  • 1
    @jasondavis You might want to try to create a custom SugarField for your status field. Then SugarCRM will generate the view from the SugarField definitions. That'd keep you from having to use the process_record hook for display stuff. Then you'd be able to use showSubPanel() to reload the subpanels as needed. And for adding buttons to the subpanels, this may help: https://www.sugaroutfitters.com/blog/how-to-add-buttons-to-views-in-sugarcrm – Chad Hutchins Aug 26 '13 at 00:18
  • @ChadHutchins Thanks for your insight, I just saw this message but last night I actually gave this a little test and it does seem to be the only way to achieve this. Could you confirm, that custom fields will not show up in the "dropdown list" field list for module builder and can only be associated with a Var in code? Want to make sure I am using them correctly. Loving the sugar outfitters site too thanks – JasonDavis Aug 27 '13 at 13:08
  • @ChadHutchins Disregard my last question I found the answer here http://forums.sugarcrm.com/f6/how-custom-data-type-65379/#post229811 thanks – JasonDavis Aug 27 '13 at 14:48
  • @jasondavis awesome, glad you figured it out and thanks for checking out SugarOutfitters! – Chad Hutchins Aug 29 '13 at 09:07