sugarcrm REST 更新 关系 beteen 联系人和帐户 javascript

sugarcrm REST update Relationship beteen Contacts and Accounts javascript

本文关键字:javascript 联系人 beteen REST 更新 关系 sugarcrm      更新时间:2023-09-26

我有以下代码:

$.get(CurrentServerAddress + '/service/v2/rest.php', {
            method: "set_relationship",
            input_type: "JSON",
            response_type: "JSON",
            rest_data: '{"session":"' + SugarSessionId + '","module_name":"Contacts","module_id":"' + CurrentContactId + '","link_field_name":"accounts","related_ids":["'+ CurrentAccountId +'"]}'
        }, function(data) {
            if (data !== undefined) {
                var addAccountResult = jQuery.parseJSON(data);
    }
});

联系人和公司之间的关系运作良好。我现在想为联系人分配一家新公司。我不知道该怎么做。

由于联系人和客户之间的关系被定义为多对多,而不是一对多,如果您只希望一个联系人和客户之间有一个链接,您应该在第一步中删除当前关系,然后在添加新关系后

删除

像这样:

// Delete previous relation
$.get(CurrentServerAddress + '/service/v2/rest.php', {
    method: "set_relationship",
    input_type: "JSON",
    response_type: "JSON",
    rest_data: '{"session":"' + SugarSessionId + '","module_name":"Contacts","module_id":"' + CurrentContactId + '","link_field_name":"accounts","related_ids":["'+ OldAccountId +'"],"name_value_list":[],"deleted":"1"}'
    }, function(data) {
    if (data !== undefined) {
        var addAccountResult = jQuery.parseJSON(data);
    }
});
// Add previous relation
$.get(CurrentServerAddress + '/service/v2/rest.php', {
    method: "set_relationship",
    input_type: "JSON",
    response_type: "JSON",
    rest_data: '{"session":"' + SugarSessionId + '","module_name":"Contacts","module_id":"' + CurrentContactId + '","link_field_name":"accounts","related_ids":["'+ NeAccountId +'"],"name_value_list":[],"deleted":"1"}'
    }, function(data) {
    if (data !== undefined) {
        var addAccountResult = jQuery.parseJSON(data);
    }
});

这应该有效...

$.get(CurrentServerAddress + '/service/v2/rest.php', {
        method: "set_relationship",
        input_type: "JSON",
        response_type: "JSON",
        rest_data: '{"session":"' + SugarSessionId + '","module_name":"Accounts","module_id":"' + CurrentAccountId + '","link_field_name":"contacts","related_ids":["'+ CurrentContactId +'"]}'
    }, function(data) {
        if (data !== undefined) {
            var addAccountResult = jQuery.parseJSON(data);
}

});