I try to run the script when range has changed and meets a specific value. value comes by using vlookup with arrayformula.
Script work only when specifically i activate the cell by entering the value.
I want this automatically range copy when meet a certain value without clicking on it.
I already try onEdit and onchange triggers it's not working. please help me if there is any way to automate the scrip
Value=Done
column=54
enter image description here
var ss=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DRW");
var active=ss.getActiveCell();var row=active.getRow();var col=active.getColumn();
var val=active.getValue();var source=ss.getRange("B"+row+":P"+row).getValues();
var destination=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("BOM");
var last=destination.getRange("A1:A").getValues().filter(String).length+1
if(col==30 && val=="Done")
{
destination.getRange("B"+last+":P"+last).setValues(source);
destination.getRange("A"+last+":A"+last).setValue(new Date());Browser.msgBox("Data Sent To BOM")
ss.getRange('AE1:AF1').activate();
ss.getActiveRangeList().clear({ contentsOnly: false, skipFilteredRows: false });}
Related
CURRENT SITUATION
As an owner I've created a spreadsheet that makes an editor of everyone who has received the link. However there are some partially protected sheets with a few unprotected columns, making it possible for these editors to change values. I have an onEdit function that automatically sorts the entire range of a sheet when a cell has been edited by user.
PROBLEM
Unfortunately, since these sheets are partially protected, the AUTOSORT does not work. I need to add something to the script so that when the onEdit is triggered, the activesheet becomes unprotected and the AUTOSORT can do its job. After that the protection is added again (with a few columns as an exception). I don't want everyone to lose their editors rights after this. So it needs to go back to normal.
Script that I tried so far but not working:
function onEdit() {
if (e.range.columnStart == 3 && e.range.getValue() != '') {
var sheets = ["FASHION NL", "FASHION BE","KIDS & UNDERWEAR BNL" ,"NEW BUSINESS BNL" ,"SPORTS & SHOES BNL", "HD&E BNL"]; // Please set your expected sheet names.
var sheet = e.range.getSheet();
if (sheets.includes(sheet.getSheetName())) {
var range = sheet.getRange("A5:bY600");
var spreadsheet = SpreadsheetApp.getActive();
var allProtections =
spreadsheet.getActiveSheet().getProtections(SpreadsheetApp.ProtectionType.SHEET);
var protection = allProtections[0];
protection.remove();
range.sort({ column: 11, ascending: true });
e.source.toast('Sort complete.');
}
}
var protection = spreadsheet.getActiveSheet().protect();
protection.setUnprotectedRanges([spreadsheet.getRange('AK:AK'),
spreadsheet.getRange('BN:BN')])
var editors = SpreadSheet.getEditors();
for (var i = 0; i < editors.length; i++) {
SpreadSheet.removeEditor(editors[i])
}
}
CLARIFICATION PROBLEM
It does not give me an error, but script fails to sort the data range.
SAMPLE SHEET STRUCTURE
Trigger is on column C (3)
Script is created in a way that it reflects whether the Activesheet where the edit takes place is one of the predetermined range of sheets.
You should keep all your permissions as they're and set the function as if it's run by yourself (delete all the parts that have to do with removing and adding permissions). Call it other way than onEdit, for example autoSort(), and set an installable trigger run by event. You can read about it here
The sorting then would be run as it was done by you but triggered by other users' changes. Give it a try and let me know!
I am doing a dependant dropdown list in google sheets using a script.
The source sheet data is read into an array, The destination sheet pulls the dropdown options from the aray.
The numbers from the source sheet are formatted as degrees; 0°, 45°, 90°, 180°.
When the are displayed in the dropdown on the destination sheet the degree symbol is removed and the 0 option doesn't show as an option at all. so I get 45, 90, 180. If I format the destination cell as percent, the the chosen option doesn't match the validation. and I still can't get the 0°.
How can I pass the formatting with the numbers so everything works correctly?
I was thinking I need to do something with setNumberFormat('##0"°"'), but I don't know how.
This is how I am creating the data from the array:
var ws = SpreadsheetApp.getActiveSpreadsheet() .getSheetByName(mainWsName) ;
var wsOptions = SpreadsheetApp.getActiveSpreadsheet() .getSheetByName(optionsWsName) ;
var options = wsOptions.getRange(3, 2,wsOptions.getLastRow()-2, 5).getValues();
var optionsFormat = wsOptions.getRange(3, 2,wsOptions.getLastRow()-2, 5).getNumberFormat()
This is how the data is being retrieved from the array:
var filteredOptions = options.filter(function(o){ return o[0] === firstLevelColValue && o[1] === val });
var listToApply = filteredOptions.map(function(o){ return o[2] });
var cell = ws.getRange(r, thirdLevelColumn) ;
applyValidationToCell(listToApply,cell);
This is my first time asking a question here, I hope I have given the information necessary to solve my problem. Let me know if there is additional information needed.
Thanks
Use getDisplayValues() instead of getValues()
This will allows you to retrieve the values in exactly the same way as they are displayed in the spreadsheet.
I need a simple script for Google Sheets to allow only one of 6 checkboxes to be checked at a time. The end user will check a checkbox and should see the one they checked before turn unchecked or FALSE when they check the new one. The "problem" for a newbie like is me that the checkboxes will be asymmetrically located. They are in cells D14, D30, J14, J32, P14 and P30. I also need to duplicate this sheet a number of times, so preferably the script should work on any of the duplicates I make the same way. The cells will always be these six cells in every sheet.
I've seen many posts about this subject and tried to use the example scripts to my problem without success, so I want to ask specifically about my spreadsheet.
Here is a link to a draft version of my sheet with the locations of the checkboxes:
https://docs.google.com/spreadsheets/d/1PtxetS-Gyv7LyMD19yF3NuWZ24RvqUjyK42SmQTttiU/edit?usp=sharing
Thank you,
Lassi
You can set up an onEdit() trigger that will:
Check whether the cell edited is a checkbox (by verifying its range).
Check that the new value for the cell is TRUE (the checkbox has been enabled).
In case both of 1 and 2 apply, unset the rest of the defined checkboxes in the same sheet.
Note that the execution of the script may be a bit slow (due to Google Apps Script limitations) and that the script will work independently for each of the Sheets in your workbook.
Code
var CHECKBOX_CELLS = ["D14", "J14", "P14", "D30", "J32", "P30"];
function onEdit(e) {
var range = e.range;
var checkboxIndex = CHECKBOX_CELLS.indexOf(range.getA1Notation());
if (checkboxIndex > -1 && range.getValue() == true) {
var sheet = range.getSheet();
for (var i=0; i<CHECKBOX_CELLS.length; i++) {
if (i==checkboxIndex) continue;
sheet.getRange(CHECKBOX_CELLS[i]).setValue(false);
}
}
}
I'm looking for a way to change the value (or format) for an individual series label when hovering it in anycharts.
Currently I'm only able to access the entire axis and I can find no getter method for individual labels so as to attach a listener.
xAxis.labels().listen('mouseOver', function(e) {
console.log(this, e.target);
});
This jsfiddle is as far as I got (see console log), this as well as the event.target reference the entire axis but not the label:
https://jsfiddle.net/robstarbuck/pbhd4b7L/9/
Indeed, there was a little bug with cache and format() function, our dev team made the fix, so please check the working sample:
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
var value = xAxis.scale().ticks().get()[labelIndex];
label.format(value * 2);
https://jsfiddle.net/pbhd4b7L/13/ – it also shows how to work with tick values:
Currently it takes the js from branch, but this fix will be included in the upcoming release – 7.14.0 version (ETA: May 2017)
Our API is a little bit complicated here, but we're working hard to improve it. Does this what you're looking for?
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
label.fontColor('red');
label.draw();
https://jsfiddle.net/pbhd4b7L/10/
This issue was fixed in the 7.14.0 release, use this code:
xAxis.labels().listen('mouseOver', function(e) {
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
var value = xAxis.scale().ticks().get()[labelIndex];
label.format(value * 2);
label.fontColor('red');
label.draw();
});
with the latest version: https://jsfiddle.net/2t08ahkg/3/
I have a test that checks the value an HTML5 range input.
return this.remote
// etc.
.findById('range')
.getAttribute("value")
.then(function(val){
expect(parseInt(val)).to.equal(2);
});
The value is correct when I check its initial value, but if I change the value then check, it has not been updated. I found that the value doesn't update in the developer tools either. I tried using
.sleep(3000)
between changing the value and calling
.getAttribute('value')
but that didnt' seem to be the issue.
In this JSfiddle, inspecting the range element with your browser's developer tools will show the title change, but the value does not (even though the value is correctly changed in the textbox). So this may be an issue with the webdriver, but I'd like to know if anyone has run into this issue.
Is this related to the test's failure to get the updated value? Is there another method I can use to read values(attributes)?
Edit:
It seems like the browser's onchange/oninput event is not triggering properly (similar problems: WebDriver: Change event not firing and Why does the jquery change event not trigger when I set the value of a select using val()?), and the webdriver is possibly not able to, either. Do I have to add Jquery as a define for my test, even though I only need to use trigger() ? Or is there another solution?
Edit2: I've added a better example of how I'm using the range input in this new JSfiddle. I added plus/minus buttons, which fail to trigger the change event that should update the value attribute of the range input, (and which fails to enter the value into the textbox).
You could fire the change event manually in your test. I was able to get the 'textValue' input in your JSFiddle to update that way and I imagine it might work similarly in your test.
rangeBar = document.querySelector('#range');
function myFire(element, eventType) {
var myEvent = document.createEvent('UIEvent');
myEvent.initEvent(
eventType, // event type
true, // can bubble?
true // cancelable?
);
element.dispatchEvent(myEvent);
}
myFire(rangeBar, 'change');
This comes up often enough that I have a helper in my base test class (Java)
public enum SeleniumEvent
{blur,change,mousedown,mouseup,click,reset,select,submit,abort,error,load,mouseout,mouseover,unload,keyup,focus}
public void fireEvent(WebElement el, SeleniumEvent event)
{
((JavascriptExecutor) getDriver()).executeScript(""+
"var element = arguments[0];" +
"var eventType = arguments[1];" +
"var myEvent = document.createEvent('UIEvent');\n" +
"myEvent.initEvent(\n" +
" eventType, // event type\n" +
" true, // can bubble?\n" +
" true // cancelable?\n" +
");\n" +
"element.dispatchEvent(myEvent);", el, event.toString());
}
Another thought. getAttribute("value") might not be getting what you think it does. In JavaScript, document.querySelector('#range').getAttribute('value') always returns the hard-coded value attribute (i.e. the default or initial value), not the input's current value.
document.querySelector('#range').value returns the current value.