为什么我在执行更新请求后总是收到"Duplicate Alert"错误?



我正在为Vtiger CRM编写Chrome扩展程序。 我需要创建在项目页面上的CRM中为"提案文本"字段添加值的功能。

以下是文档: https://www.vtiger.com/docs/rest-api-for-vtiger#/Update

我怎么做:

  1. 从Vtiger API获取项目。
  2. 更改项目对象中的值"cf_potentials_proposaltext"。
  3. 发出POST(根据文档要求(请求更新Vtiger API端点,发送更新的项目对象
  4. 获取"重复警报"响应。

我绝对确定,因为我检查了我是否正在发送修改后的项目对象 - 使用控制台.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);
}
});
}

提前谢谢你。

通过使用修订 https://www.vtiger.com/docs/rest-api-for-vtiger#/Revise 一次而不是更新解决了问题。感谢@pinaki

相关内容

最新更新