Здравствуйте, я пытаюсь вызвать пользовательский API через этот код в sugarcrm:
({
extendsFrom: 'RowactionField',
defaultFirsName: 'first_name',
defaultLastName: 'last_name',
initialize: function (options) {
this._super('initialize', [options]);
this.def.first_name = _.isEmpty(this.def.first_name) ? this.defaultFirsName : this.def.first_name;
this.def.last_name = _.isEmpty(this.def.last_name) ? this.defaultLastName : this.def.last_name;
},
/** * Rowaction fields have a default event which calls rowActionSelect */
rowActionSelect: function () {
this.upper_name();
},
upper_name: function () {
var first = this.model.get(this.def.first_name);
var last = this.model.get(this.def.last_name);
var fullName = first + last;
if (fullName) {
app.alert.show('name-check-msg', {
level: 'success',
messages: 'Firstname and Lastname filled.',
autoClose: true
});
}
else {
app.alert.show('name-check-msg', {
level: 'error',
messages: 'First name and last name must be filled.',
autoClose: false
});
}
var self = this;
url = app.api.buildURL('Leads', 'UpperName', null, {
record: this.model.get('id')
});
app.api.call('GET', url, {
success: function (data) {
app.alert.show('itsdone', {
level: 'success',
messages: 'Confirmed to uppercase name.',
autoClose: true
});
},
error: function (error) {
app.alert.show('err', {
level: 'error',
title: app.lang.getAppString('ERR_INTERNAL_ERR_MSG'),
messages: err
});
},
});
}
})
имя "uppernamebutton.js", его функции, он проверяет, пусто ли имя и фамилия, и покажетсообщение об ошибке для заполнения полей затем вызывает API для Uppercase первых букв имен.
Вот код для пользовательского API, я назвал его «UpperNameApi.php»:
<?php
class UpperNameApi extends SugarApi
{
public function registerApiRest()
{
return array(
'UpperNameRequest' => array(
//request type
'reqType' => 'POST',
//endpoint path
'path' => array('Leads', 'UpperName'),
//endpoint variables
'pathVars' => array('module',''),
//method to call
'method' => 'UpperNameMethod',
//short help string to be displayed in the help documentation
'shortHelp' => 'Example endpoint',
//long help to be displayed in the help documentation
'longHelp' => 'custom/clients/base/api/help/MyEndPoint_MyGetEndPoint_help.html',
),
);
}
public function UpperNameMethod($api, $args)
{
if (isset($args['record']) && !empty($args['record'])) {
$bean = BeanFactory::getBean('Leads', $args['record']);
if (!empty($bean->id)) {
$first = $bean->first_name;
$first = ucwords($first);
$bean->first_name = $first;
$last = $bean->last_name;
$last = ucwords($last);
$bean->last_name = $last;
$bean->save();
}
return 'success';
}
return 'failed';
}
}
Пожалуйста, помогите гениальному программисту.