Breaking out Kinetic App Data

Edit: This came from here:

It’s ironic that you posted this today, because I am fighting the escaped string issue to make it easier to read the jsonc files that encapsulate App Studio layers. I tried using your template solution from another thread for parsing and kept getting Sorry Something Went Wrong.

Do you have any tips on getting the code from the Content key in the layout files to format as proper json? This is the format:
"{\"config\":{\"Name\":\"config\",\"Version\":\"2.0\"},\"layout\":{\"Name\":\"layout\",\"Version\":\"3.0\",\"Diffs\":[{\"Id\":\"\",\"Path\":\"/caption\",\"Value\":\"Customer(entry)\",\"Operation\":\"Replace\",\"Index\":0}],\"Operation\":\"Replace\"},\"Main\":{\"Name\":\"Main\",\"Version\":\"3.0\",\"Diffs\":[{\"Id\":\"\",\"Path\":\"/caption\",\"Value\":\"Customer(entry)\",\"Operation\":\"Replace\",\"Index\":0}],\"Operation\":\"Replace\"},\"Slider.NewCustomerShipTo\":{\"Name\":\"Slider.NewCustomerShipTo\",\"Version\":\"3.0\",\"Diffs\":[],\"Operation\":\"Replace\"},\"Activity\":{\"Name\":\"Activity\",\"Version\":\"3.0\",\"Diffs\":[],\"Operation\":\"Replace\"},\"Slider.GlbContactList\":{\"Name\":\"Slider.GlbContactList\",\"Version\":\"3.0\",\"Diffs\":[],\"Operation\":\"Replace\"},\"Slider.GlbShipToList\":{\"Name\":\"Slider.GlbShipToList\",\"Version\":\"3.0\",\"Diffs\":[],\"Operation\":\"Replace\"}"

1 Like

Let’s go back and explore what you tried, and why you are doing this so I can help better.

I wouldn’t try, as those are pieces of a whole, and it’s probably better to retrieve the whole, so you can study it in context.

Anyway, give us the skinny on what you are actually doing and why so we know how to answer.

1 Like

Thank you for breaking this out into a separate topic, and for taking the time to help.

The reason I’m trying to read the layout.jsonc files is that I’m having issues in App Studio that I cannot fix in the UI. Specifically, the refresh button in Customer disappeared completely in one of my layers. I never removed it, but it is gone. I can add it back, but App Studio keeps defaulting the tool properties to have a style of “Primary”. Removing Primary and 0 in these properties won’t save:

So my plan was to physically remove the Primary and 0 values from the JSON file.

I’ve tried a bunch of different pieces of code to format the output I’ve found on these forums - mostly yours.

The function I tried last night was this (I removed the full json because it was messing up this posts’ formatting):

string json = "{\"config\":{\"Name\":\"config\",\"Version\":\"2.0\"}

Newtonsoft.Json.Linq.JObject obj =JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(json);

DataSet resultDS = JsonConvert.DeserializeObject<DataSet>(obj["config"].ToString());

output = resultDS;

I also tried your template suggestions here, attempting to pull out the “config” object:

Ok, first, I don’t know if it’s a typo, but that is missing a closing brace “}” on the end.

That (corrected) json when formatted will look like:

{
    "config": {
        "Name": "config",
        "Version": "2.0"
    },
    "layout": {
        "Name": "layout",
        "Version": "3.0",
        "Diffs": [
            {
                "Id": "",
                "Path": "/caption",
                "Value": "Customer(entry)",
                "Operation": "Replace",
                "Index": 0
            }
        ],
        "Operation": "Replace"
    },
    "Main": {
        "Name": "Main",
        "Version": "3.0",
        "Diffs": [
            {
                "Id": "",
                "Path": "/caption",
                "Value": "Customer(entry)",
                "Operation": "Replace",
                "Index": 0
            }
        ],
        "Operation": "Replace"
    },
    "Slider.NewCustomerShipTo": {
        "Name": "Slider.NewCustomerShipTo",
        "Version": "3.0",
        "Diffs": [],
        "Operation": "Replace"
    },
    "Activity": {
        "Name": "Activity",
        "Version": "3.0",
        "Diffs": [],
        "Operation": "Replace"
    },
    "Slider.GlbContactList": {
        "Name": "Slider.GlbContactList",
        "Version": "3.0",
        "Diffs": [],
        "Operation": "Replace"
    },
    "Slider.GlbShipToList": {
        "Name": "Slider.GlbShipToList",
        "Version": "3.0",
        "Diffs": [],
        "Operation": "Replace"
    }
}

This won’t work because config is not a dataset.

Where do you want to go from here?

1 Like

The missing curly brace was only because I trimmed the full JSON for the post and neglected to add the closing brace.

The output you’re showing is exactly what I’m trying to get for output. I didn’t really need to pull just the config key out…I thought that was the parent key to the entire object. I want the whole thing, and I was trying to convert it to a dataset only for easy viewing. Either a formatted string (like you’re showing) or a dataset will work great for my purposes.

Thanks Kevin!

1 Like

Then JToken.Parse(json).ToString() will give you formatted (pretty) output.

This is what I’m seeing when I run the function to parse the string:

Is there an intermediate step I’m missing? The code is very simple:

string json = "{\"config\":{\"Name\":\"config\",\"Version\":\"2.0\"},\"layout\":{\"Name\":\"layout\",\"Version\":\"3.0\",\"Diffs\":[{\"Id\":\"\",\"Path\":\"/caption\",\"Value\":\"Customer(entry)\",\"Operation\":\"Replace\",\"Index\":0}],\"Operation\":\"Replace\"}}";

output = Newtonsoft.Json.Linq.JToken.Parse(json).ToString();

No, but you are missing something :wink:

If you are expecting the return from your function to look like json, then you are out of luck out of the box. “output” is a string, not an object, thus it will be serialized as a string.

You can go vote on the idea linked in my main thread, and for now use the workaround I posted there by encasing it in a dataset.

If you need more help with that let me know.

2 Likes

OK, that makes sense. For my own knowledge, I would be certainly be interested in learning how to turn this into a dataset.

I understand how you did it in your example, but you were generating the dataset from system (and generated) objects. I need to do it from string input, and I’m not sure how to split the strings into the key/value hierarchy that a dataset will require.

2 Likes
//using Newtonsoft.Json;
//using Newtonsoft.Json.Linq;

Func<string, string, object, DataSet> CreateDSAndAddCustomObjectAsRow = (tableName, columnName, objToAdd) =>
{
    var ds = new DataSet();
    var dt = ds.Tables.Add(tableName);
    dt.Columns.Add(new DataColumn(columnName, typeof(object)));
    dt.Rows.Add(objToAdd);
    return ds;
};

string json = "{\"config\":{\"Name\":\"config\",\"Version\":\"2.0\"},\"layout\":{\"Name\":\"layout\",\"Version\":\"3.0\",\"Diffs\":[{\"Id\":\"\",\"Path\":\"/caption\",\"Value\":\"Customer(entry)\",\"Operation\":\"Replace\",\"Index\":0}],\"Operation\":\"Replace\"}}";

var o = JToken.Parse(json);

output = CreateDSAndAddCustomObjectAsRow("TestTable", "TestColumn", o);

{
  "output": {
    "TestTable": [
      {
        "TestColumn": {
          "config": {
            "Name": "config",
            "Version": "2.0"
          },
          "layout": {
            "Name": "layout",
            "Version": "3.0",
            "Diffs": [
              {
                "Id": "",
                "Path": "/caption",
                "Value": "Customer(entry)",
                "Operation": "Replace",
                "Index": 0
              }
            ],
            "Operation": "Replace"
          }
        }
      }
    ]
  }
}
3 Likes

Kev, you are something else man. Thank you for being so generous with your time & knowledge!

I want to get where you are. I’m in the process of taking the courses in the Microsoft Learning Center C# Collection. This covers the concepts and syntax of C#, but I’m going to want to learn whatever will help me understand the wiring of Epicor better.

I’m thinking I’ll want to learn at least:

  • EntityFramework Core
  • LINQ
  • MVC/MVVM architecture

Did I miss anything? Are there any programming patterns you’ve noticed in the Epicor codebase that you think would be helpful to understand?

Grateful for your help, as always :pray: :eagle: :dumpster_fire:

2 Likes

Ok first step.

Break everything.

destroy that 70s show GIF by Laff

Then figure out how to put it back together again, only better. (or worse, you’ll still learn)

I’ll get back to you with a longer answer, this ol’ brain has had enough for today.

6 Likes