3

Using Sitecore 9.0.1 and DEF 2.0.1, to process JSON from an API. This works well until I have child entities in the json.

E.g.

{

  "name": "XXX",
  "short_description": null,
  "description": null,
  "type": "destination",
  "childobject": [
    {
      "id": "1",
      "name": "YYY",
      "type": "AAA"

    },
    {
      "id" : "2"
      "name": "FFF",
      "type": "ASSSAA"
    }
  ]
}

My processor adds the parent object to IterableDataSettings with just the one row for the parent object. But how do I process childobjects ? It would seem they need to be added to a seperate IterableData set and pipeline but is that even possible in code?

My issues may stem from using a generic processor (ReadJsonDetailApiProcessor) that knows nothing about the "childobjects".

When I create an accessor for childobjects, could I use a custom Value Reader implementation ? But then again it would need to use a seperate pipeline

As you can tell, Im lacking clarity on how to do this at the moment

  • Why does pipeline step pass only parent object instead of all json? – Vlad Shpak May 17 '18 at 0:36
  • Pipeline step does have all of the json but it's processed based on json key names and accessed via JSONPath. This works for simple types but not for the child objects. Im thinking I may need a CustomReader implementation for the childobject data accessor.. – Steve Ward May 17 '18 at 0:58
  • Hi @VladShpak. The pipeline step does have all the json. However, the child objects aren't mapped to any Sitecore items and Sitecore Item Field Value Accessor only allows a field name. It seems to me I would like to give the field value for childobject it's own Sitecore mapping and it's own resolution of a Sitecore item in the DEF, but I would need to configure the Sitecore template to use somewhere and that config for child objects doesnt seem to exist in DEF. Does that make any sense or am I completely off the track? – Steve Ward May 28 '18 at 0:26
2

To resolve this issue you have to deep dive into two Pipeline Steps that could help you.


Resolve Sitecore Item Pipeline Step

This Pipeline step has "Find Existing Item" section with two settings.

enter image description here

Parent for Item - You have to specify the parent item in the content tree in order to pipeline step knows the main root location for resolved items. This setting uses for the first-level item. In your case under selected parent will be added items with mapped fields: name, short_description, description, type.

Parent for Item Location - If a location is set, and the object at the location is a Sitecore item, this item is used as the parent instead of the item specified in Parent for Item. This setting can be used when you need resolve "childobjects". How it works. When the parent item was added/updated it's still in the context together with source object(json) and it means that you just can extract/get/copy childobjects from source and iterate them and for the resolver use this field to specify parent.


Copy Object from Context to New Location Pipeline Step

This Pipeline Step has "Location Settings" section. You can use this pipeline step in order to extract/copy/get "childobjects".

enter image description here

Source object location - to specify source object location. In your case to specify your json object location.

Source Object value Accessor - Component used to read the source object from the object resolved from the source object location (if not set, the source object itself is used). In other words here accessor should be used that knows how to extract/get/read childobject from json/parentjson.

Target Object Location - The object that is resolved is copied to this location. It means that object resolved from Source "Object value Accessor" will be copied to the specified location.

Now you should be able to iterate the childobjects.

Example:

enter image description here

  • Thanks Vlad. My existing Pipeline goes Resolve item => Apply Mappings => Update Sitecore. Would the new "Copy Object from Context to New Location Pipeline Step" go between Resolve item and Apply Mappings ? Where would the step for iterating the child data fit into this? – Steve Ward Jun 1 '18 at 0:17
  • Also, do you know if ""Copy Object from Context to New Location Pipeline Step"" can be used to add to the mappings set up in Apply Mappings? This would be instead of a seperate pipeline step for iterating the child date – Steve Ward Jun 1 '18 at 5:52
  • Should be similar as in option 2 sitecore.stackexchange.com/questions/11711/… – Vlad Shpak Jun 1 '18 at 7:18
  • I updated my answer with an example. How I see it. – Vlad Shpak Jun 1 '18 at 7:20
  • Is there any documentation that explains exactly how to use the "Copy Object from Context to New Location Pipeline Step"? I need to do something similar to this and I really don't understand how to use a step of that type. Is there any Sitecore documentation that explains all of the OOB step types and how to use them? – Corey Burnett Jun 13 '18 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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