首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SugarCRM Rest联系人和文档之间的set_relationship

SugarCRM Rest联系人和文档之间的set_relationship
EN

Stack Overflow用户
提问于 2019-08-17 00:59:05
回答 1查看 540关注 0票数 1

我试图在文档和SugarCRM上的联系人之间建立(链接/设置关系)。我不知道如何具体地构造"name_value_list“。至少我认为这是错误的。

我尝试了以下几点:

1.

'name_value_list': []

2.

代码语言:javascript
复制
'name_value_list' : [{
            'name': "documents_contacts",
            'value': 'Other',
                    }],

3.

代码语言:javascript
复制
'name_value_list': [{'table': "%s_%s" % (ModuleName, LinkedModuleName)},
                                {'fields': [
                                        {"id": str(uuid.uuid1())},
                                        {"date_modified": str(datetime.datetime.now())},
                                        {"deleted":  '0'},
                                        {"document_id": RecordID},
                                        {"contact_id": LinkedRecordID},
                                            ]

4.

代码语言:javascript
复制
'name_value_list':[{"%s_%s" % (ModuleName, LinkedModuleName): 'Other',
                                "id": str(uuid.uuid1()),
                                "date_modified": str(datetime.datetime.now()),
                                "deleted":  '0',
                                "document_id": RecordID,
                                "contact_id": LinkedRecordID
                                }]

SugarCRM CE版本6.5.20 (Build1001)

SugarCRM v4_1 Rest文档:

代码语言:javascript
复制
* Set a single relationship between two beans.  The items are related by module name and id.
 *
 * @param String $session -- Session ID returned by a previous call to login.
 * @param String $module_name -- name of the module that the primary record is from.  This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
 * @param String $module_id - The ID of the bean in the specified module_name
 * @param String link_field_name -- name of the link field which relates to the other module for which the relationship needs to be generated.
 * @param array related_ids -- array of related record ids for which relationships needs to be generated
 * @param array $name_value_list -- The keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
 * @param integer $delete -- Optional, if the value 0 or nothing is passed then it will add the relationship for related_ids and if 1 is passed, it will delete this relationship for related_ids
 * @return Array - created - integer - How many relationships has been created
 *               - failed - integer - How many relationsip creation failed
 *               - deleted - integer - How many relationships were deleted
 * @exception 'SoapFault' -- The SOAP error, if any
 */
    Method [  public method set_relationship ] {
      - Parameters [7] {
        Parameter #0 [  $session ]
        Parameter #1 [  $module_name ]
        Parameter #2 [  $module_id ]
        Parameter #3 [  $link_field_name ]
        Parameter #4 [  $related_ids ]
        Parameter #5 [  $name_value_list ]
        Parameter #6 [  $delete ]
      }
    }

Python 3.7

代码语言:javascript
复制
def SetRelationship(self, ModuleName, ModuleID, LinkFieldName, RelatedID):
    method = 'set_relationship'
    data = {
        'session':self.SessionID,
        'module_name':ModuleName,
        'module_id':ModuleID,
        'link_field_name':LinkFieldName,
        'related_ids':[RelatedID, ]
            }
    response = json.loads(self.request(method, data))

SetRelationship('Documents', 'e9d22076-02fe-d95d-1abb-5d572e65dd46', 'Contacts', '2cdc28d8-763e-6232-2788-57f4e19a9ea0')

结果:{“创建”:0,“失败”:1,“删除”:0}

预期结果:{“创建”:1、“失败”:0、“删除”:0}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-18 16:03:02

你可能是想打电话给

代码语言:javascript
复制
SetRelationship('Documents', 'e9d22076-02fe-d95d-1abb-5d572e65dd46', 'contacts', '2cdc28d8-763e-6232-2788-57f4e19a9ea0')

请注意这里的小写contacts,因为API需要文档中链接字段的名称,而不是模块的名称。

如果仍然没有解决问题,请检查sugarcrm.log和php日志中是否有错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57532544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档