SugarCRM:PHP没有在自定义按钮上从ajax执行

时间:2017-01-19 18:36:48

标签: php ajax sugarcrm

我在自定义按钮上调用ajax时出现问题。自定义按钮位于案例列表视图中,列表中的每个案例都有一个。单击时,此按钮应执行对自定义端点的ajax调用,将assigned_user_id更新为当前登录的用户,并重定向到与该按钮关联的大小写。

目前,我正在点击端点,并且可以通过ajax调用记录正在发送的案例的ID,但无法通过调用来更新案例分配的用户。

这是ajax调用:

function take_ticket(url, id) {
    $.ajax({
        url: '/custom/modules/Cases/assign_ticket.php',
        contentType: 'JSON',
        data: {
            'id': id
        },
        success: function(response){
            window.location = url;
            //alert(response);
        },
        error: function(response) {
            alert('Error');
        }
    });
    return false;
}

这是我创建的自定义端点(请注意,我正在对用户ID进行硬编码以进行测试):

<?php
if ($_GET['id']) {
    $test = $_GET['id'];
    updateUser($test);
}

function updateUser($test) {
    $case = new aCase();
    $case->retrieve($test);
    $case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'
    $case->save();  
}
?>

如果我删除所有案例创建/更新逻辑并且只是echo $ test,我会得到我期望的响应。但是,有了更新逻辑,即使我只是回显$ test,我的响应也是空的,并且案例没有得到更新。

编辑:由于获得了无效的入口点错误,我尝试在include / MVC / Controller / entry_point_registry.php中为modules / Cases / case.php添加一个入口点:

$entry_point_registry = array(
    'cases' => array('file' => 'modules/Cases/Case.php', 'auth' => false),
    'takeTicket' => array('file' => 'custom/modules/Cases/assign_ticket.php', 'auth' => false),
    'emailImage' => array('file' => 'modules/EmailMan/EmailImage.php', 'auth' => false),
.....

这不起作用,所以我在custom / Extension / application / Ext / EntryPointRegistry / customEntryPoint.php中添加了一个条目:

$entry_point_registry['takeTicket'] = array(
    'file' => 'custom/modules/Cases/assign_ticket.php',
    'auth' => false
);

$entry_point_registry['cases'] = array(
    'file' => 'modules/Cases/Case.php',
    'auth' => false
);

1 个答案:

答案 0 :(得分:1)

根据提供的信息,文件中有一些更改:

定制/模块/案例/ assign_ticket.php

$case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'; //Added semicolon (syntax error)

定制/扩展/应用/外部/ EntryPointRegistry / customEntryPoint.php

    'auth' => true //You need to be authenticated/authorised to perform saves on records

的Ajax:

        url: 'index.php?entryPoint=takeTicket', //If you check the Sugar docs carefully, you'll see that the URL you need to call is index.php?entryPoint={yourEntryPointRegistryKey}