Google Sheet - OnEdit TimeStamp on separate Sheets not working - google-sheets

I was running Google Sheets with only 1 Sheet and this script (updating timestamp onEdit)
function onEdit(e) {
if (!e.value) return;
e.source.getActivesheet()
.getRange('G50')
.setValue(new Date());
}
but as soon as I added 2 additional sheets, it stopped working. I dont get it, because I thought, this script will now run on either of these sheets as soon as I edit on. (but it does nothing)
What am I not thinking about? Thanks for help in advance.

How about a change as follows?
From :
e.source.getActivesheet()
To :
e.source.getActiveSheet()
In the case of onEdit(), even when an error occurs, the error doesn't display. So if you want to know whether the error occurs, please confirm "View > Execution Transcript" on Script Editor after onEdit() was launched. You can see the running process of onEdit() in the Execution Transcript.

Related

This document requires 'TrustedScriptURL' assignment in Google Sheets

I have a Google Spreadsheet where I have the following information on specific cells in the sheet:
Cell B1: Has the URL http://www.google.com.co/search?q=NASA+watching+now%3A+site%3Awww.youtube.com
Cell B2: has the following formula: =IMPORTXML(B1,"//title")
Here is the link of the Google spreadsheet - if you want to test from your side.
And here is the Google Spreadsheet I'm working on - which, I want to get the specific data:
Title: Text (in the h3 HTML tag of the result item).
Url: Link (in the <a> HTML tag of the result item)
Description: Text next to the thumbnail of the result item.
See screenshot with the data to get using IMPORTXML:
The previous code returns the title of the given URL - in this case, the URL stored in the B1 cell.
It was working without problems (since 12/02/2022 - dd/MM/yyyy) until today (13/02/2022 - dd/mm/yyyy).
I checked the Chrome console "F12 Developer tools" and I get this error:
This document requires 'TrustedScript' assignment.
injectIntoContentWindow # VM364:27
By clicking the # VM364:27 line, the following code is shown:
function injectIntoContentWindow(contentWindow)
{
if (contentWindow && !injectedFramesHas(contentWindow))
{
injectedFramesAdd(contentWindow);
try
{
contentWindow[eventName] = checkRequest;
contentWindow.eval( /* ERROR with and (X) is shown here. */
"(" + injectedToString() + ")('" + eventName + "', true);"
);
delete contentWindow[eventName];
}
catch (e) {}
}
}
Searching on the internet, I barely could get the causes of this error:
Google Chrome update - making security stricter.
Chrome extensions - try to disable such extensions and try again.
CPS (Content-Security-Policy) - must be honest = I don't understand this point; it's from the website to scrape the data OR from Google Sheets the CPS is the root cause?
The solutions given to this problem are in Python - with the use of DOMPurify - as is described in this answer, but, I don't know and neither have found any clues about this problem and its solution in Google Spreadsheets.
I've tried:
Recover previous working Google Spreadsheet version - the result is that the formula re-evaluates and no result is returned; looking in Console, the This document requires 'TrustedScriptURL' assignment message shows.
Disable Google Chrome installed extensions - I only have AdBlock (this code was working without issues), anyway, I turned off, reload the spreadsheet and the error mentioned above raises in Console.
Using another page - I tried with Wikipedia and Wiki.fandom and it works - i.e. data is returned. Probably in this case, Google injected in their searcher an script for avoid injection? - I'm really not sure, only speculating/rambling here.
Another possible cause I consider is maybe my IP was blacklisted or blocked, but, I'm not sure.
My browser information:
Chrome version: 98.0.4758.82 (Build oficial) (64 bits) (cohort: Stable)
Windows 10 Version 21H2 (Build 19044.1466)
Is there any way to solve this error in Google Sheets?
PS: I'm interested in know the workaround using google sheets and/or custom scripts - via script editor/Apps Script. The use of IMPORTXML function is not mandatory - I find curious that it was working and then today, not anymore.
I will just leave this here:
=INDEX(UNIQUE(REGEXREPLACE(QUERY(IMPORTXML(A1, "//a/#href"),
"where Col1 contains 'youtube.com/'"), "\/url\?q=|&sa=.*", )))
=IMPORTXML(A1, "//title")
=IMPORTXML(A1, "//h3")
TL;DR: This document requires 'TrustedScript' assignment error is not the root cause of the delay of the IMPORTXML function - probably there is other cause(s) (outside of the developer's handling), but, after all, the code works - see working google spreadsheet - just, wait until the results are shown or use another way to web-scrapping the desired data.
Since the This document requires 'TrustedScript' assignment message stays appearing in the Console of the browser, but, the code I posted on my question (and the code posted by SO user player0 in their answer) works, it seems to me that the delay of the response using IMPORTXML might be due its buggy functionality and/or some restriction Google detected by doing multiple requests.
So, here are my tips about this:
Check very closely how the page where the data will be extracted from and its structured before doing excessive requests - or you might face a significant delay in the response of the IMPORTXML function - as I experienced it.
Get more familiar with XPath and check if the data is dynamically generated in the page - this makes even harder to get the desired data using this way of scrapping.
This is the spreadsheet with the desired results - if anyone is interesed1.
1 Check the "Results-mix" sheet (which contains both the code I manage to create and the code provided by player0 in their answer).
If you really want to get similar results in a less convoluted way, consider use another strategy for web-scrapping or use official APIs - when available.

Neo4j fails to start up due to trigger execution failure

I have a triggered called create-owner-notification. It worked like a charm after creating it, but after a restart of Neo4j it blocks a successful start up of the database. The error found in debug.log is:
[a.t.Trigger] Error executing trigger create-owner-notification in phase before Unknown function 'apoc.create.uuid' (line 5, column 83 (offset: 193))
"MERGE (o)<-[:RELATES_TO]-(n:Notification:OwnerNotification{date_created: dt, uid: apoc.create.uuid()})<-[:HAS_NOTIFICATION{read: false, date_received: dt}]-(u)"
at org.neo4j.kernel.impl.query.QueryExecutionKernelException.asUserException(QueryExecutionKernelException.java:35)
[..]
As can be seen it doesn't recognise the function apoc.create.uuid.
My first idea was to simply remove the apoc.create.uuid dependency and instead call the native randomUUID() function instead. However, there is no way I can modify or remove the current trigger, for the database cannot start. If I set the config value apoc_trigger_enabled to false the database does start successfully but I cannot interact with the trigger in order to remove it.
If need be I can share further logging or config files.
How can I get the database to startup and successfully get the trigger to work again?

Trying to refresh import XML xpath query, jquery string changes URL and breaks the request

I have successfully used importxml to pull down data from live NBA games on espn.com. However, I need the importxml function to refresh every minute (or some frequent amount of time) to keep fetching the live data and have it update in my google sheets.
I found this script online to refresh the import xml but it adds a jquery string to the end of the URL for cache busting. The jquery string at the end of the URL changes the URL from being in a specific game like this:
https://www.espn.com/nba/game?gameId=401161051
(which would successfully fetch the data) back to just the NBA scoreboard:
https://www.espn.com/nba/game?gameId=401161051.1234232
I need the import xml function to successfully refresh while cache busting, without adding a random number to the end of the URL because espn sends you to a different page if that happens.
This is my import XML function that works successfully
=IMPORTXML("https://www.espn.com/nba/matchup?gameId=401161049","//tr[20]")
Assuming your import formula is in cell A2 you will make the following modification:
=IMPORTXML("your link&"&A1,"your xpath")
Then in cell A1 do
=today()^0+A1
Don't forget to enable these settings:
Congrats it updates every minute and edit.
Answer:
You can use an Apps Script time-based trigger to go off every minute and update the cell in question.
More Information:
From the Tools > Script editor menu item, you can create a function with the following code:
function updateTheSheet() {
var formula = '=IMPORTXML("https://www.espn.com/nba/matchup?gameId=401161049","//tr[20]")'
ss = SpreadsheetApp.getActiveSpreadsheet()
ss.getSheets()[0].getRange('A2').setFormula(formula);
}
Assuming that the cell you wish to have update is in the first sheet, in cell A2. You can change this in the getRange() function.
From here, save the script with the save icon, press the run button (►), and confirm the authentication of running the script.
From here, following the Edit > Current project's triggers menu item, you will have a new page open in the G Suite Developer Hub. Click the + Add Trigger button in the bottom right and set up the trigger settings as follows:
Choose which function to run: updateTheSheet
Choose which deployment should run: Head
Select event source: Time-driven
Select type of time based trigger: Minutes timer
Select minute interval: Every minute
And press save. Now, the function will run each minute and update that cell with the formula, causing the formula to recalculate and update itself.
References:
Google Apps Script - setForumla()
Installable Triggers

Cypress Time out not respecting the value given on command

Since our test agents are slow some times- i am trying to add some additional time outs for some commands
I did it like using time out value on command as shown below.But its not respecting the value given
My understanding is cypress will wait for "10000" MS for getting the #Addstory element?
Can any one advice is this is the correct way please?
Thank you so much
cy.get('#addstory > .ng-scope').click({ timeout: 10000 })
In cypress.json file, increase the timeout to 10 seconds or what ever timeout you want like this: "defaultCommandTimeout": 10000 and save the file. Now close the app and open it again. Navigate to Settings > Configuration you should be able to see the new value set for defaultCommandTimeout.
I issue was i was adding time out on click not for getting the element when i changed like below -All good waiting for add story to be visible as i expected before click
cy.get('#addstory > .ng-scope',{ timeout: 10000 }).click()

QtLua capture slider value change

I am trying to make a simple UI using qtlua, in which I want to capture the slider value everytime it changes. I tried to connect to the valueChanged() signal, but qlua gives me the following error:
cannot find source signal valueChanged()
The code snippet looks like this:
slide = (widget.sliderLight)
print(slide)
qt.connect(slide, 'valueChanged()',
function()
print('Value: ', slide.value)
end)
So just a test to print everytime the value changes. But I cannot get it working. The documentation for the qtlua doesn't have a class for qslider, so that's a dead end for me. And I couldn't find any examples for using qtlua with a slider that is connected to the valueChanged() signal. The only example I found was with the test.lua in the qtuiloader example, but that uses a timer, which I assume is pooled at regular interval. My aim is to hook this up to an image processing system, so it would be useful if I could tie it to when the value changes, rather than patch in with a timer and a check system. I am pretty new to qt, so must be missing something. Any and all help would be really appreciated!
Oh and I made sure I have tracking checkbox checked in the qtdesigner, to ensure that the signal is emitted.
Okay, so I dug around a little more in the documentation of QT for the valueChanged() slot. Turns out, the function signature has an int argument in it, so the Lua connect code was looking for a function signature without any arguments. Modifying the above code to the following works as expected:
slide = (widget.sliderLight)
print(slide)
qt.connect(slide, 'valueChanged(int)',
function(w)
print('Value: ', w)
end)
Declaring a function with the same signature also passes in the required value, which saves me an explicit value query.
Hopefully, this will be useful for someone someday.

Resources