C# code task: RPAEngine does not exists
AnsweredI'm trying to read a string variable loaded with the response from a REST Api call
But I did not get far because i'm stuck a loading the json string from a variable in Foxtrot.
I get error "The name 'RPAEngine' dones not exists in the current context"
I seems that the first line where I load Newtonsoft.Json dll is working, because it does not fail on the using (it did before a wrote the first line).... so RPAEngine is working in the very first line, but not in the line -> RPAEngine.GetVar("AuthenticationResponce", json);
Next problem is to loop the deserialized json object and put data into a List in Foxtrot, so I can continue working on the data in a normal Foxtrot way ;-)
#### CODE ####
RPAEngine.LoadDLL("C:\Users\dby\Downloads\Newtonsoft.Json.dll")
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace HelloWorld
{
public class Hello
{
static void Main()
{
string json = "";
RPAEngine.GetVar("AuthenticationResponce", json);
RootObject root = JsonConvert.DeserializeObject<RootObject>(json, QuickType.Converter.Settings);
// loop to root object and save to a Foxtrot list variable
foreach(var item in root.data)
{
// loop to root object and save to a Foxtrot list variable
//Console.WriteLine(item);
}
}
}
public class TotalCurrency
{
public object currency { get; set; }
public object amount { get; set; }
}
public class Datum
{
public int id { get; set; }
public int pid { get; set; }
public object tid { get; set; }
public int uid { get; set; }
public string description { get; set; }
public DateTime start { get; set; }
public DateTime end { get; set; }
public DateTime updated { get; set; }
public int dur { get; set; }
public string user { get; set; }
public bool use_stop { get; set; }
public string client { get; set; }
public string project { get; set; }
public string project_color { get; set; }
public string project_hex_color { get; set; }
public string task { get; set; }
public string billable { get; set; }
public bool is_billable { get; set; }
public object cur { get; set; }
public List<string> tags { get; set; }
}
public class RootObject
{
public int total_grand { get; set; }
public object total_billable { get; set; }
public List<TotalCurrency> total_currencies { get; set; }
public int total_count { get; set; }
public int per_page { get; set; }
public List<Datum> data { get; set; }
}
}
-
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.
-
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 stuckThere 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": [
]
},
] -
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.
-
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:
- Call REST WebApi - DONE
- Save the JSON response to file - DONE
- Read JSON from file into something that can loop through the records - ISSUE
- 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"
},
]
},
] -
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:
- Call REST WebApi (C# action)
- 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)
- Use the "Open List" action to load the CSV file to a Foxtrot list (Open List action)
- Now you can loop your list...
Alternatively, you can:
- Call REST WebApi (REST action)
- Use Foxtrot formulas and/or Regular Expression to convert the big Foxtrot text variable to a list
-
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.
Please sign in to leave a comment.



Comments
10 comments