GAS: Alternative to using ScriptProperties.getProperty which is needed to retrieve events by ID - google-apps-script

I am learning GAS. The app script on the Quickstart: Managing Responses for Google Forms uses the depecrated Class&method:ScriptProperties.getProperty(key) ie.ScriptProperties.getProperty('calId'). I have reported this as an issue to Google. Is there a better way to code this example and achieve similar results?
// Store the ID for the Calendar, which is needed to retrieve events by ID.
ScriptProperties.setProperty('calId', cal.getId());

You'll want to use Properties.setProperty(key, value) instead of ScriptProperties.setProperty(key, value) The reason is because The "Properties Service" has now replaced Google's ScriptProperties class. Here's my source: https://developers.google.com/apps-script/guides/properties

The other answer is almost right..., it just uses a shortcut from the documentation without defining the shortcut itself.
The syntax is as follows
PropertiesService.getScriptProperties().setProperty(key, value)
And all the similar methods as described in the documentation. (getProperty,setProperties , etc...)
The usage is the same, you can use find/replace in your script to simply update every occurrences .

Related

Chainlink Request Event Emit - Unsure whether events are being emitted, requests seem to be sucessful

I am trying to learn how to use the ChainlinkClient and I am using their example as well as one for the API that I am trying to uses.
You can see them here on this Gist.
The two contracts in the Gist are deployed on Rinkenby here:
APIConsumner.sol
APIConsumner2.sol
When I call the requestData() method on both contracts they seems to work, the transactions goes through and Link gets taken from the contracts, I am however unable to determine whether the actual data I am requesting from the external APIs gets returned, either by looking in the transaction event or trying to access the value that I am setting.
I am a bit bamboozled at this point, any guidance or suggestions would be greatly appreciated.
Thanks for the flag. The node that was hosting this is deprecated, the article has been updated, and the docs have the latest example.
Please use:
oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8;
jobId = "d5270d1c311941d0b08bead21fea7747";

Mediawiki parser function/extension to check if a user exists?

Is there a Mediawiki extension or built-in wikitext function that checks if an account with a given name exists?
I'm looking for something like:
{{#ifuserexists: username|wikitext if account exists with that username|wikitext otherwise}}
There doesn't appear to be anything easy to find in that regard (search "mediawiki parser function if user exist" and "mediawiki check if user exists" on Google or Bing for example of how search engines utterly fail to find a relevant extension)
RightFunctions can probably do that.
Found something that works.
Contribution Scores provides a parser function {{#cscore: username}} that produces an activity score if the user in question exists and "Invalid username" if the user doesn't exist.
https://www.mediawiki.org/wiki/Extension:Contribution_Scores
Just a warning: #cscore produces a malformed/corrupted string object that is thoroughly incompatible with standard string processing parser functions (including #ifeq, #sub, #replace), so you can't make a template that implements conditionals based on this. All efforts to parse the output produced unexpected/wrong results or UNIQ-QINUs.
If you merely need to view the created/uncreated status of user accounts via a manually configured dashboard, #cscore is sufficient. However, it doesn't work for any programmatic or automated mechanism in wikitext except if you use a nonstandard or deep wikitext manipulation extension where the standard StringFunctions, ParserFunctions, and RegexFunctions fall flat.

Autocomplete Not Working - Google App Script

I'm having trouble with the autocomplete feature in Google App Script.
Built-in methods like SpreadsheetApp. will provide an autocomplete menu with methods to choose from.
However, if I create my own child object, autocomplete works for a little while, and then it just stops working.
for example:
var skywardRoster = SpreadsheetApp.getActiveSheet();
skywardRoster. will produce method options for a while, and then it stops.
However, the code still functions, and methods work if I type them out manually, so I know the declarations must be right. The menu simply won't appear, and it's just very inconvenient to have to look up each method individually as I go.
I have tried: breaking the variable and retyping that line; copy and pasting the code back into the editor; using different browsers; copying the gs file itself and working within the copy; and signing out completely and signing back in. Nothing seems to get it back to work.
I'm really new to coding, and I'm not sure what can be causing this.
Does anyone know how to fix this issue?
You might want to check Built-in Google Services:Using autocomplete:
The script editor provides a "content assist" feature, more commonly called "autocomplete," which reveals the global objects as well as methods and enums that are valid in the script's current context. To show autocomplete suggestions, select the menu item Edit > Content assist or press Ctrl+Space. Autocomplete suggestions also appear automatically whenever you type a period after a global object, enum, or method call that returns an Apps Script class. For example:
If you click on a blank line in the script editor and activate autocomplete, you will see a list of the global objects.
If you type the full name of a global object or select one from autocomplete, then type . (a period), you will see all methods and enums for that class.
If you type a few characters and activate autocomplete, you will see all valid suggestions that begin with those characters.
Since this was the first result on google for a non-working google script autocompletion, I will post my solution here as it maybe helps someone in the future.
The autocompletion stopped working for me when I assigned a value to a variable for a second time.
Example:
var cell = tableRow.appendTableCell();
...
cell = tableRow.appendTableCell();
So maybe create a new variable for the second assignment just during the implementation so that autocompletion works correctly. When you are done with the implementation you can replace it with the original variable.
Example:
var cell = tableRow.appendTableCell();
...
var replaceMeCell = tableRow.appendTableCell(); // new variable during the implementation
And when the implementation is done:
var cell = tableRow.appendTableCell();
...
cell = tableRow.appendTableCell(); // replace the newly created variable with the original one when you are done
Hope this helps!
I was looking for a way how to improve Google Apps Script development experience. Sometimes autocomplete misses context. For example for Google Spreadsheet trigger event parameters. I solved the problem by using clasp and #ts-check.
clasp allows to edit sources in VS Code on local machine. It can pull and push Google Apps Script code. Here is an article how to try it.
When you move to VS Code and setup environment you can add //#ts-check in the beginning of the JavaScript file to help autocomplete with the special instructions. Here is the instructions set.
My trigger example looks like this (notice autocompletion works only in VS Code, Google Apps Script cloud editor doesn't understand #ts-check instruction):
//#ts-check
/**
* #param {GoogleAppsScript.Events.SheetsOnEdit} e
*/
function onEditTrigger(e) {
var spreadsheet = e.source;
var activeSheet = spreadsheet.getActiveSheet();
Logger.log(e.value);
}
I agree, Google Script's autocomplete feature is pretty poor comparing with most of other implementations. However the lack is uderstandable in most cases and sometimes the function can be preserved.
Loosing context
The autocomplete is limited to Google objects (Spreasheets, Files, etc.). When working with them you get autocomplete hints, unless you pass such object instance to function as an argument. The context is lost then and the editor will not give you suggestions inside the called function. That is because js doesn't have type control.
You can pass an id into the function instead of the object (not File instance but fileId) and get the instance inside of the function but in most cases such operation will slow the script.
Better solution by Cameron Roberts
Cameron Roberts came with something what could be Goole's intence or a kind of hack, don't know. At the beginning of a function assign an proper object instance to parameter wariable and comment it to block:
function logFileChange(sheet, fileId){
/*
sheet = SpreadsheetApp.getActiveSheet();
*/
sheet.appendRow([fileId]); // auto completion works here
}
Auto completion preserved

How do I retrieve messages within a bundle with a Google App Script?

I'd like to retrieve messages in GMail/Inbox with a Google App Scripts. I'm able to retrieve labelled in a certain way with label.getThreads(). Now I'm moving away from labels and starting leveraging bundles: is there a way to get messages by bundle?
I don't know if GMail/Inbox uses a special label when bundling, in that case how do I get the names of these special labels?
GmailApp class doesn't contain anything helpful as far as I can understand.
Bundles like you pointed out are just special labels.
For example you can do a search:
var updatesLabelThreads = GmailApp.search("label:Updates");
This would return all the threads under the Updates bundle. In your reply to the original post you said 'promos' didn't work, but if you use 'Promotions' it will. search() will not match partial string.

Chrome Console: VM

When executing a script directly in the console in Chrome, I saw this:
Does anyone know what's the meaning of VM117:2
What does VM stand for ?
It is abbreviation of the phrase Virtual Machine.
In the Chrome JavaScript engine (called V8) each script has its own script ID.
Sometimes V8 has no information about the file name of a script, for example in the case of an eval. So devtools uses the text "VM" concatenated with the script ID as a title for these scripts.
Some sites may fetch many pieces of JavaScript code via XHR and eval it. If a developer wants to see the actual script name for these scripts she can use sourceURL. DevTools parses and uses it for titles, mapping etc.
Thanks to #MRB,
I revisited this problem, and found the solution today,
thanks to https://stackoverflow.com/a/63221101/1818089
queueMicrotask (console.log.bind (console, "Look! No source file info..."));
It will group similar elements, so make sure you add a unique identifier to each log line to be able to see all data.
Demonstrated in the following example.
Instead of
data = ["Apple","Mango","Grapes"];
for(i=0;i<10;i++){
queueMicrotask (console.log.bind (console, " info..."+i));
}
use
data = ["Apple","Mango","Grapes"];
for(i=0;i<data.length;i++){
queueMicrotask (console.log.bind (console, " info..."+i));
}
A better way would be to make a console.print function that does so and call it instead of console.log as pointed out in https://stackoverflow.com/a/64444083/1818089
// console.print: console.log without filename/line number
console.print = function (...args) {
queueMicrotask (console.log.bind (console, ...args));
}
Beware of the grouping problem mentioned above.