I have the below script with the purpose of retrieving the value in the google sheet which will either state TRUE or FALSE. If it states false I want this script to run the two functions below (updateWIPdata and updateDebtorsdata) but if the cell value is true I don't want those functions to run at all but the functions seem to run regardless of the value in the cell so any help would be much appreciated
function updateAll() {
var updateStatus = SpreadsheetApp.getActive().getSheetByName('Updated').getRange('C2').getValue();
Logger.log(updateStatus);
if (updateStatus = 'false') {
updateWIPdata();
updateDebtorsdata();
}
}
Probably the value is a boolean.
Also, please use == or ===
if (updateStatus == false) {
Reference:
Equality operators
The fix is simple
But you also want to improve a few things in your code
The main problem is in this line:
if (updateStatus = 'false')
You are not comparing updateStatus to false, you are assigning 'false' to updateStatus. On top of that you are assigning a string, not a boolean. The line needs to be
if (false === updateStatus)
Notice three things:
false is a boolean here, it doesn't have quotation marks around it
It's on the left side of the comparison; putting litteral values on the left side is a habbit that prevents this type of error
I'm using the === comparison operator instead of the = assignment operator
Another thing you need to do is forget about var and start using const and let. If your updateStatus was a const, you would have very quickly realized the error.
Related
I have kinda a wierd question. I'm working on removing redundance from my code, and I have two functions which are basically the same, except one of the functions have two parameters and the other one only have one.
I'm wondering if it's possible to "skip" one of the parameters when the function is called, in order to reduce redundance? The functions in this case is in VueJS. Here are the functions:
addTask: function (task, member) {
if (task === '' || member === '') {
alert ('Enter Task & Member!')
}
},
addMember: function (addTeamMember) {
if (addTeamMember === '') {
alert ('Enter Name Of Team Member')
}
So in other words, is it possible to call "addTask" and only parse one argument and skip the other?
You can do it by declaring the variable directly as you can do it in many other languages.
For example:
function addTask(task, member = "") {
}
Notice: I have made a few changes to the original question as my problem was not with commas within string.
I have a function I've been working on to exclude a cell value from a new array that contains a string I am searching for. I am doing this in order to put together a list for .setHiddenValues, since .setVisibleValues is not supported/implemented yet.
Here are my requirements for the sake of clarity:
Currently working:
Able to handle numbers as well as strings
Can search for lowercase and uppercase. visibleValueStr is user inputted so it can't be so sensitive.
colValueArr may have strings with commas within.
Still working on:
visibleValueStr can be a single value or array.
Case sensitivity("apple" to match "Apple")
Not exact matches("apple" to match "apple and banana")
Here is the function I currently have with the above met/unmet conditions:
function getHiddenValueArray(colValueArr,visibleValueArr){
var flatUniqArr = colValueArr.map(function(e){return e[0].toString();})
.filter(function(e,i,a){
return (a.indexOf(e.toString())==i && visibleValueArr.indexOf(e.toString()) == -1);
})
return flatUniqArr;
}
Please let me know what other info I need. I will update this question as I continue to do my research in the meanwhile.
Clarification from comments:
User inputs input(s) on HTML form and the variable is passed on as visibleValueArr.
When using Logger.log(visibleValueArr).
[apple, banana]
When using Logger.log(colValueArr).
[[Apple],[apple][apple][apple and banana],[apple],[banana, and apple],
[apple, and banana],[orange],[orange, and banana],[kiwi],[kiwi, and orange],
[strawberry]]
So when I use:
SpreadsheetApp.newFilterCriteria().setHiddenValues(newArray).build();
newArray should be the hidden values. In this case it should be:
orange
kiwi
kiwi, and orange
strawberry
Basically anything that does not contain what visibleValueArr is.
Instead, it returns all values back, hiding them all.
When I use [Apple, Banana] the "Apple" and "Banana" values are left out of newArray as they should be, but "Apple and Banana" and "Apple, and Banana" are not"
In addition, I would also like to understand what the e,i,a in function(e,i,a) represent. I'm trying to apply .toLowerCase() in different places to see if that resolves part of my issue but I'm not sure where to do it.
Issues:
Case sensitivity("apple" to match "Apple")
Not exact matches("apple" to match "apple and banana")
Solution:
Use regex-search with case insensitivity
Modified Script:
function getHiddenValueArray(colValueArr,visibleValueArr){
/*colValueArr = [["Apple"],["apple"],["orange"],["Apple, and Banana"]];
visibleValueArr = ['apple','banana'];*/
var flatUniqArr = colValueArr.map(function(e){return e[0].toString();})
.filter(function(e,i,a){
return (a.indexOf(e)==i && !(visibleValueArr.some(function(f){
return e.search(new RegExp(f,'i'))+1;
})));
});
//Logger.log(flatUniqArr); will log orange
return flatUniqArr;
}
References:
String#search
Array#some
Array#filter
Array#map
I want to format cells with a custom function.
The cells have the content like so (without the ") :
Cell_1: "String1 String2 String3"
Cell_2: ""
Cell_3: "String1 String2 String3 String4 String5 String6"
if there is at least like 5 Strings in it, separated with a space it should be a true statement.
I tried to use a custom script like so, because im calling a function in this cell anyway, before returning the value i could set the format too:
var self = SpreadsheetApp.getActiveSheet().getActiveCell();
self.setFontWeight("normal");
if(returnValue.length>=5){
self.setFontWeight("bold");
}
return returnValue.sort().join(" ");
But i got a "You do not have permission to call setFontWeight" Exeption. After a little research i found that cunstom scripts are not allowed to cange format at all. Fine ... but how can i do it with the custom formatting condition
is something like this possible?:
=If(Split(?inputRange?;" ").length>=5;True;False)
If Yes how do i get the Range in the right format and which function is needed to get the String amount?
i tried also to write a custom function for that purpose:
function customFormat(input){
if(input.length>=5)
return true;
}
return false;
calling like so as custom condition:
=customFormat(range)
it seams like i cant use custom function there, i get no positiv result even than i return true always.
If you got some ideas how to accomplish this, i would be thankfull.
Assuming those three cells are in A1:A3
Apply conditional formatting to that range with the formula
=COUNTA(SPLIT(A1, " ")) >= 5
So I'm just getting to grips with node-red and I need to create a conditional global function.
I have two separate global.payloads set to a number value of either 0 or 1.
What I need to happen now is, if global.payload is equal to value 1 then follow this flow, if it is equal to value 0 then follow this one.
I'm just a little confused with the syntax for the function statement. Any help gratefully appreciated.
Since you haven't accepted the current answer, thought I'd give this a try.
I think this is what you need to handle inputs from two separate global contexts. I'm simulating them here with two separate inject nodes to demonstrate:
The checkconf inject node emits a 1 or a 0. Same for the meshstatus node. Substitute your real inputs for those inject nodes. The real work is done inside the function:
var c = context.get('c') || 0; // initialize variables
var m = context.get('m') || 0;
if (msg.topic == "checkconf") // update context based on topic of input
{
c = {payload: msg.payload};
context.set("c", c); // save last value in local context
}
if (msg.topic == 'meshstatus') // same here
{
m = {payload: msg.payload};
context.set('m', m); // save last value in local context
}
// now do the test to see if both inputs are triggered...
if (m.payload == 1) // check last value of meshstatus first
{
if (c.payload == 1) // now check last value of checkconf
return {topic:'value', payload: "YES"};
}
else
return {topic:'value', payload: "NO"};
Be sure to set the "topic" property of whatever you use as inputs so the if statements can discriminate between the two input. Good luck!
You can use the Switch node to do this, rather than a Function node.
I have a trigger set like below
var thiseffect:Boolean = false;
if (thistx.text >="6" && thistx.text <="12")
{ thiseffect = true; }
and the trigger will not activate in this case however if I change the 12 value in this trigger to a value below 10, OR if I change the 6 value to something greater than 10 it will trigger with no problem
Im not really sure why that is, has anyone encountered this before?
This isnt exactly an answer but rather a solution
I have converted my text input into a number variable and the trigger activates with no problem now
var thiseffect:Boolean = false;
var mynum:Number = Number(thistx.text);
if (mynum>=6 && mynum<=12)
{ thiseffect = true; }
You can use the following operators to compare strings: <, <=, !=, ==, =>, and >.
But You should note: When using these operators with strings, ActionScript considers the character code value of each character in the string, comparing characters from left to right.
So in your example it compares left to right character by character not by the actual integer value.
trace("12" <= "6") ;//evaluates true
trace("12" <= "06");//evaluates false
refer to Adobe Doc files here.