Imported range time values dont match source range time values Google sheets script - google-apps-script

I have simple google spreadsheet with two sheets: sheet1 and sheet2. In sheet2 there are time values in column A which I am trying to copy to column A in sheet2. I wrote a script(please see link) for it but values are not the same. What class/method do I need to use in order to get same values in both sheets.
I noticed if I format column A values in sheet2 to text than I get matching values but problem is I am not allowed to that and that column must remain formatted as time.
Also, my second question(please ignore if its off topic). If I have work schedule in google sheet for 3 employees: John,Peter and Mike and they all have editing permissions. If Mike decides to use filter to filter out just his work schedule, is it possible for other two employees to have unedited sheet(as I believe Mike's actions will affect other two persons). What I mean is, is it possible to restrict one persons actions just to view he is looking at while other have unaffected version(together work schedule in this case)?
link for spreadsheet:
https://docs.google.com/spreadsheets/d/1tOtwzM0CxDHBXzC8ECeXlfaTGC4i7rH2XMYYszqRINM/edit?usp=sharing
Much appreciated.

not entirely sure what the problem is, your script is working as intended and you have the same values in sheet1 as in sheet2. The only difference is that in Sheet1 you have a date format and on sheet2 you only indicate the time. I have changed the number format in the sheet1 and as you can see it's the same.
The problem you are having is that by indicating only the time, you let the sheet assume any date. For time it's not that big a deal, but you must be sure that time formats are the same. use getNumberFormat() and setNumberFormat() (read here) to set the correct formats when copying or have the formatting set in advance
As for filtering — you can simply give them view-only access and let them use filtere views (right under "Filter"). A filter will hide information for everyone on the sheet, while a filter view will only be visible to that person. You can also pre-set filter views for them as those with edit access can save filter views.

Related

Can I create a List Generator based on specific Data Criteria

I have a workbook that contains a comprehensive list of Test Scenarios my developers are responsible for. In the workbook I would like to create a "generator" that will return a complete list of tests that need to be completed based on a specific criteria.
Criteria List. When a specific answer is selected on Sheet2 it correlates to a specific column on Sheet3, and I want to populate all rows associated with that answer AND remove duplicates onto Sheet1.
For example If B2 in Sheet2 is Yes, then I want to return all rows from Sheet3 where YES appears in Column D but if Sheet2!B2 is No, I want to return all rows where No appears in Sheet3!D.
I can successfully queue an individual line/criteria using ARRAYFORMULA(IF(TestCaseGenerator!B2="YES", IF(Disputes1!D:D="YES",Disputes1!A:M,""),""))
But I have tried several =ARRAYFORMULA, =IFS, =QUERY combinations and as I stack the criteria the formula breaks; I get one of two errors:
a parse erorr and as of yet cannot determine where exactly the formula is breaking down
Not enough arguments
I know a script may be a better option, but have not written many scripts and am unsure where to even start.

How do I lock a cell's copied value determined by a formula and prevent it from updating when the referenced cell in formula does?

the sheet I'm working on generates a request number on the very first submission a user makes of a google form based off of information the user inputted in the form and a timestamp. Now, because I need for the user to be able to edit their response later which causes the form to be re-submitted, I want the request number not to be regenerated, and to stay the same as when it was initially generated. Is there any way to prevent a cell from changing from its initial value when it contains a formula that references a cell that updates?
Here is the formula contained in the cell I don't want to update with alongside its references:
=ARRAYFORMULA(ARRAY_CONSTRAIN(if(ROW(A:A)=1, "Request ID", if(D1:D="", "",C1:C&"-"&G1:G&"-"&N1:N)), MAX(if(D1:D="",0,ROW(D1:D)))-ROW()+1,1))
The formula appends different values received from the form together to create a request number (formatted as essentially C1:C-G1:G-N1:N, timestamp-System-initials) and the arrayformula and constraint ensures the formula is copied to each row in the sheet that contains a form response so far. I want this request number to stay the same as it's initial value, even as columns C, G, and N change.
Edit: Not really sure how I can provide a search history on what I've tried so far because I've been searching for anything I can to fix this problem because it's important. I've looked into indirect referencing, absolute references, considered using PropertiesService (Google Apps Script) in order to store whether the request number has been initiated before and got stuck there, considered copying the value into another column to store it but again the autoupdating feature that accompanies linking cells of course still remains an issue. I'm stuck on what kind of function/workaround I could use to achieve this. Look forward to your thoughts. I've also tried a number of other strategies as well.
Since formulas recalculate each time the spreadsheet is recalculated using a formula is not the right way to keep the original value on the current spreadsheet version. The way to achieve this is by using a script to log those values.
There are already a lot of questions about using a script to log values from one sheet to another. Here are few examples
How to Get (& Set) cell values from one sheet to another in Google Sheets?
I want to write a script to read and log values of a specific row and copy them to a new sheet

get sheet data without the hidden columns

I am currently working on GAS project, for the moment I have a table in a sheet and the idea is that my collaborators will be able to choose the format of the table, which column and which row they want to save. I thought about using the hiding column and row features but is it possible in my apps script to get only the data which they chose to save and not the hidden data ? Thank you for you answers
Apps Script works analogously to the Sheets UI
Explanation
If from the user interface you select the desired data by "click&drag", the hidden columns located between the start and the end column will be also selected (and copied). Instead you need to select the data of interest manually with "Ctrl" and click, see here.
How to transfer this to Apps Script?
Apps Script features the method sheet.isColumnHiddenByUser(columnPosition) (and isRowHiddenByUser, isRowHiddenByFilter etc.). You can use it to select only the ranges / the values of a datarange in columns and rows that are not hidden.
This implies the implementation of loops and conditions statements, so is not necessary an elegant solution.

How to disable editing of cells after midnight in googlesheet?

I have a google spreadsheet which we use to feed inventory purchase and issue data. The only problem is my staff can manipulate purchased quantity, prices and other variables at a later date. I want that if they enter data in a cell, they cannot edit it post-midnight but I can.
Also, I have filled most of the cells with formula, for example- there is formula in A1:H999, so that when they enter data, it calculates the values in other cells, and suppose my staff has entered data till A1:H500. In this case, the script should work On A1:H500, it should not consider the whole range just because i have filled it with formula. Thanks
If you want to limit access to the script to particular hours it's fairly simple. This can be done with one function if written in a clever way or with 2 functions.
Function1 will simply lock the spreadsheet and allow only you to edit by using the protection class, then use function2 (or write function1 in a clever way to do different things depending on when it starts) that is triggered at a different time to remove that protection.

How to process all named ranges in a Google Sheet?

Is there a way to process all of the Named Ranges in a Google Sheet?
Google Documents has .getNamedRanges(), but I can't find anything similar for sheets. I want to read and print each range parameter.
My end goal is to fix a lot of named ranges en masse. There are more than 200 in the document in question.
There's a bug in sheets (Documented here) and since default ranges in Named Ranges have the entire span of merged cells (ie: A1:J1), but named ranges only work in formulas if you specify JUST the first cell, I thought I could save a lot of time by just accepting the default named range (A1:J1 as an example) and then script it so I can just strip everything off of the end, leaving just A1. In order to do this, I need to simply be able to get a list of all named ranges in the sheet.
Is this possible?
The answer is now, at least, Yes. There remain some frustrating limitations with programmatic handling of named ranges, but the situation is much improved.
The same .getNamedRanges() method cited in the question works when applied to either a Sheet (only the named ranges referencing a range in the sheet) or Spreadsheet (all named ranges in the spreadsheet) object. It returns an array of all Named Ranges.
You cannot access a Named Range directly by name in GAS. A rather maddening oversight requiring iterating through an entire array of named ranges to get to the one needed.
In the end, however, there really isn't much you can't do with them. As several other questions on SO highlight, it's rarely if ever a good idea to programmatically delete a named range. Even though it would be a lot easier to delete one and then re-add it sometimes, that will break every reference in your sheet to the named range (unless they use the awkward indirect("named_range_name") construct).
Short answer is no, unfortunately.
there is an enhancement request at:
https://code.google.com/p/google-apps-script-issues/issues/detail?id=917
you can star to vote for it and receive updates.