- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
Please I'm trying to create my data source load by script, with my restmessageV2, after to create my staging table and transform map using load data. But i have error with my script data source due to the table objet. Here is the code, if someone could help please.
Thanks
(function loadData(import_set_table, data_source) {
//Je recupère la methode dans le Rest Message et l'application scoped en paramètres
var r = new sn_ws.RESTMessageV2('x_1205883_librar_0.MeteoFrance', 'getStations');
var tableName = import_set_table.getTableName();
//Je recupère les infos liées d'exécution de la requête dans response, récupération du corps de la réponse dans le responseBody, et le code HTTP du statut si ça marché ou pas dans httpStatus
var response = r.execute();
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
var responseBody = response.getBody();
var data = JSON.parse(responseBody);
var nomStation = data[0].nom;
var idStation = data[0].id;
var short_descStation = 'La Station météo est : ' + nomStation + '(' + idStation + ')';
//Si le status est 200 (OK!) -> Je crée l'Incident en récupérant le nom et l'id.
for (var i = 0; i < parsed.length; i++) {
var gr = new GlideRecord(tableName); //
gr.initialize();
gr.station_name = parsed[i].nom;
gr.station_id = parsed[i].id;
gr.http_status = httpStatus;
gr.raw_body = body;
gr.insert();
}
} else {
gs.addErrorMessage('Erreur de création : ' + httpStatus);
}
})(import_set_table, data_source);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks for your answer.
Here is how I fix it :
(function loadData(import_set_table, data_source, import_log, last_success_import_time, partition_info) {
//Je recupère la methode dans le Rest Message et l'application scoped en paramètres
var r = new sn_ws.RESTMessageV2('x_1205883_librar_0.MeteoFrance', 'getStations');
//Je recupère les infos liées d'exécution de la requête dans response, récupération du corps de la réponse dans le responseBody, et le code HTTP du statut si ça marché ou pas dans httpStatus
var response = r.execute();
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
var responseBody = response.getBody();
var data = JSON.parse(responseBody);
//var parsed = JSON.parse(responseBody);
var nomStation = data[0].nom;
var idStation = data[0].id;
var short_descStation = 'La Station météo est : ' + nomStation + '(' + idStation + ')';
//Je remplie la description de chaque champ avec un retour à la ligne, indentation 2 espaces -> contient des '\n'
var descStation = JSON.stringify(data[0], null, 2);
//Si le status est 200 (OK!) -> Je crée l'Incident en récupérant le nom et l'id.
var obj = {
"idStation" : data[0].id,
"nomStation" : data[0].nom,
"short_descStation" : short_descStation,
"descStation" : descStation
};
import_set_table.insert(obj); //I PUT THIS WHILE SETTING AN OBJECT
//import_set_table.insert(data[0]); //I COULD PUT THIS
} else {
gs.addErrorMessage('Erreur de création : ' + httpStatus);
}
})(import_set_table, data_source, import_log, last_success_import_time, partition_info);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Jeff W NZAO B ,
In your code you parsed the response into data but later iterate over parsed (which is undefined).
Also body is used but never defined (you stored the response in responseBody).
var r = new sn_ws.RESTMessageV2('x_1205883_librar_0.MeteoFrance', 'getStations');
var tableName = import_set_table.getTableName();
var response = r.execute();
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
var responseBody = response.getBody();
var parsed = JSON.parse(responseBody);
for (var i = 0; i < parsed.length; i++) {
var gr = new GlideRecord(tableName);
gr.initialize();
gr.station_name = parsed[i].nom;
gr.station_id = parsed[i].id;
gr.http_status = httpStatus;
gr.raw_body = responseBody;
gr.insert();
}
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks for your answer.
Here is how I fix it :
(function loadData(import_set_table, data_source, import_log, last_success_import_time, partition_info) {
//Je recupère la methode dans le Rest Message et l'application scoped en paramètres
var r = new sn_ws.RESTMessageV2('x_1205883_librar_0.MeteoFrance', 'getStations');
//Je recupère les infos liées d'exécution de la requête dans response, récupération du corps de la réponse dans le responseBody, et le code HTTP du statut si ça marché ou pas dans httpStatus
var response = r.execute();
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
var responseBody = response.getBody();
var data = JSON.parse(responseBody);
//var parsed = JSON.parse(responseBody);
var nomStation = data[0].nom;
var idStation = data[0].id;
var short_descStation = 'La Station météo est : ' + nomStation + '(' + idStation + ')';
//Je remplie la description de chaque champ avec un retour à la ligne, indentation 2 espaces -> contient des '\n'
var descStation = JSON.stringify(data[0], null, 2);
//Si le status est 200 (OK!) -> Je crée l'Incident en récupérant le nom et l'id.
var obj = {
"idStation" : data[0].id,
"nomStation" : data[0].nom,
"short_descStation" : short_descStation,
"descStation" : descStation
};
import_set_table.insert(obj); //I PUT THIS WHILE SETTING AN OBJECT
//import_set_table.insert(data[0]); //I COULD PUT THIS
} else {
gs.addErrorMessage('Erreur de création : ' + httpStatus);
}
})(import_set_table, data_source, import_log, last_success_import_time, partition_info);
