I am trying to import csv file to content data via power shell script.am getting following error message

    New-UsingBlock : Item '/sitecore/content/Web3/Content Shared 
    Folder/Property Page' is not in editing mode. Item ID: {A6E40603-D2E7- 
   4527-94B9-8B8F646E4574}
        At line:26 char:2
       +     New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
       +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       + CategoryInfo          : OperationStopped: (:) [New-UsingBlock], 
         EditingNotAllowedException
         FullyQualifiedErrorId:Sitecore.Exceptions.EditingNotAllowedException,Cognifide.PowerShell.Commandlets.Data.NewUsingBlockCommand

Did anyone came across this problem before and solved it? please help me also let me know for more info

            #Upload the file on the Server in temporary folder
             #It will create the folder if it is not found
             $TargetLanguage = "fr-CA"
              $Language = "en"

             $dataFolder = [Sitecore.Configuration.Settings]::DataFolder
             $tempFolder = $dataFolder + "/temp/upload"
             $filePath = Receive-File -Path $tempFolder -overwrite
             $templatePath = "Chartwell/Project/Website/Page 
              Template/Property Page"   #Here
                  $contentPath = "master:/content/Web3/Content Shared 
                 Folder/Property Page" #Here

              if($filePath -eq "cancel"){
           exit
             }

                $resultSet =  Import-Csv $filePath

              $rowsCount = ( $resultSet | Measure-Object ).Count;

            if($rowsCount -le 0){
          Remove-Item $filePath
    exit
}

Write-Log "Bulk Update Started!";
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
    foreach ( $row in $resultSet ) {
    $ItemName = $row."PropertyNameEn"; #Here


    $ItemNamePreClean  = $ItemName

    if( $ItemNamePreClean -match "'"){
    $ItemNamePreClean = $ItemNamePreClean -replace "'", "";
    }
    if( $ItemNamePreClean -match "ˆ"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ˆ", " ";
    }
    if( $ItemNamePreClean -match "\("){
    $ItemNamePreClean = $ItemNamePreClean -replace "\(", " ";
    }
    if( $ItemNamePreClean -match "\)"){
    $ItemNamePreClean = $ItemNamePreClean -replace "\)", " ";
    }

    if( $ItemNamePreClean -match "à"){
    $ItemNamePreClean = $ItemNamePreClean -replace "à", "a" ;
    }
    if( $ItemNamePreClean -match "á"){
    $ItemNamePreClean= $ItemNamePreClean -replace "á", "a";
    }
    if( $ItemNamePreClean -match "â"){
    $ItemNamePreClean = $ItemNamePreClean -replace "â", "a";
    }
    if( $ItemNamePreClean -match "À"){
    $ItemNamePreClean = $ItemNamePreClean -replace "À", "A";
    }
    if( $ItemNamePreClean -match "Á"){
    $ItemNamePreClean= $ItemNamePreClean -replace "Á", "A";
    }
    if( $ItemNamePreClean -match "Â"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Â", "A";
    }

    if( $ItemNamePreClean -match "é"){
    $ItemNamePreClean = $ItemNamePreClean -replace "é", "e";
    }
    if( $ItemNamePreClean -match "è"){
    $ItemNamePreClean = $ItemNamePreClean -replace "è", "e";
    }
    if( $ItemNamePreClean -match "ê"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ê", "e";
    }
    if( $ItemNamePreClean -match "ë"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ë", "e";
    }
    if( $ItemNamePreClean -match "É"){
    $ItemNamePreClean = $ItemNamePreClean -replace "É", "E";
    }

    if( $ItemNamePreClean -match "ó"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ó", "o";
    }
    if( $ItemNamePreClean -match "ô"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ô", "o";
    }
    if( $ItemNamePreClean -match "Ó"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Ó", "O";
    }
    if( $ItemNamePreClean -match "Ô"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Ô", "O";
    }

    if( $ItemNamePreClean -match "î"){
    $ItemNamePreClean = $ItemNamePreClean -replace "î", "i";
    }
    if( $ItemNamePreClean -match "ï"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ï", "i";
    }
    if( $ItemNamePreClean -match "Î"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Î", "I";
    }
    if( $ItemNamePreClean -match "Ï"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Ï", "I";
    }

    if( $ItemNamePreClean -match "ù"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ù", "u";
    }
    if( $ItemNamePreClean -match "û"){
    $ItemNamePreClean = $ItemNamePreClean -replace "û", "u";
    }
    if( $ItemNamePreClean -match "Ù"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Ù", "U";
    }
    if( $ItemNamePreClean -match "Û"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Û", "U";
    }

    if( $ItemNamePreClean -match "æ"){
    $ItemNamePreClean = $ItemNamePreClean -replace "æ", "ae";
    }
    if( $ItemNamePreClean -match "Æ"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Æ", "AE";
    }

    if( $ItemNamePreClean -match "ç"){
    $ItemNamePreClean = $ItemNamePreClean -replace "ç", "c";
    }
    if( $ItemNamePreClean -match "Ç"){
    $ItemNamePreClean = $ItemNamePreClean -replace "Ç", "C";
    }

    if( $ItemNamePreClean -match "[^a-zA-Z0-9 ]"){
    $ItemNamePreClean = $ItemNamePreClean -replace "[^a-zA-Z0-9 ]", "";
    }

    $ItemName = $ItemNamePreClean
    $ItemName;
        $currentItem = New-Item $ContentPath -type $templatePath -ErrorAction SilentlyContinue -Name $itemName -Language $Language 
        if ($currentItem){
            $currentItem.Editing.BeginEdit();
            $currentItem["Legacy ID"]= $row."PropertyID";   #Here
            $currentItem["Property ID"]= $row."PropertyID"; #Here
            $currentItem["Property Name"] = $row."PropertyNameEn";  #Here           
            $currentItem["Property Description"] = $row."PropertyDescEn";   #Here
            $currentItem["USP"] = $row."USP";   #Here
            $currentItem["Property Tag Line"] = $row."PropertyTagLineEn";   #Here
            $currentItem["Is owned"] = $row."IsOwned";  #Here
            $currentItem["Is Managed"] = $row."IsManaged";  #Here
            $currentItem["Is Leased"] = $row."IsLeased";    #Here
            $currentItem["Is Deleted"] = $row."IsDeleted";  #Here
            $currentItem["Is Featured"] = $row."IsFeatured";    #Here
            $currentItem["Is New Property"] = $row."IsNewProperty"; #Here
            $currentItem["Property Region"] = $row."PropertyRegion";    #Here
            $currentItem["Property Square Footage Max"] = $row."PropertySquareFootageMax";  #Here
            $currentItem["Property Square Footage Min"] = $row."PropertySquareFootageMin";  #Here
            $currentItem["Percent Share In Property"] = $row."PercentShareInProperty";  #Here
            $currentItem["Property Brochure Name"] = $row."PropertyBrochureName";   #Here
            #$currentItem["Property Brochure"] = $row."";   #Here
            $currentItem["Property Type"] = $row."";    #Here
            $currentItem["Property Type Description"] = $row."";    #Here
            $currentItem["Property Neighborhood"] = $row."NeighbourhoodID"; #Here
            #$currentItem["Property Seo Area"] = $row."";   #Here

        #Care Service Section
            $currentItem["Care Section Title"] = $row."";   #Here
            $currentItem["Care Section Description"] = $row.""; #Here


        #Dining Section
            $currentItem["Dining Section Title"] = "Dining Services";   #Here
            $currentItem["Dining Section Description"] = $row."DiningDataDesc"; #Here


        #WellnessData
            $currentItem["Wellness Section Title"] = "Wellness Services";   #Here
            $currentItem["Wellness Section Description"] = $row."WellnessDataDesc"; #Here


        #Activities Section
            $currentItem["Activities Section Title"] = "Activities Services";   #Here
            $currentItem["Activities Section Description"] = $row."ActivitiesDataDesc"; #Here


        #Amenities Section
            $currentItem["Amenities Section Title"] = "Amenities";  #Here
            $currentItem["Amenities Section Description"] = $row."AmenitiesDataDesc";   #Here


        #Address Section
            $currentItem["Street name and number"] = $row."StreetNameAndNoEn";  #Here
            $currentItem["Municipalty"] = $row."MunicipaltyEn"; #Here

            $currentItem["Postal code"] = $row."PostalCode";    #Here
            $currentItem["Longitude"] = $row."Longitude";   #Here
            $currentItem["Latitude"] = $row."Latitude"; #Here
            $currentItem["Is Display on Map"] = $row."IsDisplayInMap";  #Here




            #French Section
            $langAdd = Add-ItemLanguage -Item $currentItem -Language $Language -TargetLanguage $TargetLanguage -IfExist Skip;
            $currentItem.Editing.EndEdit();

            $ItemPath = $ContentPath + "\" + $itemName
            $NewcurrentItem = Get-Item -Path "master:" -Id $currentItem.id -Language $TargetLanguage
            $NewcurrentItem.Editing.BeginEdit();
            $NewcurrentItem["Property Name"] = $row."PropertyNameFr"; 
            $NewcurrentItem["Property Description"] = $row."PropertyDescFr";
                            $currentItem["USP"] = $row."USPFr"; 
            $NewcurrentItem["Property Tag Line"] = $row."PropertyTagLineFr"; 
            $NewcurrentItem["Property Brochure Name"] = $row."PropertyBrochureNameFr"; 
            $NewcurrentItem["Dining Section Title"] = $row."DiningDataTitleFr"; 
            $NewcurrentItem["Dining Section Description"] = $row."DiningDataDescFr"; 
            $NewcurrentItem["Wellness Section Title"] = $row."WellnessDataTitleFr"; 
            $NewcurrentItem["Wellness Section Description"] = $row."WellnessDataDescFr"; 
            $NewcurrentItem["Activities Section Title"] = $row."ActivitiesDataTitleFr"; 
            $NewcurrentItem["Activities Section Description"] = $row."ActivitiesDataDescFr"; 
            $NewcurrentItem["Amenities Section Title"] = $row."AmenitiesDataTitleFr"; 
            $NewcurrentItem["Amenities Section Description"] = $row."AmenitiesDataDescFr"; 
            $NewcurrentItem["Street name and number"] = $row."StreetNameAndNoFr"; 
            $NewcurrentItem["Municipality"] = $row."MunicipaltyFr";             


            $NewcurrentItem.Editing.EndEdit();
        }
        else {
            $logThis =  "Couldn't find: " + $ContentPath + "Item: " + $itemName;
            $logThis;
            Write-Log $logThis;
        }
    }
}
$logInfo = "Bulk Update is Completed!";
$logInfo
Write-Log $logInfo

  Remove-Item $filePath

In your script you first start with:

$currentItem.Editing.BeginEdit();
$currentItem["Legacy ID"]= $row."PropertyID";   
$currentItem["Property ID"]= $row."PropertyID"; 
# ...
# other $currentItem changes
# ...
# and then you finish editing $currentItem with line
$currentItem.Editing.EndEdit();

Then you start editing $NewcurrentItem:

$NewcurrentItem = Get-Item -Path "master:" -Id $currentItem.id -Language $TargetLanguage
$NewcurrentItem.Editing.BeginEdit();
$NewcurrentItem["Property Name"] = $row."PropertyNameFr"; 

but suddenly you edit $currentItem with this line. And $currentItem is not in editing mode anymore:

$NewcurrentItem["Property Description"] = $row."PropertyDescFr";
#
#
    $currentItem["USP"] = $row."USPFr"; # <--- THIS Line CAUSES ERROR
#
#
$NewcurrentItem["Property Tag Line"] = $row."PropertyTagLineFr"; 

It's line $currentItem["USP"] = $row."USPFr"; which causes error

  • That's working but my csv data is not imported to the page.only page is created without any values – sitecore-u9 Apr 6 at 17:15
  • My answer updated to point you in which line you have bug – Marek Musielak Apr 6 at 17:39

It looks like somewhere inside your using block you try to update a field but you are not in editing mode.

One way to do this

$item.Editing.BeginEdit()
$item.Fields["Title"].Value = "new title"
$item.Editing.EndEdit()

or

$item."Title" = "new title"

if you obtain an item in a different way than cmdlets (Database.GetItem) you will have to wrap an item to be able to access fields like properties

here is how to wrap your item

$item = $item | Wrap-Item

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.