I'm by no means what I would call a "developer" but dabble quite a bit. I'm working on some Apps Script code to query an API and push the results into SQL. I have most of the bits working but I've noticed that while I'm debugging in the Apps Script editor, when I step into the following line of code, the editor throws the "could not connect to server message at the top.
var response = UrlFetchApp.fetch(clientApiURL,options);
var resultSet = JSON.parse(response.getContentText()); <-- this is the line that is crashing the IDE
Anyone know how to better debug this? When I'm not debugging it, the code seems to behave and function properly. But with this API, not all objects are formatted the same way, so I like to use the debugger to inspect them. I can do that when the editor crashes.
Any help/insight would be super appreciated. I've also pasted below the value of response.getContentText()
{"result":{"lead":[{"id":"332","accountID":null,"ownerID":null,"companyName":"","title":null,"firstName":"RYAN","lastName":"CAVANAUGH","street":null,"city":null,"country":null,"state":null,"zipcode":null,"emailAddress":"email#here.com","website":null,"phoneNumber":null,"officePhoneNumber":null,"phoneNumberExtension":null,"mobilePhoneNumber":null,"faxNumber":null,"description":null,"campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":null,"active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":null,"id":"5222020","callCount":"215","queryLimit":"50000"}
This will reproduce the error:
function test(){
var obj={"result":{"lead":[{"id":"332","accountID":null,"ownerID":null,"companyName":"","title":null,"firstName":"RYAN","lastName":"CAVANAUGH","street":null,"city":null,"country":null,"state":null,"zipcode":null,"emailAddress":"email#here.com","website":null,"phoneNumber":null,"officePhoneNumber":null,"phoneNumberExtension":null,"mobilePhoneNumber":null,"faxNumber":null,"description":null,"campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":null,"active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":null,"id":"5222020","callCount":"215","queryLimit":"50000"}
var resultSet = JSON.parse(obj);
}
Taking a look at the problem:
function test(){
var obj={"result":{"lead":[{"id":"332","accountID":null,"ownerID":null,"companyName":"","title":null,"firstName":"RYAN","lastName":"CAVANAUGH","street":null,"city":null,"country":null,"state":null,"zipcode":null,"emailAddress":"email#here.com","website":null,"phoneNumber":null,"officePhoneNumber":null,"phoneNumberExtension":null,"mobilePhoneNumber":null,"faxNumber":null,"description":null,"campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":null,"active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":null,"id":"5222020","callCount":"215","queryLimit":"50000"}
var resultSet = JSON.parse(JSON.stringify(obj));
}
but so what the point of the parse is to return an object from a string not from object.
But I do see the problem. 'Cannot connect to the server'
I found that this does seem to work know:
function test(){
var obj='{"result":{"lead":[{"id":"332","accountID":"","ownerID":"","companyName":"","title":"","firstName":"RYAN","lastName":"CAVANAUGH","street":"","city":"","country":"","state":"","zipcode":"","emailAddress":"email#here.com","website":"","phoneNumber":"","officePhoneNumber":"","phoneNumberExtension":"","mobilePhoneNumber":"","faxNumber":"","description":"","campaignID":"789934082","trackingID":"202003_5e6fa18a87853a69eb306910","industry":"","active":"1","isQualified":"1","isContact":"1","isCustomer":"1","status":"4","updateTimestamp":"2020-05-08 20:24:48","createTimestamp":"2020-05-03 20:23:29","leadScoreWeighted":"23","leadScore":"26","isUnsubscribed":"0","leadStatus":"customer","persona":"","product_5e554b933fb5b":""}]},"error":"","id":"5222020","callCount":"215","queryLimit":"50000"}';
var resultSet = JSON.parse(obj);
var end="is near";//I just put this here to have a place to stop with debugger running
}
I replaced all of the null s with "".
I would like to have an option to save the geoJSON file from Google Spreadsheets.
The issue has been raised here:
https://gis.stackexchange.com/questions/140995/publishing-google-sheet-to-web-as-geojson-file
although the plugin available here:
https://github.com/mapbox/geo-googledocs/
doesn't work because the geocode receiving the error message:
https://github.com/mapbox/geo-googledocs/issues/42
UiApp has been deprecated. Please use HtmlService instead.
I tired to combine the existing code, provided by this plugin with the code proposed as a way to fixing this issue:
https://gist.github.com/hidrodixtion/c3a6b6ba7af624d1800625efb7a40fbd
The code name is Geo.js as per the plugin provided above
I put the function doGet above the Geocoders as per below:
// Global variables
function doGet() {
return HtmlService.createHtmlOutputFromFile('Index');
}
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sheet = ss.getActiveSheet(),
activeRange = ss.getActiveRange(),
settings = {};
var geocoders = {
yahoo: {
... another part of the code available here:
https://raw.githubusercontent.com/mapbox/geo-googledocs/master/MapBox.js
unfortunately it doesn't work.
It seems like I don't know where I must superseed the depreciated UiApp function with the HTML service.
The problem is, that I don't know what part of the code in the Geo plugin should be replaced. It might be really helpful as the plugin can do the geocoding either.
My another part of combination was as follows:
I changed the code:
// Create a new UI
var app = UiApp.createApplication()
.setTitle('Export GeoJSON')
.setStyleAttribute('width', '460')
.setStyleAttribute('padding', '20');
into:
var app = HtmlService.createHtmlOutput().setWidth(800).setHeight(600);
.setTitle('Export GeoJSON') //line 105
.setStyleAttribute('width', '460')
.setStyleAttribute('padding', '20');
but once I save now I get this:
Syntax error. (line 105, file "Geo")
I picked up this code from here:
https://gist.github.com/hidrodixtion/c3a6b6ba7af624d1800625efb7a40fbd
line 141
Does anybody knows how to fix this issue?
I am experimenting with iMacros to automate as task that Firefox will do. I simply want to save the current page with the MAFF extension. The JavaScript that the iMacros forum has lead me to, is this:
// I stuck these variable in just to try something.
var doc = "http://www.traderjoes.com";
var file = "C:\\Export\\Test.maff";
var format = "MAFF";
// I stuck these variable in just to try something.
var MafObjects = {};
Components.utils.import("resource://maf/modules/mafObjects.jsm",
MafObjects);
var jobListener = {
onJobComplete: function(aJob, aResult) {
if (!Components.isSuccessCode(aResult)) {
// An error occurred
} else {
// The save operation completed successfully
}
},
onJobProgressChange: function(aJob, aWebProgress, aRequest,
aCurSelfProgress,
aMaxSelfProgress,
aCurTotalProgress,
aMaxTotalProgress) { },
onStatusChange: function(aWebProgress, aRequest, aStatus,
aMessage) { }
};
var saveJob = new MafObjects.SaveJob(jobListener);
saveJob.addJobFromDocument(doc, file, format);
saveJob.start();
I was only getting an error on line 26 because this was sample code. With the little JavaScript I know I tried to add some variables on the lines before the code starts. The thing is that when I try to search for syntax example for the method .addJobFromDocument I don’t find much, just like two results. Is this a method of JavaScript? Usually with things from the DOM you will get a great deal of information on them.
Does anybody know a way of automating the save of MAFF of the current open tab in Firefox and then closing the browser? iMacros was something I came to and glad to see it features but really I just want to automate from a command line the saving of a URL as a MAFF archive The doc (that I got from iMacros forum) also had these code snippets but I don’t have much idea how to use them. Thanks
var fileUri = Components.
classes["#mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService).
newFileURI(file);
var persistObject = new MafObjects.MafArchivePersist(null, format);
persistObject.saveDocument(doc, fileUri);
Also:
var doc = gBrowser.contentDocument;
var file = Components.classes["#mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\My Documents\\Test.maff");
var format = "TypeMAFF";
I am trying to get the icon url/name corresponding to document retrieved from a SharePoint document library using the following javascript code (i am using JSOM):
function GetIcon(filename)
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var iconName;
iconName = web.mapToIcon(filename, '', SP.Utilities.IconSize.Size16);
var iconUrl = "/_layouts/images/" + iconName.get_value();
alert(iconUrl);
}
i cant observe any problem in the code but it always shows icon name as '0' than displaying the real icon name (i.e. icdoc.gif, ictxt.gif etc).
Am i missing something here?
Please guide me through this.
Your code works fine for me. It even works if the file does not exist and with an unrecognized file extension. Also, permissions do not appear to be involved.
If you browse to the page using Chrome and look on the Network tab of the Developer Tools (F12), you can view the raw response of the request. The name of the request is "Process Query". The image below shows the area I am referring to. This should give you some more insight on the problem.
iconName will be only populated after calling executeQueryAsync
context.executeQueryAsync(function() {
var iconUrl = "/_layouts/images/" + iconName.get_value();
alert(iconUrl);
}, function() { alert("Errors"); });