C# code task: RPAEngine does not exists

Answered

Comments

10 comments

  • Avatar
    Mathias Balsløw

    Hi Dennis,

    The C# action doesn't have a "GetVar" function as you can simply use Foxtrot variables in the code by writing the variable like in any other place in Foxtrot: [%Var]

    In terms of saving data to a Foxtrot list, that is not directly possible, but an easy way of doing this is to store the data in a txt or csv file and then use the Open List action afterwards to load the data from the file to a Foxtrot list.

    0
    Comment actions Permalink
  • Avatar
    Dennis Bybæk

    Saving the JSON to a CSV sounds like a possibility.

    But might have to strip the JSON header data, to get down to the actual list (data)... right?

     

    I tried that manually.:

    GRRR... æøå issue :-(

    Saved it to a CSV file and tried Data Import wizard.... no good.
    And looked at: https://support.foxtrotalliance.com/hc/en-us/articles/115002592531-How-to-Create-Use-Data-Import-Templates
    But i'm stuck

    There are 40 records, but is just reads lines i the CSV file

    In the buttom is a simplified example, with 2 records... can you load that from a CSV/TXT to a List variable?

    I have let some æøå stay in the example... the response is actually with correct æøå lettes, but put in the variable, I get these strange characters. And I cannot change culture.

     

     

    [
    {
    "id": 1356408357,
    "pid": 154282987,
    "tid": null,
    "uid": 2548913,
    "description": "på Økonomidata idriftsættelse",
    "start": "2019-11-08T14:28:10+01:00",
    "end": "2019-11-08T16:28:10+01:00",
    "updated": "2019-11-09T10:30:55+01:00",
    "dur": 7200000,
    "user": "Dby",
    "use_stop": true,
    "client": "30009 (Customer A)",
    "project": "1000 (Project 3)",
    "project_color": "0",
    "project_hex_color": "#06aaf5",
    "task": null,
    "billable": null,
    "is_billable": false,
    "cur": null,
    "tags": [

    ]
    },
    {
    "id": 1356383852,
    "pid": 153833694,
    "tid": null,
    "uid": 2548913,
    "description": "Økonomidata integration",
    "start": "2019-11-08T14:06:41+01:00",
    "end": "2019-11-08T15:06:41+01:00",
    "updated": "2019-11-08T14:27:21+01:00",
    "dur": 3600000,
    "user": "Dby",
    "use_stop": true,
    "client": "20038 (Customer B)",
    "project": "2050 (Project 1)",
    "project_color": "0",
    "project_hex_color": "#4dc3ff",
    "task": null,
    "billable": null,
    "is_billable": false,
    "cur": null,
    "tags": [

    ]
    },
    ]

    0
    Comment actions Permalink
  • Avatar
    Dennis Bybæk

    I managed saving the REST response directly to a TXT (ANSI)... all good with the æøå

    But reading the file into a variable (TEXT) the æøå is changed to the weird characters, no matter what I choose in Encoding.

    0
    Comment actions Permalink
  • Avatar
    Mathias Balsløw

    Hi Dennis,

    It seems like you are a bit of track with the approach. Encoding can be solved and worked around in different ways, but could you maybe start by describing the objective of what you are trying to do? You're mixing a lot of actions that I suspect you can simply boil down to one.

    0
    Comment actions Permalink
  • Avatar
    Dennis Bybæk

    Hi Mathias

    Main issue is to get the JSON data into a List, so I can loop through it and work with the data, record by record.

    The Encoding was just a side-issue... I'll make a new post, if needed, to keep it seperate.

    Main steps:

    1. Call REST WebApi - DONE
    2. Save the JSON response to file - DONE
    3. Read JSON from file into something that can loop through the records - ISSUE
    4. Loop the records and do stuff - PENDING

    A very simplified JSON example could be the following
    But I'm afraid that the sub-list "tags" might be an issue... if so, skip/remove the sub-list

     

    [
    {
    "id": 1356408357,
    "description": "Example description 1",
    "start": "2019-11-08T14:28:10+01:00",
    "end": "2019-11-08T16:28:10+01:00",
    "tags": [
    {
    "tagId": "3",
    "tagText": "Charlie"
    },
    ]
    },
    {
    "id": 1356383852,
    "description": "Example description 2",
    "start": "2019-11-08T14:06:41+01:00",
    "end": "2019-11-08T15:06:41+01:00",
    "tags": [
    {
    "tagId": "5",
    "tagText": "Alpha"
    },
    {
    "tagId": "7",
    "tagText": "Beta"
    },
    ]
    },
    ]

    0
    Comment actions Permalink
  • Avatar
    Mathias Balsløw

    Hi Dennis,

    The mentioned steps, do you perform all of them with your C# or with a mix of actions?

    I would assume that the easiest solution would be to:

    1. Call REST WebApi (C# action)
    2. Write the JSON response to a CSV file, you could also take care of encoding in this step (C# action) (for inspiration: https://stackoverflow.com/a/36348017)
    3. Use the "Open List" action to load the CSV file to a Foxtrot list (Open List action)
    4. Now you can loop your list...

    Alternatively, you can:

    1. Call REST WebApi (REST action)
    2. Use Foxtrot formulas and/or Regular Expression to convert the big Foxtrot text variable to a list
    0
    Comment actions Permalink
  • Avatar
    Dennis Bybæk

    Hi Mathias

    I'm using REST action saved to a file... that's all good.

    Then using "Open List" -> Import:

    It just reads the lines in the file. Open Data action does the same thing.

     

    0
    Comment actions Permalink
  • Avatar
    Mathias Balsløw

    Hi Dennis,

    From what I can see in your screenshot above, you are attempting to use the "Open List" on a file containing a JSON formatted text. You need a CSV file with this format:

    "id;description;start;end

    123;text;2019-11-08;2019-11-09

    124;text;2019-11-09;2019-11-10"

    It seems like you have just taken the JSON string and saved it as a CSV file, which won't work. You need your data in the actual CSV format to be able to use the "Open List" action.

    0
    Comment actions Permalink
  • Avatar
    Dennis Bybæk

    Hi Mathias

    Yes.. JSON to something I can loop.

    I think i'll try a C# action to deserialize the JSON from the file and put it into a CSV list.... then I can open the CSV and loop the records.

    0
    Comment actions Permalink
  • Avatar
    Mathias Balsløw

    Hi Dennis,

    Exactly, that's my suggestion for a solution. That is always the easiest way to do it.

    For things like this, I typically use Python as it is very easy to work with APIs and JSON, but you can, of course, do it in C# if that is your preferred programming language.

    0
    Comment actions Permalink

Please sign in to leave a comment.