I need to store an Australian domain as a string. Australian domains end with ".com.au"
Google Scripts seems to be displaying all instances of ".com.au" with "(class)".
To reproduce, create a basic function in Google Apps Scripts as follows:
function myFunction() {
var x = "com.au";
console.log("x: " + x);
var z = 1; //<--create break point here
}
Create a breakpoint at var z = 1, and then debug the script.
Actual Results:
In the console (at breakpoint):
x: (class)
Expected Results:
x: "com.au"
*Note: upon further testing, from a practical perspective, "(class)" seems to still be treated as "com.au" so this is not a blocker to use, but it is odd and does not help when debugging.
This issue was reported as a bug to Google: https://issuetracker.google.com/issues/114358543
This looks to be a bug of the Google Apps Script editor debugger that should be reported to Google. Please follow the directions on https://developers.google.com/apps-script/support#bugs.
I just got around this bug with the use of an Array.
function myFunction() {
var array = new Array();
var text ="email#email.com.br";
array[0] = string;
}
text returns email#email.(class)
array[0] returns email#email.com.br
Related
I wanted to learn a little more about Google Forms so I did this little form and as I was adding text validation to the the textItems which are meant to contain a URL and an Email I noticed that some of the things I expected to see in the code completion drop downs were not available. So I tried running without them and kept on getting errors like "cannot find setValidation(TextValidationBuilder)".
function createSimpleForm()
{
var linkValidation=FormApp.createTextValidation().requireTextIsUrl();
var emailValidation=FormApp.createTextValidation().requireTextIsEmail();
var ss=SpreadsheetApp.getActiveSpreadsheet();
var form=FormApp.create('Google Apps Script Question');
form.setDescription('A Simple Form to display my script editing problem.')
.setConfirmationMessage('Thanks. I\'ll be getting back to you at your email.')
.setAllowResponseEdits(true)
.setAcceptingResponses(false)
.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
var containerLink=form.addTextItem();
containerLink.setTitle('Enter a URL')
.setValidation(linkValidation);
var clientEmail=form.addTextItem();
clientEmail.setTitle('Enter an email address')
.setValidation(emailValidation)
.isRequired();
}
Then I noticed that only the build() command returns a TextValidation object and that's what the parameter for setValidation needs
So at that point I decided to stick the commands that I thought belong there and finished with a build() and code runs with no errors.
function createSimpleForm()
{
var linkValidation=FormApp.createTextValidation().setHelpText('This must be a URL.').requireTextIsUrl().build();
var emailValidation=FormApp.createTextValidation().setHelpText('This must be a EMail.').requireTextIsEmail().build();
var ss=SpreadsheetApp.getActiveSpreadsheet();
var form=FormApp.create('Google Apps Script Question');
form.setDescription('A Simple Form to display my script editing problem.')
.setConfirmationMessage('Thanks. I\'ll be getting back to you at your email.')
.setAllowResponseEdits(true)
.setAcceptingResponses(false)
.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
var containerLink=form.addTextItem();
containerLink.setTitle('Enter a URL')
.setValidation(linkValidation);
var clientEmail=form.addTextItem();
clientEmail.setTitle('Enter an email address')
.setValidation(emailValidation)
.isRequired();
}
I tried shutting down my browser and returning to the script editor but it doesn't seem to make any difference the same methods still missing from content assist. I'm wondering if any one else has had the same problem?
Yes, the methods build, copy, and setHelpText are missing from the autocomplete on TextValidationBuilder objects. You may want to report this on the Apps Script issue tracker.
Documentation is more reliable than the editor, so when in doubt, go with what documentation says. The autocomplete is flawed in other ways; for example, on the array objects it misses such basic methods as indexOf, map, filter, and reduce.
Q: why is e.parameter.wfId undefined (in the log) after running the script below (as a web-app)
I call script with this URL
https://script.google.com/a/macros/gappspro.com/exec?service=my-webapp-key
without a parameter (&wfId=somecharacters)
function doGet(e) {
var app = UiApp.createApplication().setTitle('Workflow Builder');
var mainGrid = app.createGrid(2,1).setId('FILE_doGet_mainGrid');
app.add(mainGrid);
var wfId = '1234567890' // FILE.doGet.randomString();
mainGrid.setWidget(1,0, app.createTextBox().setValue(wfId).setId('wfId').setName('wfId'));
var handler = app.createServerHandler('func');
handler.addCallbackElement(mainGrid);
Logger.log(e.parameter.wfId);
return app;
}
function func(e) {
return x;
}
I am trying to implement the workflow script from chapter 8 of james ferreira’s book Enterprise Application Essentials and in the add Docs section i ran into the problem that e.parameter.wfId in line “var wfRowArray = FILE.ssOps.getWfRowFromSS(e.parameter.wfId), “ is undefined when running the script. (on page 134 in the book, not the PDF).
In the example above i brought the code back to the essence of what is causing the error,...for me.
e.parameter.wfId is only available in your func(e) function, not in the doGet. the variable e represents the elements of the callBackElement catch by the handler function.
If I have understood your question correctly, this is behaving as expected.
You say "h-ttps://script.google.com/a/macros/gappspro.com/exec?service=my-webapp-key without a parameter (&wfId=somecharacters)"
So, I believe you are not passing any URL parameters to the script URL and therefore you get them as undefined.
If you call your script with the URL parameters, say
h-ttps://script.google.com/a/macros/gappspro.com/exec?service=my-webapp&wfId=somecharacters
then you can expect to see e.parameter.wfld
i use directionFinder in Google Apps Script application and I want do add some waypoints. Everything works well when i add this like this:
var directions = Maps.newDirectionFinder().setOrigin(start).setDestination(end)
.addWaypoint('Berlin')
.addWaypoint('Hamburg')
.getDirections();
but when I want do add some waypoints dynamicaly in loop like this:
var directions = Maps.newDirectionFinder().setOrigin(start).setDestination(end)
while (results.hasNext()) {
directions.addWaypoint('Berlin')
directions.addWaypoint('Hamm')
}
directions.getDirections();
finally the object directions hasn't any waypoints. What I'm doing wrong? There isn't possible to add waypoints in a loop?
I created a simple script (see bellow). It works correctly - the res contains 4 legs.
function testMapWayPoints() {
var directions = Maps.newDirectionFinder().setOrigin('Berlin').setDestination('Rotterdam');
var wayPoints = ['Potsdam', 'Hanover', 'Dortmund'];
for (var i = 0; i < wayPoints.length; i++) {
directions.addWaypoint(wayPoints[i]);
}
var res = directions.getDirections();
}
I assume that the results.hasNext() returns false. If not then, could you create a minimum compilable example/function which is possible to copy-and-paste to the editor and which reproduces the problem.
Update 00: Additionally I wrote a deployed web app demonstrating that the addWaypoint function works. Here is the app source code.
I have some google apps script code that adds Editors to a document with no problem. However, when I run the following code I find that some of the editors are removed, and some error with the following message: "Exception: We're sorry, a server error occurred. Please wait a bit and try again."
var file = DocsList.getFileById( fid );
var editors = file.getEditors();
for ( el = 0; el < editors.length ; el++ ) {
file.removeEditor( editors[ el ] );
}
Given that the editors are retrieved from the file itself, and then fail to be removed, I cannot see how to progress this, as the error message offers no help.
Has anyone experienced similar. I cannot see any issues raised against this.
Thanks in advance.
Chris
You could try to put your file.remove(editors[ el ]) in a try-catch structure to catch the error (and see it) and let your app finish in every case.
Example :
function myFunction() {
var file = DocsList.getFileById( '0AnqS........bW1DNnVBbVE' );
var editors = file.getEditors();
Logger.log(editors.join())
for ( el = 0; el < editors.length ; el++ ) {
try{
file.removeEditor( editors[ el ] );
Logger.log(editors[el]+' removed');// this editor is successfully removed
} catch(error)
{Logger.log('error on el = '+editors[el]+' = '+error)
}
}
}
This of course brings no answer on your issue but it could help to see what is happening in more details, which editor gets an error and which doesn't.
I have the same experience, both removeEditor and removeViewer can fail for some users, despite obtaining the user object from the getViewers or getEditors methods.
My observation is that unless the returned user object is a Google apps account holder then the remove action will fail.
So, on a google apps domain example.com a file might be shared with the following email addresses:
normal_account#example.com
group_account#example.com
third_party#some_other_example.com
removeEditor/removeViewer will only succeed for the first address on the list.
Although the call to getEditors/getViewers returns a list of user objects, some of the objects appear empty eg user.getEmail() returns a blank string, which is what the API documentation says will happen https://developers.google.com/apps-script/reference/drive/user#getEmail%28%29 if the email address is not available.
I am learning GAS and want to use spreadsheet functions within my script. As a test I did a simple case but on save it threw "reference Error: 'Left' is not defined." I've looked through examples of code and can't see an alternate syntax.
function testLeft(){
return LEFT("abcdef",3);
}
A second simple test, same result
function testNow(){
return Now()
}
Any suggestions? My wild guess is that there is a special syntax within scripts for using a built-in spreadsheet function. Or maybe not all functions available directly in spreadsheets are available for use in GAS?
Thanks.
Unfortunately spreadsheet functions are not available in Google Apps Script. In this case you can use JavaScript's substring() method to get the portion of the string you desire.
I am from a VBA background and I have found this site
http://excelramblings.blogspot.co.uk/2012/05/google-apps-script-equivalents-for.html
provided by Bruce Mcpherson very helpful lots of ready made functions for copying and pasting into your Google App Script especially if you are converting from an Excel spreadsheet to a Google spreadsheet.
Bruces Code for LEFT:
function Left(str,optLen) {
return Mid( str, 1 , optLen);
}
And to use the above LEFT function you will also need Bruces Mid function:
function Mid (str,optStart,optLen) {
var start = IsMissing (optStart) ? 0 : optStart - 1;
var length = IsMissing (optLen) ? Len(str) - start + 1 : optLen ;
DebugAssert( str.slice, str + ' is not a valid string for Mid function');
return str.slice ( start, start + length);
This is my attempt at simulating the mid Function
function fMid(varInStr, intPlace) {
//GAS does not have a Mid Function so I have made this one for now
//varInStr is the input string and you want a character returned from it at a given position
//intPlace is the position of the character you want
//Example
//=fMid("123456789", 9) returns "9"
var P
var N
P = intPlace -1
N = intPlace
return varInStr.substring(P,N)
};