SugarCRM - how to populate some field with web ser

2019-06-13 17:36发布

I have my index.php file which is calling web service out of sugar and it returns me as response when I run it on my local Apache this result which is OK:

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

I created one additional button within Detail View which I plan to call this web service but I do not know how to bind that button, my index.php file and result from that web service to pack in some field. For testing purposes I would like to put this whole response on example in field Comment of Contact module: so that field Comment should Contain above whole response (I will later parse it).

I created new button (which does not do anything currently )

I created button in 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();
    }
}
?>

I will appreciate help with this. So to recapitulate : With this my button I want to call my index.php file which will call web service and I want to set web service response in my field Comment (I am getting response in index.php file as htmlspecialchars($client->__getLastResponse())

this is the whole index.php file that I am using currently to call some web service.

    <?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条回答
登录 后发表回答