3

I've recently found out that you can serialize items if it's new only using

<evaluator type="Unicorn.Evaluators.NewItemOnlyEvaluator, Unicorn" singleInstance="true"/>

When I add this to the configuration, all the items I include will only be serialized if it is new.

I would like to serialize a parent item and only some specific child items to be serialized when it's new, the other child items will still be serialized normally. How can I achieve this?

1 Answer 1

2

You will need 2 configurations for this as the evaluator works per configuration.

Your first configuration should serialize the parent and exclude children. Your second configuration can include the child items and be set to use the `NewItemOnlyEvaluator:

For example:

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <unicorn>
            <configurations>
                <configuration name="Example.ParentItems"
                               description="Serialize the parent item but none of the child items"
                               patch:after="configuration[@name='Foundation.Serialization']">
                    <targetDataStore physicalRootPath="$(sourceFolder)\$(layer)\$(module)\serialization\parentItems" />
                    <predicate>
                        <include name="ParentItem" database="master" path="/sitecore/Content/ParentItem">
                            <exclude path="ChildItem1" />
                            <exclude path="ChildItem2" />
                        </include>
                    </predicate>
                </configuration>
                <configuration name="Example.ChildItems"
                               description="Serialize the child items using the NewItemOnlyEvaluator"
                               patch:after="configuration[@name='Foundation.Serialization']">
                    <targetDataStore physicalRootPath="$(sourceFolder)\$(layer)\$(module)\serialization\newitemonly" />
                    <evaluator type="Unicorn.Evaluators.NewItemOnlyEvaluator, Unicorn" singleInstance="true"/>
                    <predicate>
                        <include name="Child Item 1" database="master" path="/sitecore/Content/ParentItem/ChildItem1"></include>
                        <include name="Child Item 2" database="master" path="/sitecore/Content/ParentItem/ChildItem2"></include>
                    </predicate>
                </configuration>
            </configurations>
        </unicorn>
    </sitecore>
</configuration>

Update based on your updated question:

If you want to be more specific about which child items are NewItemOnly then you just need to be specific with your exclusions in the main configuration and also with your predicates in your NewItemOnlyEvaluator configuration.

5
  • Hit enter too early... examples coming :)
    – Richard Seal
    Commented Aug 14, 2019 at 13:47
  • Thanks for the answer, but wouldn't all the child items only be serialized when it's new? what I want to achieve is that only some/specific child items will be serialized as new items only, and the other child items will be serialized normally. I'll edit my question to be more clear
    – qwert
    Commented Aug 14, 2019 at 13:58
  • The same principle applies here, you need multiple configurations, one for the always update and one for the items you want as NewItemOnly. Also, I think your understanding of NewItemOnly is backwards. The items will always be serialized to disk. The evaluator works when syncing to Sitecore. If the item already exists in the target database, then it will not be added/updated. If it is not there, it will be created.
    – Richard Seal
    Commented Aug 14, 2019 at 14:00
  • I have updated the configuration example to show what you need
    – Richard Seal
    Commented Aug 14, 2019 at 14:04
  • I've tried it in my project and it is working as you said. thanks for the answer
    – qwert
    Commented Aug 15, 2019 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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