SAP Knowledge Base Article - Public

2856818 - UPSERT for dynamic group fails. Error: The group name is duplicate. for Key -1 with the index 0

Symptom

Image/data in this KBA is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental.

You are trying to add a new user to an existing dynamic group via an API UPSERT but the upsert fails.
Sample error: The group name is duplicate. for Key -1 with the index 0

Environment

  • BizX
  • SuccessFactors (SF)

Reproducing the Issue

  1. Perform API query, e.g. sample upsert call below:

    {
        "__metadata": {
            "uri": "DynamicGroup"
        },
        "groupName": "DynamicGroup_Testing",
        "groupType": "permission",
        "dgIncludePools": {
            "__metadata": {
                "uri": "DGPeoplePool"
            },
            "filters": [
                {
                    "__metadata": {
                        "uri": "DGFilter"
                    },
                    "field": {
                        "__metadata": {
                            "uri": "DGField"
                        },
                        "name": "user",
                        "allowedOperators": {
                            "__metadata": {
                                "uri": "DGFieldOperator"
                            },
                            "token": "aa"
                        }
                    },
                    "expressions": {
                        "__metadata": {
                            "uri": "DGExpression"
                        },
                        "operator": {
                            "__metadata": {
                                "uri": "DGFieldOperator"
                            },
                            "token": "eq"
                        },
                        "values": {
                            "__metadata": {
                                "uri": "DGFieldValue"
                            },
                            "fieldValue": "testUser100"
                        }
                    }
                }
            ]
        }
    }



  2.  Call fails and an error similar to the following is displayed: The group name is duplicate. for Key -1 with the index 0

Cause

1. Upsert call needs to be modified

2. Limitation of OData API (see below)

Resolution

The requirement of adding a new user to an existing dynamic group can be achieved via API with a request body similar to the one below, but please note the following:

  1. You must specify the groupID in the request (e.g. value  "groupID": "5956" in the sample request below)
  2. You must list all the users that already are in the specific group and also the new users to be added into the group. The reason for this is that, effectively, this is an override operation, thus all the original values will be overwritten and a new definition for the group will be generated
  3. You must make sure all the usernames are correct, and that the users actually exist in the system; this is a limitation of the OData API as the values are not verified (in other words: if you add invalid users, these will actually added to the group)


Sample upsert call:

{
    "__metadata": {
        "uri": "DynamicGroup"
    },
    "groupName": "APITest",
    "groupType": "permission",
    "groupID": "5956",
    "dgIncludePools": 
    	{
        "__metadata": {
            "uri": "DGPeoplePool"
        },
        "filters": [
            {
                "__metadata": {
                    "uri": "DGFilter"
                },
                "field": {
                    "__metadata": {
                        "uri": "DGField"
                    },
                    "name": "user",
                    "allowedOperators": {
                        "__metadata": {
                            "uri": "DGFieldOperator"
                        },
                        "token": "aa"
                    }
                },
                "expressions": [{
                    "__metadata": {
                        "uri": "DGExpression"
                    },
                    "operator": {
                        "__metadata": {
                            "uri": "DGFieldOperator"
                        },
                        "token": "eq"
                    },
                    "values": {
                        "__metadata": {
                            "uri": "DGFieldValue"
                        },
                        "fieldValue": "username1"
                    }
                },
                {
                    "__metadata": {
                        "uri": "DGExpression"
                    },
                    "operator": {
                        "__metadata": {
                            "uri": "DGFieldOperator"
                        },
                        "token": "eq"
                    },
                    "values": {
                        "__metadata": {
                            "uri": "DGFieldValue"
                        },
                        "fieldValue": "username2"
                    }
                },
                {
                    "__metadata": {
                        "uri": "DGExpression"
                    },
                    "operator": {
                        "__metadata": {
                            "uri": "DGFieldOperator"
                        },
                        "token": "eq"
                    },
                    "values": {
                        "__metadata": {
                            "uri": "DGFieldValue"
                        },
                        "fieldValue": "username3"
                    }
                }
                ]
            }
        ]
    }
}

See Also

https://help.sap.com/viewer/28bc3c8e3f214ab487ec51b1b8709adc/latest/en-US/c39ab58243154979bf060c0e5eac7cfa.html

Keywords

  •  The group name is duplicate. for Key -1 with the index 0
  •  OData
  •  Dynamic group
, KBA , LOD-SF-INT-ODATA , OData API Framework , How To

Product

SAP SuccessFactors HCM Core 1908