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

标签 javascript jquery google-chrome-extension vtiger vtigercrm

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

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

我是如何做到的:

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

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

提前谢谢您。

最佳答案

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

关于javascript - 为什么我在执行更新请求后总是收到 "Duplicate Alert"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57509628/

相关文章:

jQuery.css() - marginLeft 与 margin-left?

javascript - 检查文件是否存在,根据消息显示,jQuery

javascript - 如何将上下文菜单限制为仅针对 Chrome 扩展程序中的某些选定文本显示?

javascript - 如何在显示之前的 Jquery keyup 事件期间从输入中删除空格

javascript - 具有多个元素的 CSS 图像不透明度淡入淡出过渡(类)

javascript - 使用 html 5 async 属性异步加载脚本

javascript - onclick 或内联脚本在扩展中不起作用

javascript - 我可以使用内容脚本 js 文件以编程方式注入(inject) CSS 文件吗?

javascript - 无法使用 Sinon 在类中 stub 箭头函数

javascript - 如何在 <canvas> 中绘制一条在 Safari/Chrome/Firefox 中看起来相同的对 Angular 线?