0

我有以下代码:

$.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);
    }
});

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

4

2 回答 2

0

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

像这样的东西:

// 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);
    }
});
于 2012-08-10T06:03:40.867 回答
0

这应该工作...

$.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);
}

});

于 2012-08-09T12:48:11.863 回答