如何基于共享公用密钥的主列表更新辅助列表中的多个记录 [英] How Can I Update Multiple Records in a Secondary List based on a Primary List that Shares a Common Key

查看:68
本文介绍了如何基于共享公用密钥的主列表更新辅助列表中的多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表(主要和次要"),它们共享一个公共键值(CommonKey).主列表具有一个状态字段(状态).什么时候 主服务器上的状态已更改我需要使用主服务器上的状态更新辅助文件中的所有记录.注意-列表共享一对多的关系,并且主键在主列表中是唯一的.

I have two lists (Primary and Secondary) they share a common key value (CommonKey). The Primary list has a status field (Status). When the status is changed on the Primary I need to update all of the records in the secondary file with the status form the primary file. Notes - the lists share a one to many relationship and the common key is unique in the primary list. 

推荐答案

能够:

  • 使用REST调用基于CommonKey识别相关记录
  • 计数结果
  • 遍历结果并更新状态

请参阅此线程

Refer to this thread Identify Duplicates with REST which will take you through the first two steps in detail. All we have left is loop and update.

以下是我们示例的一些测试数据:

Here is some test data for our example:

我们需要基于主要列表创建一个列表工作流,该工作流会在列表更改时触发.

We need to create a list workflow based on the Primary list that triggers when the list is changed.

这是工作流程:

第一阶段与我们计算项目的上一个线程几乎完全相同:

The first stage is almost exactly the same as in the previous thread where we counted the items:

但是,我们添加了一个额外的阶段来循环浏览并更新辅助文件中的状态:

However, we have added an additional stage to loop through and update the status in the secondary file:

这是工作流程日志:

这是工作流在第一个主记录上运行时在我们列表中的结果:

And this is the result in our lists when the workflow runs on the first primary record:

由于我们覆盖了上一个线程中循环的所有内容,因此我认为我唯一需要添加的就是获取"消息的详细信息.和更新.要了解我们正在获得"什么?这是返回字典的字符串 变量WFResponse:

Since we cover everything up to the loop in the previous thread, I think the only thing I have to add is the details of the "Get" and the update. To understand what we are "getting" this is the string that was returned to the dictionary variable WFResponse:

{"d":{"results" ;:[{"__ metadata":{"id":"Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(1)","uri":"; http:\/\/SITE.DOMAIN.com \/ExpenseReports \/_ api \/Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(1)," etag"; ::"\""18"",类型":"SP.Data.SecondaryListItem"},"Id":1,"CommonKey":"A123",状态" :"Entered","ID":1},{"__ metadata":{"id":"Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items( 2),"uri":"http:\/\/SITE.DOMAIN.com \/ExpenseReports \/_ api \/Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\ /Items(2)"、etag":\"、7"、type":SP.Data.SecondaryListItem"}、Id":2、CommonKe" y":"A123",状态":输入","ID":2},{"__ metadata":{"id":"Web/Lists(guid'912b08b8-18ad -4fce-9593-2ba37e2c5a0b')\/Items(3)'',``uri'':``http:\/\//SITE.DOMAIN.com \/ExpenseReports \/_ api \/Web \/Lists(guid' 912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(3)","etag":"\""7","type":"SP.Data.SecondaryListItem" },"Id":3,"CommonKey":"A123","Status":"Entered","ID":3},{"__ metadata":{"id":" ; Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(10)," uri:""http:\//\/SITE.DOMAIN.com \/ExpenseReports \ /_api \/Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(10)","etag":"\""7",类型":"SP.Data.SecondaryListItem"},"Id":10,"CommonKey":"A123","Status":"Ent ered","ID":10}]}}

哪个有点难读.但是,如果将字符串粘贴到在线JSON解析器之一中,它将变得更加清晰,如下所示:

Which is a bit difficult to read. However, if you paste the string into one of the online JSON parsers it becomes a bit clearer and looks like this:

{

  • " d " : {
    • "结果" : [
    • "d":{
      • "results":[
      1. {
        • " __元数据" : {
          • " id " :"Web \/列表(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items( 1)"
          • " uri ":" http:\/\/SITE.DOMAIN .com \/ExpenseReports \/_ api \/Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(1)"
          • " etag " :"\""18 \""
          • " type ":" SP.Data.SecondaryListItem"
      1. {
        • "__metadata":{
          • "id":"Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(1)",
          • "uri":"http:\/\/SITE.DOMAIN.com\/ExpenseReports\/_api\/Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(1)",
          • "etag":"\"18\"",
          • "type":"SP.Data.SecondaryListItem"
      • " __元数据" : {
        • " id " :"Web \/列表(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items 2)"
        • " uri ":" http:\/\/SITE.DOMAIN .com \/ExpenseReports \/_ api \/Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(2)"
        • " etag " :"\""7 \""
        • " type ":" SP.Data.SecondaryListItem"
        • "__metadata":{
          • "id":"Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(2)",
          • "uri":"http:\/\/SITE.DOMAIN.com\/ExpenseReports\/_api\/Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(2)",
          • "etag":"\"7\"",
          • "type":"SP.Data.SecondaryListItem"
          • " __元数据" : {
            • " id " :"Web \/列表(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items( 3)"
            • " uri ":" http:\/\/SITE.DOMAIN .com \/ExpenseReports \/_ api \/Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(3)"
            • " etag " :"\""7 \""
            • " type ":" SP.Data.SecondaryListItem"
            • "__metadata":{
              • "id":"Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(3)",
              • "uri":"http:\/\/SITE.DOMAIN.com\/ExpenseReports\/_api\/Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(3)",
              • "etag":"\"7\"",
              • "type":"SP.Data.SecondaryListItem"
              • " __元数据" : {
                • " id " :"Web \/列表(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items( 10)"
                • "" uri " :"http:\/\/SITE.DOMAIN .com \/ExpenseReports \/_ api \/Web \/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(10)"
                • " etag " :"\""7 \""
                • " 类型":"SP.Data.SecondaryListItem"
                • "__metadata":{
                  • "id":"Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(10)",
                  • "uri":"http:\/\/SITE.DOMAIN.com\/ExpenseReports\/_api\/Web\/Lists(guid'912b08b8-18ad-4fce-9593-2ba37e2c5a0b')\/Items(10)",
                  • "etag":"\"7\"",
                  • "type":"SP.Data.SecondaryListItem"

                  ]

                • 当我们将Get操作的索引从0更改为3时,可以看到ID返回的值分别为1,2,3,10.

                  You can see where the values returned for ID are 1,2,3,10 as we vary the index on the Get action from 0 to 3. Zero is always the first item.

                  对于共享公用密钥的每个ID,更新操作只是将辅助文件中的状态字段更新为主文件中的状态.

                  The update action just updates the status field in the secondary file to the status from the primary file for each of the IDs that share the common key.


                  这篇关于如何基于共享公用密钥的主列表更新辅助列表中的多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆