SugarCRM - 如何使用Web服务响应填充某些字段?

时间:2013-03-07 13:45:38

标签: web-services sugarcrm

我的index.php文件是用糖调用Web服务的,当我在我的本地Apache上运行它时,它返回我作为响应这个结果是可以的:

<soapenv:Envelope   <soapenv:Body> <ns:CommandResponseData> 
 <ns:Operation  name="BalanceAdjustment"> </ns:Operation>  
</ns:CommandResponseData> </soapenv:Body> </soapenv:Envelope>

我在详细信息视图中创建了一个额外的按钮,我计划调用此Web服务,但我不知道如何绑定该按钮,我的index.php文件以及该Web服务的结果以打包在某个字段中。 出于测试目的,我想在接触模块的注释字段中将此完整响应放在示例中:以便字段注释应包含上面的整个响应(我稍后会解析它)。

我创建了新按钮(当前没有做任何事情)

我在view.detail.php中创建了按钮。

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
require_once('include/json_config.php'); 
require_once('include/MVC/View/views/view.detail.php'); 
class ContactsViewDetail extends ViewDetail
{
    function ContactsViewDetail()
    {
        parent::ViewDetail();
    }
    function display()
    {
        $this->dv->defs['templateMeta']['form']['buttons'][101] = array (
            'customCode' => '<input title="Call" accesskey="{$APP.LBL_PRINT_PDF_BUTTON_KEY}" class="button" onClick="javascript:CustomFunctionHere();" name="tckpdf" value="Call" type="button">');
        parent::display();
    }
}
?>

我将非常感谢您的帮助。所以概括一下:有了这个我的按钮,我想调用我的index.php文件,该文件将调用web服务,我想在我的字段中设置web服务响应评论(我在index.php文件中得到响应为htmlspecialchars($client->__getLastResponse()

这是我目前用来调用某些Web服务的整个index.php文件。

    <?php
        include_once 'CommandRequestData.php';
        include_once 'CommandResponseData.php';

        $client = new SoapClient("http://127.0.0.1:8181/TisService?WSDL", array(
              "trace"      => 1,        // enable trace to view what is happening
              "exceptions" => 1,        // disable exceptions
              "cache_wsdl" => 0)        // disable any caching on the wsdl, encase you alter the wsdl server
          );

        $req = new CommandRequestData();

        $req->Environment->Parameter[0]->name = "ApplicationDomain";
        $req->Environment->Parameter[0]->value = "CAO_LDM_00";
        $req->Environment->Parameter[1]->name = "DefaultOperationNamespace";
        $req->Environment->Parameter[1]->value = "CA";

        $req->Command->Operation->namespace = "CA";
        $req->Command->Operation->name = "BalanceAdjustment";
        $req->Command->Operation->ParameterList->StringParameter[0]->name = "CustomerId";
        $req->Command->Operation->ParameterList->StringParameter[0]->_ = "387671100009";
        $req->Command->Operation->ParameterList->IntParameter[0]->name = "AmountOfUnits";
        $req->Command->Operation->ParameterList->IntParameter[0]->_ = "1000";
        $req->Command->Operation->ParameterList->IntParameter[1]->name = "ChargeCode";
        $req->Command->Operation->ParameterList->IntParameter[1]->_ = "120400119";

        try {
            $result = $client->ExecuteCommand($req);
$result->CommandResult->OperationResult->Operation->name . "<br /><br />";          
        }
        catch(SoapFault $e){
            echo "<br /><br />SoapFault: " . $e . "<br /><br />";
        }
        catch(Exception $e){

        }

        echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";
    ?>

0 个答案:

没有答案