为什么我在执行更新请求后总是收到 "Duplicate Alert" 错误?
Why I'am always getting "Duplicate Alert" error after doing update request?
我正在写 Chrome Vtiger CRM 的扩展。
我需要创建为项目页面上 CRM 中的 "Proposal text" 字段增加价值的能力。
这是文档:https://www.vtiger.com/docs/rest-api-for-vtiger#/Update
我是怎么做到的:
- 从 Vtiger 获取项目 API。
- 更改项目对象中的值 "cf_potentials_proposaltext"。
- 制作POST(根据文档要求)请求更新 Vtiger API 端点,发送更新的项目对象
- 获得 "duplicate alert" 响应..
我绝对确定,因为我检查过我正在发送修改后的项目对象 - 使用 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);
}
});
}
提前致谢。
问题通过使用修改 https://www.vtiger.com/docs/rest-api-for-vtiger#/Revise 一次而不是更新来解决。感谢@pinaki
我正在写 Chrome Vtiger CRM 的扩展。 我需要创建为项目页面上 CRM 中的 "Proposal text" 字段增加价值的能力。
这是文档:https://www.vtiger.com/docs/rest-api-for-vtiger#/Update
我是怎么做到的:
- 从 Vtiger 获取项目 API。
- 更改项目对象中的值 "cf_potentials_proposaltext"。
- 制作POST(根据文档要求)请求更新 Vtiger API 端点,发送更新的项目对象
- 获得 "duplicate alert" 响应..
我绝对确定,因为我检查过我正在发送修改后的项目对象 - 使用 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);
}
});
}
提前致谢。
问题通过使用修改 https://www.vtiger.com/docs/rest-api-for-vtiger#/Revise 一次而不是更新来解决。感谢@pinaki