深度插入导航属性动态WebAPI

时间:2017-06-28 13:59:35

标签: json dynamics-crm microsoft-dynamics dynamics-crm-webapi microsoft-dynamics-webapi

我使用Microsoft Dynamics Web API将数据写入Microsoft Dynamics 365中的实体。当我尝试执行deep insert时,我收到错误

  

未申报的财产' ccseq_employeeid'它只在有效负载中有属性注释,但在有效负载中没有找到属性值。在OData中,只有声明的导航属性和声明的命名流可以表示为没有值的属性。

为什么我收到此错误,如何解决错误?

JSON

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000", "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        { 
          "ccseq_employeeid@odata.bind": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ccseq_clientid@odata.bind": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}

ExpenseTransactionSetExpenseTransaction的父级,这意味着ExpenseTransaction查找ExpenseTransactionSetccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID是一对多关系。 systemuserccseq_clientsExpenseTransaction中查找的单独实体。

我还在"ccseq_employeeid@odata.bind"

上尝试了以下变体
  • objectid_systemuser@odata.bind
  • objectid_ccseq_employeeid@odata.bind
  • ccseq_employeeid@data.bind
  • ccseq_employeeid@odata.bind : systemusers()
  • ccseq_employeeid_systemusers@odata.bind
  • systemuserid_systemusers@odata.bind

我看到this问题和this问题并尝试了建议的解决方案但没有成功。

2 个答案:

答案 0 :(得分:3)

我发现了解读this线程的答案。深插入中导航属性的正确语法是使用子实体名称,后跟括号和字段名称。需要将json更改为以下

{
    "ccseq_importdate" : "2017-05-28T04:00:00Z", 
    "ccseq_month" : "1", 
    "ccseq_year" : "2017", 
    "ccseq_name" : "Test", 
    "ccseq_status" : "100000000",
    "ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID" : 
    [ 
        {
          // Next two lines are changed 
          "ExpenseTransaction[ccseq_employeeid@odata.bind]": "/systemusers(6d2fd71b-32d1-dd11-a4f5-001a6449bbe7)", 
          "ExpenseTransaction[ccseq_clientid@odata.bind]": "/ccseq_clients(663ebd00-73b9-4faf-90ed-f56bb9c2dc9b)", 
          "ccseq_navemployeeid" : "11111", 
          "ccseq_employeefirstname" : "John"
        }
    ]
}

答案 1 :(得分:0)

在元数据文档from matplotlib import pyplot from matplotlib.widgets import Slider import matplotlib.pyplot as plt import numpy as np a, b, c, d = [np.random.randint(10, size = 4) for _ in range(4)] grid = ((a,b),(c,d)) grid = np.array(grid) fig = plt.figure(figsize=(7,5)) ax = fig.add_subplot(111) plt.subplots_adjust(left=0.15, bottom=0.25) words = ['Sample1', 'Sample2'] data_start = 0.5 dataSlider_ax = fig.add_axes([0.15, 0.1, 0.7, 0.05]) dataSlider = Slider(dataSlider_ax, 'value', 0, 1, valinit=data_start) image = ax.imshow(grid[0], interpolation='none', aspect='auto') texts = [[ax.text(i,j,words[0]) for i in range(grid.shape[2])] for j in range(grid.shape[1])] def update(val): global image, texts ref = int(dataSlider.val * 2) print (ref) image.set_data(grid[ref]) for (j,i),label in np.ndenumerate(grid[ref]): texts[j][i].set_text(words[ref]) print(ax.get_children()) # if this list keeps getting longer, you are leaking objects dataSlider.on_changed(update) pyplot.show() 中,您可以检查集合值导航属性{org-url}/api/data/v8.0/$metadata的元素类型吗?

它是否具有ccseq_ccseq_expensetransactionset_ccseq_expensetransaction_ExpenseTransactionSetID作为其导航属性的相同类型?如果没有,并且属性ccseq_employeeid属于派生类型,则可能需要注释导航属性对象,如下所示:

ccseq_employeeid