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



我在对自定义按钮进行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();  
}
?>

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

编辑:由于得到一个无效的入口点错误,我尝试在include/MVC/Controller/entry_point_registry.php中为模块/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
);

根据提供的信息,对文件进行了一些更改:

custom/modules/Cases/assign_ticket.php

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

custom/Extension/application/Ext/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}

最新更新