Copied to clipboard

Flag this post as spam?

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


  • Marshall Penn 78 posts 258 karma points
    Mar 01, 2018 @ 17:51
    Marshall Penn
    0

    Update page property programmatically

    I imported 700+ news articles from the previous CMS, which i did programmatically without issue using "contentService.CreateContent(..." and "contentService.SaveAndPublishWithStatus(data);" I added a prefix so that there would not be any name clashes - however now I want to remove that prefix (e.g. "20171205-") on a "menuTitle" field that I use as the article title.

    But there is a save problem after I have updated the value:

    I have tried

    "var c = Services.ContentService.GetById(x.Id);" (x is the IPublishedContent of the page)

    along with "var saveAttempt = Services.ContentService.SaveAndPublishWithStatus(c);"

    or even "Services.ContentService.Save(c);"

    but i just get this error

    "Cannot insert the value NULL into column 'id', table 'UMBCinvenLocal.dbo.cmsContentVersion'; column does not allow nulls. INSERT fails. The statement has been terminated."

    Does anyone know whatI am doing wrong here?

    Thanks, Marshall

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Mar 02, 2018 @ 11:47
    Steve Morgan
    1

    Are you sure that the x.Id is an actual content node ID?

    Can you check for a null on c - are you debugging? Stick a breakpoint after you GetById and see if you are actually getting a content object back.

  • Marshall Penn 78 posts 258 karma points
    Mar 02, 2018 @ 14:14
    Marshall Penn
    0

    Hi Steve,

    Yes i am sure that x.Id is the content node:

    IEnumerable<IPublishedContent> list = parentpage.Children.Where(t => t.DocumentTypeAlias == "newsPage");
    string menutitle = "";
    NewsPage np = null;
    foreach (var x in list) {
        np = (NewsPage)x;
        menutitle = np.MenuTitle;
        if (menutitle.Length > 8) {
            if (menutitle.Substring(6, 1) == "-") {
                sb.AppendLine("Success! ID: " + x.Id + " menuTitle: " + menutitle);
    

    this is giving this output into the StringBuilder:

    Success! ID: 1476 menuTitle: 170731-XXXXX completes Private Placement of XXXXX Success! ID: 1478 menuTitle: 170710-XXXXX invests in XXXXX, the leading XXXXX services provider Success! ID: 1479 menuTitle: 170629-XXXXX generates successful partial realisation of XXXXX Success! ID: 1480 menuTitle: 170628-XXXXX completes acquisition of XXXXX Success! ID: 1481 menuTitle: 170619-XXXXX extends relationship with XXXXX until 2021 Success! ID: 1483 menuTitle: 170523-XXXXX continues expansion in Europe with the acquisition of XXXXX

    Do you think is might have something to do with the transition to the id that has the int plus the guid format?

    Marshall

  • Marshall Penn 78 posts 258 karma points
    Mar 02, 2018 @ 15:24
    Marshall Penn
    0
     foreach (var x in list) {
                    np = (NewsPage)x;
                    menutitle = np.MenuTitle;
                    if (menutitle.Length > 8) {
                        if (menutitle.Substring(6, 1) == "-") {
    
                            var c = Services.ContentService.GetById(x.Id);
                            sb.AppendLine("Success! ID: " + c.Id + " c.Name: " + c.Name);
    
                            c.SetValue("menuTitle", menutitle.Substring(7));
                            Services.ContentService.Save(c);
    

    The stringbuilder still gives output - but the error is still there on the save:

    Cannot insert the value NULL into column 'id', table 'UMBCinvenLocal.dbo.cmsContentVersion'; column does not allow nulls. INSERT fails. The statement has been terminated.

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Mar 02, 2018 @ 16:38
    Steve Morgan
    0

    Googling that error seems to suggest others have seen this error when they've either scripted and recreated the DB on a server (and missed the unique identifer auto increment property off that table) or manually inserted data straight into the db and botched it.

    I take it neither of those apply?

    Are you running on SQL Express / SQL Server?

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Mar 02, 2018 @ 16:41
    Steve Morgan
    100

    Check that table has the Identity Specification

    enter image description here

  • Marshall Penn 78 posts 258 karma points
    Mar 02, 2018 @ 16:47
    Marshall Penn
    0

    Hi Steve,

    I did indeed recreate the database from azure down locally via a .bacpac file - and that is indeed the problem.

    What was wrong with the old Sql Server .bak file format? Force-restore and off you go!

    So i can assume that all the tables need identity switched on then?

    Marshall

  • Marshall Penn 78 posts 258 karma points
    Mar 02, 2018 @ 16:51
    Marshall Penn
    0

    I will re-download load it using Create Scripts and set it to Schema and Data

    Thanks very much

    Marshall

Please Sign in or register to post replies

Write your reply to:

Draft