如何:更改 SugarCRM 中的下拉值

HOW TO: Changing Dropdown Value in SugarCRM

我正在尝试通过单击按钮更改下拉列表的值,我使用的是 SugarCRM CE 6.5,这是我遇到的问题:

下面是我的代码:

-- detailviewdefs.php

<?php
$module_name = 'UA_Quotes';
$viewdefs [$module_name] = 
array (
'DetailView' => 
array (
 'templateMeta' => 
array (
  'include' => 
   array (
    0 =>
    array (
      'file' => 
      'custom/modules/UA_Quotes/JS/clickPayment.js',
      ),
    ),
  'form' => 
  array (
    'closeFormBeforeCustomButtons' => true,
    'buttons' => 
    array (
      0 => 'EDIT',  
      1 => 'DELETE',
      2 => 
      array (
        'customCode' => '{$Monthly_Payment}',
      ),
    ),
    'footerTpl' => 'modules/UA_Quotes/tpls/DetailViewFooter.tpl',
  ),
  'maxColumns' => '2',
  'widths' => 
  array (
    0 => 
    array (
      'label' => '10',
      'field' => '30',
    ),
    1 => 
    array (
      'label' => '10',
      'field' => '30',
    ),
  ),
  'useTabs' => false,
  'tabDefs' => 
  array (
    'LBL_EDITVIEW_PANEL2' => 
    array (
      'newTab' => false,
      'panelDefault' => 'expanded',
    ),
  ),
),
'panels' => 
array (
  'lbl_editview_panel2' => 
  array (
    0 => 
    array (
      0 => 'name',
      1 => 
      array (
        'name' => 'ua_contracts_ua_quotes_1_name',
      ),
    ),
    1 => 
    array (
      0 => 
      array (
        'name' => 'monthlystart_c',
        'label' => 'LBL_MONTHLYSTART',
      ),
      1 => 
      array (
        'name' => 'quote_stage',
        'studio' => 'visible',
        'label' => 'LBL_QUOTE_STAGE',
      ),
    ),
    2 => 
    array (
      0 => 
      array (
        'name' => 'monthlydeadline_c',
        'label' => 'LBL_MONTHLYDEADLINE',
      ),
    ),
  ),
),
),
);
?>

-- view.detail.php

<?php


require_once('include/MVC/View/views/view.detail.php');

class UA_QuotesViewDetail extends ViewDetail
{
public function __construct()
{
    parent::ViewDetail();
}

public function display()
{
    echo '<script type="text/javascript"    src="custom/modules/UA_Quotes/js/clickPayment.js"></script>';
    $groups = $this->bean->Get_Products($this->bean->id, true);
    $this->ss->assign('GROUPS', $groups);

    $this->ss->assign('NET_TOTAL', currency_format_number($this->bean->net_total_amount));
    $this->ss->assign('TOTAL', currency_format_number($this->bean->total_amount));
    $this->ss->assign('Monthly_Payment', '<input type="button" onclick="GetPayment();" value="Monthly Payment"/>');
    /*
    $this->dv->ss->assign('Monthly_Payment', '<input type="button" 
    onclick="alert(\'How to change status :(\')" value="Monthly Payment"/>');*/

    parent::display();
}
}

-- clickPayment.js

function GetPayment(){

var record = $("#record").val();
// var pathArray = window.location.href.split("=");
var fdata = { 'record':record };   
// console.log(pathArray[3]," - your Record ID");
$.ajax({
                    type: 'POST',                 
                    url: "custom/modules/UA_Quotes/js/changestatus.php?&fdata="+fdata+"",
                    data: fdata, //{recordID: pathArray[3]},
                    dataType: 'html',
                    async: false,
                    error: function(resp){},
                    success: function(resp){
                        location.reload(true);
                    }                     
                    /*  success:function(fdata){                     
                        console.log("Customer Status Change"); 
                         location.reload(true);        
                    },
                    error: function(fdata) {
                        // if error occured
                        console.log(" NA ");                     
                    }   */
                });
}

-- 最后,我的 changestatus.php

<?php

$myrecordID = $_POST['record'];
$focus = new UA_Quotes();
$focus->retrieve($myrecordID);
$focus->quote_stage_dom = 'Paid';

?>

很抱歉 post 的代码太长了,我已经和他们打交道好几天了,看来运气不好。 :( 任何帮助,将不胜感激!谢谢!

您报告的错误似乎是由于入口点使用不当造成的。

请尝试在 custom/include/MVC/Controller/entry_point_registry.php 中注册自定义入口点,如下所示:

$entry_point_registry['ChangeStatus'] = array('file' => 'modules/UA_Quotes/entrypoint/changestatus.php' , 'auth' => '1');

只需在您的入口点注册表中添加该行,如果该文件尚不存在,请在该位置添加一个具有该名称的文件。

数组中的file部分指向你的代码所在的位置,auth部分允许你指定用户是否需要认证或不需要访问入口点。

然后通过以下方式调用它:index.php?entryPoint=ChangeStatus&id=...(&to_pdf=true)

如果您希望响应为 json 或文本,则可能需要最后一个参数 &to_pdf=true。没有它,您将在答案中得到整个 html 页。

你可以在没有入口点的情况下通过添加一个控制器来完成它,然后通过以下方式从你的脚本中调用它:index.php?module=UA_Quotes&action=changestatus

顺便说一下,您在元数据中加载 javascript 文件并查看。在detailview应该足够了。

同意第一个答案。可能您可以尝试使用您端点的控制器来更改 changestatus.php 上的文件 例如:

http://techs.studyhorror.com/sugarcrm-how-add-custom-actions-i-46