Skip to main content

Notifications

Microsoft Dynamics CRM forum
Unanswered

Error while creating Knowledge Article record programmatically

Posted on by 275

Hello,

I am trying to create Knowledge Article record and getting below error:

{"error":{"code":"0x80040237","message":"A record with matching key values already exists.",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionSourceKey":
"Plugin/Microsoft.Crm.Service.ObjectModel.KnowledgeArticleService",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiStepKey":"2c33e9b7-ac2e-4dcc-8e73-a8cbc0eab812",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiDepthKey":"1",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiActivityIdKey":"5405f633-dc70-4be4-b17e-722a0c777e66",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiPluginSolutionNameKey":"System",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiStepSolutionNameKey":"System",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionCategory":"ClientError",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionMessageName":"DuplicateRecord",
"@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionHttpStatusCode":"412",
"@Microsoft.PowerApps.CDS.ErrorDetails.SqlExceptionMessage":"Violation of UNIQUE KEY constraint 'ndx_KnowledgeArticleBase'.
Cannot insert duplicate key in object 'dbo.KnowledgeArticleBase'. The duplicate key value is <redacted>.",
"@Microsoft.PowerApps.CDS.HelpLink":"go.microsoft.com/.../
Microsoft.Crm.CrmException%3a80040237&client=platform",
"@Microsoft.PowerApps.CDS.InnerError.Message":"Cannot insert duplicate key."}}

Has anyone faced this before?

Thanks,

Mridula

  • Amit Katariya007 Profile Picture
    Amit Katariya007 5,816 Moderator on at
    RE: Error while creating Knowledge Article record programmatically

    Can you check the duplicate detection rules. Because when you create anything manually and if it is a duplicate then you can ignore the warning manually but when you try same thing with code/customization, then probablu system will not allow this creation.

  • Mridula Profile Picture
    Mridula 275 on at
    RE: Error while creating Knowledge Article record programmatically

    calling createKnowledgeArticles function with same title and content again and again.

    While doing so, its throwing error. But not sure which is the field considered as duplicate by KA.

    P.S. I have 50+ KA's with same title and content. So considering this, thinking title and content cannot be unique fields.

  • meelamri Profile Picture
    meelamri 13,198 User Group Leader on at
    RE: Error while creating Knowledge Article record programmatically

    Are you trying to create multiple KA's and running the code again to create same ones?

    --> No, How do you create multiple KA ?

  • Mridula Profile Picture
    Mridula 275 on at
    RE: Error while creating Knowledge Article record programmatically

    Hi Mehdi,

    I tried commenting st_products custom field. Still facing same issue.

    pastedimage1627291548263v1.png

  • Mridula Profile Picture
    Mridula 275 on at
    RE: Error while creating Knowledge Article record programmatically

    Hi Mehdi,

    Are you trying to create multiple KA's and running the code again to create same ones?

    Thanks,

    Mridula

  • meelamri Profile Picture
    meelamri 13,198 User Group Leader on at
    RE: Error while creating Knowledge Article record programmatically

    I can't reproduce this issue on my environment.  Could you test the same code without the "st_products" attribute ?

  • Mridula Profile Picture
    Mridula 275 on at
    RE: Error while creating Knowledge Article record programmatically

    No.

  • meelamri Profile Picture
    meelamri 13,198 User Group Leader on at
    RE: Error while creating Knowledge Article record programmatically

    Do you have any alternate keys for the entity Knowledge Article?

  • Mridula Profile Picture
    Mridula 275 on at
    RE: Error while creating Knowledge Article record programmatically

    hi Mehdi,

    var data =

       {

           "st_products": sessionStorage.getItem("ProductValue"),

           "title": sessionStorage.getItem("Title"),

           "content": content

       }

       // create account record

       Xrm.WebApi.createRecord("knowledgearticle", data).then(

           function success(result) {

           },

           function (error) {

           }

       );

    pastedimage1627288588428v1.png

    st_products is a custom multi select optionset value.

    The above error which I am getting is random, if I run the same set of records again and again, it creates KA's and sometimes(randomly) throw error.

    I have 50+ KA's with same title and content.

    Thanks,

    Mridula

  • meelamri Profile Picture
    meelamri 13,198 User Group Leader on at
    RE: Error while creating Knowledge Article record programmatically

    Hi,

    Please share your code ..

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans