我正在为Vtiger CRM开发Chrome扩展程序。 我需要在项目页面上的CRM中创建为“投标文本”字段添加值的功能。
以下是文档:https://www.vtiger.com/docs/rest-api-for-vtiger#/Update
我该怎么做:
我绝对可以确定,因为我检查了是否正在发送修改后的项目对象-使用console.log'Temprorary_1'(位于vtigerAddProposal中)和'Temprorary_2'(位于vtigerUpdatePotential中),还检查了Chrome开发者控制台中的更改值网络标签。
这是我的代码:
function vtigerAddProposal() {
var temprorary_potential;
var dialog = $('#dialog');
chrome.storage.sync.get(['proposal'], function(result) {
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/retrieve',
type: 'GET',
data: {
'id': localStorage.getItem('vtiger_last_opportunity_id')
},
success: function( response ) {
temprorary_potential = response['result'];
console.log("Temprorary_1: " + JSON.stringify(temprorary_potential, null, 2));
temprorary_potential['cf_potentials_proposaltext'] = result.proposal;
vtigerUpdatePotential(temprorary_potential);
},
error: function (response) {
console.log("Failed to get opportunity from Vtiger.");
$('#dialog-inner-text').text("Vtiger: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
});
}
function vtigerUpdatePotential(data) {
var dialog = $('#dialog');
console.log("Temprorary_2: " + JSON.stringify(data, null, 2));
// Second Part
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/update',
type: 'POST',
data: {
element: JSON.stringify(data)
},
success: function( response ) {
console.log("Successfully updated Vtiger potential.")
console.log(response);
localStorage.removeItem('vtiger_last_opportunity_id'); // в случае успеха удаляем oppId
},
error: function (response) {
console.log("Failed to update potential in Vtiger.")
$('#dialog-inner-text').text("Vtiger potential wasn't update: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
}
谢谢。
答案 0 :(得分:1)
使用修订https://www.vtiger.com/docs/rest-api-for-vtiger#/Revise一次而不是更新来解决问题。感谢@pinaki