Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 403 posts 1520 karma points
    Jun 14, 2021 @ 12:38
    Paul de Quant
    0

    Missing Key attribute in Nested Content when upgrading from v7 to v8

    Hello,

    We're in the process of upgrading a CMS from V7 to V8. We use the nested content type a lot and what we've noticed is that a Key attribute has been added in the new version. However we have also experienced an issue where by the frontend view won't load because this key is not present.enter image description here

    We have hundreds of instances of this data type in our content. Does anyone have a way of fixing this that doesn't involve redoing the content? We know that by publishing the page, the key attribute is added but all instances are set to 00000-00000-00000-00000.

    Any thoughts?

    Thanks

  • shekhar sharma 22 posts 110 karma points
    Jun 14, 2021 @ 12:57
    shekhar sharma
    0

    Hello Paul ,

    Can you try with Below Steps.

    Take backup 1ST of your project.

    1. Delete all the Model Classes in Website/ App_Data/Models/ Delete all the classes excepts ( Default Classes Like File.Generate.cs)
    2. Login into the CMS and generate model again.
    3. If you are using PURELive Model Builder than rebuild the solution or if you are using AppData than include all the ModelBuilder Classes in your application and rebuild the application.

    Thanks,

    Shekhar

  • Paul de Quant 403 posts 1520 karma points
    Jun 14, 2021 @ 13:15
    Paul de Quant
    0

    Hi Shekhar,

    That didn't do anything I'm afraid. Same result.

    Thanks

  • Paul de Quant 403 posts 1520 karma points
    Jun 22, 2021 @ 07:31
    Paul de Quant
    100

    Managed to solve it with this bit of SQL I wrote. Only works on SSMS 2019+

    DECLARE @MyCursor CURSOR; DECLARE @ItemID int; DECLARE @ItemTextValue nvarchar(max); DECLARE @ItemValid int;

    BEGIN SET @MyCursor = CURSOR FOR SELECT pd.id, textValue FROM umbracoPropertyData pd INNER JOIN cmsPropertyType pt ON pt.id = pd.propertytypeid INNER JOIN [umbracoContentVersion] cv on cv.id = pd.versionId WHERE ISNULL(CAST(pd.textValue as nvarchar(max)), '') != '' AND dataTypeId in (SELECT [nodeId] FROM [dbo].[umbracoDataType] WHERE [propertyEditorAlias] = 'Umbraco.NestedContent') AND ISJSON(CAST(textValue as nvarchar(max))) = 1

    OPEN @MyCursor
    FETCH NEXT FROM @MyCursor
    INTO @ItemID, @ItemTextValue
    
    WHILE @@FETCH_STATUS = 0
        BEGIN
    
            DECLARE @outerJson NVARCHAR(MAX);
            DECLARE @innerJson NVARCHAR(MAX);
    
            SET @outerJson = @ItemTextValue
    
            DECLARE @Outer_Counter int
            DECLARE @Outer_Count int
    
            DECLARE @Inner_Counter int
            DECLARE @Inner_Count int
    
            SET @Outer_Counter = 0;
            SET @Outer_Count = (SELECT COUNT(*) FROM OPENJSON(@outerJson))
    
            WHILE @Outer_Counter < @Outer_Count
                BEGIN
    
                    SET @outerJson = JSON_MODIFY(@outerJson,'$[' + cast(@Outer_Counter as nvarchar(10)) + '].key', '' + cast(newid() as nvarchar(60)) + '')
    
                    SET @Inner_Counter = 0;
                    SET @Inner_Count = (SELECT COUNT(*) FROM OPENJSON(@outerJson,'$[' + cast(@Outer_Counter as nvarchar(10)) + '].items'))
    
                    PRINT 'Item Id:' + CAST(@ItemID as nvarchar(10)) + ' Item Count: ' + CAST(@Inner_Count as nvarchar(10))
    
                    WHILE @Inner_Counter < @Inner_Count
                        BEGIN
                            IF (@Inner_Counter > 0)
                                BEGIN
                                    SET @outerJson = @innerJson
                                END
    
                            SET @innerJson = JSON_MODIFY(@outerJson,'$[' + cast(@Outer_Counter as nvarchar(10)) + '].items[' + cast(@Inner_Counter as nvarchar(10)) + '].key', '' + cast(newid() as nvarchar(60)) + '')         
    
                            PRINT 'Items: ' + CAST(@innerJson as nvarchar(max))
    
                            SET @Inner_Counter = @Inner_Counter + 1; 
                        END
    
                        SET @Outer_Counter = @Outer_Counter + 1;
    
                END;
    
            IF (@innerJson IS NULL OR LEN(RTRIM(LTRIM(@innerJson))) = 0)
                BEGIN TRY
                    UPDATE umbracoPropertyData SET textValue = @outerJson WHERE id = @ItemID
                END TRY
                BEGIN CATCH
                    PRINT 'Outer Error: ' +  CAST(@ItemID as nvarchar(max)) + char(13) + char(10)
                END CATCH
            ELSE
                BEGIN TRY
                    UPDATE umbracoPropertyData SET textValue = @innerJson WHERE id = @ItemID
                END TRY
                BEGIN CATCH
                    PRINT 'Inner Error: ' + CAST(@ItemID as nvarchar(max))
                END CATCH
    
                SET @innerJson = ''
    
    FETCH NEXT FROM @MyCursor
    INTO @ItemID, @ItemTextValue
    

    END

    CLOSE @MyCursor; DEALLOCATE @MyCursor;

    END;

Please Sign in or register to post replies

Write your reply to:

Draft