Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pjz 9 posts 102 karma points
    Oct 30, 2018 @ 22:26
    pjz
    0

    Unable to update form record - UpdateRecord(formRecord, form)

    I have API method to update or insert the form record based on whether the UniqueId is provided or not. But I got the error when try to update the existing form record. Why does the Umbraco.Forms.Data.Storag.RecordStorage.UpdateRecord() perform the Insert? Any help will be greatly appreciated!

    PJ

    Error: {"The INSERT statement conflicted with the FOREIGN KEY constraint \"FKUFRecordFieldsUFRecords_Id\". The conflict occurred in database \"myUmbracoDB\", table \"dbo.UFRecords\", column 'Id'.\r\nThe statement has been terminated."}

    Sample Code:

    Guid recordId;
    bool isValidId = Guid.TryParse(rec.RecordId, out recordId);                 
    var formRecord = new Record()
    {
        UniqueId = isValidId ? recordId : Guid.NewGuid(),
        UmbracoPageId = docuemnt.Id,
        Created = DateTime.Now,
        Form = form.Id,
        State = FormState.Opened,
        RecordFields = fieldDictionary                        
    };
    
    formRecord.RecordData = formRecord.GenerateRecordDataAsJson();
    
    using (var storage = new RecordStorage())
    {      
        var record = isValidId ? storage.UpdateRecord(formRecord, form) : storage.InsertRecord(formRecord, form);                        
    }
    
  • pjz 9 posts 102 karma points
    Jan 17, 2019 @ 08:27
    pjz
    0

    The reason is the table UFRecordFields has been altered and the Record became the foreign key of UFRecords.Id. Looks like the UpdateRecord() function insert the records into UFRecordFields.

Please Sign in or register to post replies

Write your reply to:

Draft