On google sheets trying to hide/unhide rows based on the values in particular cells, and trying to write a script in AppsScript for that. Found that one that works in isolation (if B55=NO it hides 64 next rows):
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var range = e.range;
if (activeSheet.getName() !== 'Inputs' || range.getA1Notation() !== 'B55') return;
if (e.value === 'No') {
activeSheet.hideRows(56, 64);
} else if (e.value === 'Yes') {
activeSheet.showRows(56, 64);
}
}
But I need the same for Multiple Cells and multiple rows, as soon as I expand it only last part of the code works and not the first:
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var range = e.range;
if (activeSheet.getName() !== 'Inputs' || range.getA1Notation() !== 'B55') return;
if (e.value === 'No') {
activeSheet.hideRows(56, 64);
} else if (e.value === 'Yes') {
activeSheet.showRows(56, 64);
}
}
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var range = e.range;
if (activeSheet.getName() !== 'Inputs' || range.getA1Notation() !== 'B121') return;
if (e.value === 'No') {
activeSheet.hideRows(122, 67);
} else if (e.value === 'Yes') {
activeSheet.showRows(122, 67);
}
}
From here Cell B121 is working, but my B55 Stops working. Any tips? thanks!
You need to merge the 2 functions onEdit, try
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var range = e.range;
if (activeSheet.getName() !== 'Inputs') return;
if (range.getA1Notation() == 'B55'){
if (e.value === 'No') {
activeSheet.hideRows(56, 64);
} else if (e.value === 'Yes') {
activeSheet.showRows(56, 64);
}
}
if (range.getA1Notation() == 'B121') {
if (e.value === 'No') {
activeSheet.hideRows(122, 67);
} else if (e.value === 'Yes') {
activeSheet.showRows(122, 67);
}
}
}
Answers have already been provided, but consider the more general case:
function myFooBar() {
console.log("the first one")
}
function myFooBar() {
console.log("the second one")
}
function doMyFooBar() {
myFooBar();
}
When you run doMyFooBar(), the console shows the second one. Reading from the top of the script to the bottom, the last declaration of function myFooBar() replaces any previous declarations of that function.
Mike is correct, you can only have on onEdit() trigger, but cannot just merge as he shows since there are returns if the condition is not found
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var range = e.range;
if (activeSheet.getName() == 'Inputs' && range.getA1Notation() == 'B55') {;
if (e.value === 'No') {
activeSheet.hideRows(56, 64);
} else if (e.value === 'Yes') {
activeSheet.showRows(56, 64);
}
}
if (activeSheet.getName() == 'Inputs' && range.getA1Notation() == 'B121') {
if (e.value === 'No') {
activeSheet.hideRows(122, 67);
} else if (e.value === 'Yes') {
activeSheet.showRows(122, 67);
}
}
}
Related
My knowledge is limited, so I'm just praying y'all will enlighten me who knows bare minimum of JS. I want to bypass a timer that makes it unable to go to the next page (I need 35s every single time and that's a lot considering some lessons have over 200 slides). How do I write a script for tampermonkey to make it show the link to the next page instantly?
// Obsługa przycisku Dalej
function goNext(vIsExam) {
// Przycisk nieaktywny - blokada przejścia
if (document.getElementById("pNext").rel != 'enabled') return false;
if (vIsExam==1) {
} else {
location.href='../sql/MemSql.php?pRun=MemCourseGoNext&pCourseResultId=262261&pCourseLessonId=227436';
}
} // function
// Aktywacja przycisku Dalej
function waitNextLesson(vTimeLeft, vTimer) {
setCookie('cLessonTime',vTimeLeft);
if (vTimeLeft > 0) {
document.getElementById('pNext').rel = 'disabled';
document.getElementById('pNextDiv').className = 'CourseInactive';
if (vTimer == 0) {
document.getElementById('pNextIcon').className = 'FontAwesome';
document.getElementById('pNextIcon').innerHTML = vTimeLeft;
} else {
document.getElementById('pNextIcon').className = 'FontAwesome';
document.getElementById('pNextIcon').className = 'FontAwesome FontAwesomeArrowRight';
}
document.getElementById('pNextName').innerHTML = 'CZEKAJ';
vTimeLeft = vTimeLeft - 1;
setTimeout("waitNextLesson("+vTimeLeft+","+vTimer+")",1000);
} else {
document.getElementById('pNext').rel = 'enabled';
document.getElementById('pNextDiv').className = '';
document.getElementById('pNextIcon').className = 'FontAwesome FontAwesomeArrowRight';
document.getElementById('pNextIcon').innerHTML = '';
document.getElementById('pNextName').innerHTML = 'NASTĘPNY SLAJD';
if (document.getElementById('iLessonAutoPlay').checked == true) document.getElementById('pNext').click();
}
} // function
// Obsługa LessonAutoPlay
function jLessonAutoPlay(e) {
setCookie('LessonAutoPlay', document.getElementById('iLessonAutoPlay').checked);
jStopPropagation(e);
} // function
//if (getCookie('LessonAutoPlay') == 'true') document.getElementById('iLessonAutoPlay').checked = true;
// Obsługa skrótów klawiaturowych (strzałka [<] i [>])
$("body").keyup(function(oEvent){
// Sprawdzenie czy można obsługiwać skróty
if (document.getElementById('DIALOG').style.display == 'none' && document.getElementById('LOADER').style.display == 'none') {
// Klawisz [<]
if (oEvent.keyCode == 37) {
document.getElementById("pPrev").click();
}
// Klawisz [>]
if (oEvent.keyCode == 39) {
if (document.getElementById("pNext").rel == 'enabled') {
document.getElementById("pNext").click();
}
}
}
});
Can anyone tell me what CRM would hate about this onload function I've created?
It's telling me Form_OnLoad is not defined. Looks defined to me. It's enabled in my form onload, published, etc.
Thank you.
function Form_OnLoad() {
//Calculates total commission for AE1
// Products + Services
if (Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
var comm1 = (Xrm.Page.getAttribute("new_commissionproductae1").getValue() + Xrm.Page.getAttribute("new_commissionserviceae1").getValue());
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(comm1);
} else if {
// Products only
(Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionproductae1").getValue());
} else if {
// Services only
(Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());
} else {
// Net Sales
(Xrm.Page.getAttribute("new_commissionnetae1").getValue() !== null) && (Xrm.Page.getAttribute("new_commissionseligible").getValue() == "Yes") {
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());
}
}
I believe that's because your JavaScript is not correct. Try to use following code instead of yours:
function Form_OnLoad() { //Calculates total commission for AE1
// Products + Services
if (Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null &&
Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null &&
Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
var comm1 = Xrm.Page.getAttribute("new_commissionproductae1").getValue() + Xrm.Page.getAttribute("new_commissionserviceae1").getValue();
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(comm1);
} else if (Xrm.Page.getAttribute("new_commissionproductae1").getValue() !== null &&
Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionproductae1").getValue());
} else if (Xrm.Page.getAttribute("new_commissionserviceae1").getValue() !== null &&
Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());
} else if (Xrm.Page.getAttribute("new_commissionnetae1").getValue() !== null &&
Xrm.Page.getAttribute("new_commissionseligible").getValue() === "Yes") {
Xrm.Page.getAttribute("new_commissiontotalae1").setValue(Xrm.Page.getAttribute("new_commissionserviceae1").getValue());
}
}
I'm trying to combine two scripts I use on google sheets into one.
They will both work on different tabs.
What is the proper way of combining scripts together?
My two scripts are as follows:
function onEdit(e) {
var sheets = ['Sanshiro', 'Yujiro', 'Mei', 'Suil', 'Martin', 'Yuta', 'Rachel','So'],
cols = [1, 6, 4],
writeCols = [15, 11],
ind = cols.indexOf(e.range.columnStart);
if (sheets.indexOf(e.source.getActiveSheet()
.getName()) === -1 || ind === -1 || !e.value) return;
if (ind === 0 && e.value === 'Update') {
e.range.setValue(new Date());
} else if (ind === 1) {
if (e.range.offset(0, 5)
.getValue() === '') e.range.offset(0, 5)
.setValue(2);
if (e.range.offset(0, 9)
.getValue() === '') e.range.offset(0, 10)
.setValue(new Date());
if (e.range.offset(0, -5)
.getValue() === '') e.range.offset(0, -5)
.setValue(new Date());
else if (ind === 1) {
if (e.range.offset(0, 1)
.getValue() === 'Updated') e.range.offset(0, 1)
.setValue(Col1);
}
}}
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Must Place candis" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks the column
var nextCell = r.offset(0,12);
nextCell.setValue(new Date());
}
}
}
Any help would be much appreciated! If you can help me understand the process then I would like to learn!
Thanks so much!
How about following script? 2 script was summarized in one using "IF".
function onEdit(e) {
var s = SpreadsheetApp.getActiveSheet();
var sheets = ['Sanshiro', 'Yujiro', 'Mei', 'Suil', 'Martin', 'Yuta', 'Rachel','So'];
if (sheets.indexOf(e.source.getActiveSheet().getName()) > -1){
script1();
}
if(s.getName() == "Must Place candis") {
script2(s);
}
}
function script1(){
var cols = [1, 6, 4],
writeCols = [15, 11],
ind = cols.indexOf(e.range.columnStart);
if (ind === 0 && e.value === 'Update') {
e.range.setValue(new Date());
} else if (ind === 1) {
if (e.range.offset(0, 5)
.getValue() === '') e.range.offset(0, 5)
.setValue(2);
if (e.range.offset(0, 9)
.getValue() === '') e.range.offset(0, 10)
.setValue(new Date());
if (e.range.offset(0, -5)
.getValue() === '') e.range.offset(0, -5)
.setValue(new Date());
else if (ind === 1) {
if (e.range.offset(0, 1)
.getValue() === 'Updated') e.range.offset(0, 1)
.setValue(Col1);
}
}
}
function scritp2(s){
if( s.getName() == "Must Place candis" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks the column
var nextCell = r.offset(0,12);
nextCell.setValue(new Date());
}
}
}
I am looking to make a checkbox that when unchecked, will turn off a certain function in a .js file. Can someone help me?
popup.html
HTML Check box:
content.js
Turn off this function:
var tweet = new Array();
var tweetName = new Array();
function linkSnipe() {
for (var i = 0; i < 5; i++) {
tweetName[i] = document.getElementsByClassName("fullname js-action-profile-name show-popup-with-id")[0].innerHTML;
tweet[i] = document.getElementsByClassName("js-tweet-text")[i].innerHTML;
}
if (tweet[0].match(shoeName) == shoeName && tweet[0].match(filterer) != filterer && tweet[0].match(filter2) != filter2) {
if(checkon == "Tweets"){
document.getElementsByClassName("twitter-timeline-link")[0].click();
update();
}
}
else if (tweet[1].match(shoeName) == shoeName && tweet[1].match(filterer) != filterer && tweet[1].match(filter2) != filter2) {
if(checkon == "Tweets"){
document.getElementsByClassName("twitter-timeline-link")[1].click();
update();
}
}
else if (tweet[2].match(shoeName) == shoeName && tweet[2].match(filterer) != filterer && tweet[2].match(filter2) != filter2) {
if(checkon == "Tweets"){
document.getElementsByClassName("twitter-timeline-link")[2].click();
update();
}
}
else if (tweet[3].match(shoeName) == shoeName && tweet[3].match(filterer) != filterer && tweet[3].match(filter2) != filter2) {
if(checkon == "Tweets"){
document.getElementsByClassName("twitter-timeline-link")[3].click();
update();
}
}
else if (tweet[4].match(shoeName) == shoeName && tweet[4].match(filterer) != filterer && tweet[4].match(filter2) != filter2) {
if(checkon == "Tweets"){
document.getElementsByClassName("twitter-timeline-link")[4].click();
update();
}
}
else if(checkon == "Tweets") {
location.reload();
}
}
setTimeout("linkSnipe()", 250);
}
When the checkbox is checked, redefine the function as:
<input type=checkbox ..... onchange="doit()">
function doit() {
window.linkSnipe=function() {}
}
I've used this too:
function doit() {
window['linkSnipe']=function() {}
}
If you want to turn the function on and off by the checkbox:
<input type=checkbox ..... onchange="doit(this)">
var linkSnipeSave = linkSnipe;
function doit(ck) {
if (ck.checked)
window['linkSnipe']=linkSnipeSave
else {
linkSnipeSave = linkSnipe; //not sure if this line is needed...pls test
window['linkSnipe']=function() {}
}
}
You could simply have a Boolean variable that changes with the state of your check box. You could then put an if statement around the function call that will only trigger if the checkbox is checked.
http://jsfiddle.net/W5P8X/
//initialize some variables.
bike_checked = false;
car_checked = false;
//get elements by their ID from html
bike = document.getElementById("bike");
car = document.getElementById("car");
//add event listeners to the html elements we found above
bike.addEventListener("click", toggle_bike, false);
car.addEventListener("click", toggle_car, false);
//toggle bike_checked variable on click
function toggle_bike(){
if(bike_checked == true)
bike_checked = false;
else
bike_checked=true;
current_state();
}
//toggle car_checked variable on click
function toggle_car(){
if(car_checked == true)
car_checked = false;
else
car_checked=true;
current_state();
}
//output current state.
function current_state(){
if(car_checked == true)
alert('Car checked');
if(bike_checked == true)
alert('Bike checked');
}
I answered with only javascript and no jQuery, but you could probably make it a bit more concise with jQuery.
I hope this helps.
I have this jquery scripts. I want to use the return value from the function stockArt() into function prod_actname(). It seems i'm missing something or my implementation is wrong. How could i possibly do that?
Another scenario is when StockArt() value is changed the Activity Name must be updated also.
Say Stock Art Color is green. and the Activity Name color also be updated to color green, without selecting the color green from prod_actname() function. It will automatically be change as the StockArt color is also change. They must be in the same color.
jQuery( document ).ready(function($) {
$('#preview_design').css("background-color","black");
$('#stock_art').change(function() {
var retVal = stockArt();
$('#prod_actname').data("stockData", retVal);
});
$('#prod_actname').change(function() {
var stockData = $('#prod_actname').data("stockData");
prod_actname(stockData);
});
function stockArt()
{
var returnValue = null;
var selectStock_Art = $('#stock_art :selected').val();
if(selectStock_Art == '31145-RB-emb')
{ // green
$('#stockArt_img').removeClass().addClass('stock_art_grbg1');
}
else if(selectStock_Art == '33441-RB-emb1')
{ // yellow
$('#stockArt_img').removeClass().addClass('stock_art_yebg2');
}
else if(selectStock_Art == '33441-RB-emb2')
{ // gold
$('#stockArt_img').removeClass().addClass('stock_art_gobg3');
}
else {
$('#stockArt_img').removeClass();
}
returnValue = selectStock_Art;
return returnValue;
}
function prod_actname(stockData){
var StockArtResult = stockData;
//User stockData as needed
// assign the value to a variable, so you can test to see if it is working
var selectActivity_Name = $('#prod_actname :selected').val();
//alert(selectActivity_Name);
if(selectActivity_Name == 'Baseball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg1');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg1');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg1');
}
}
else if(selectActivity_Name == 'Basketball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg2');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg2');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg2');
}
}
else if(selectActivity_Name == 'Boys Basketball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg3');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg3');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg3');
}
}
else if(selectActivity_Name == 'Girls Basketball')
{
$('#activityName_img').removeClass();
if(selectStock_Art == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg4');
}
else if(selectStock_Art == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg4');
}else if(selectStock_Art == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg4');
}
}
}
});
Use data attributes to store data for '#prod_actname' and later access it.
You can leverage jQuery.data for this.
Try this
jQuery( document ).ready(function($) {
$('#preview_design').css("background-color","black");
$('#stock_art').change(function() {
var retVal = stockArt();
$('#prod_actname').data("stockData", retVal);
});
$('#prod_actname').change(function() {
var stockData = $('#prod_actname').data("stockData");
prod_actname(stockData);
});
function stockArt()
{
var returnValue = null;
var selectStock_Art = $('#stock_art :selected').val();
if(selectStock_Art == '31145-RB-emb')
{ // green
$('#stockArt_img').removeClass().addClass('stock_art_grbg1');
}
else if(selectStock_Art == '33441-RB-emb1')
{ // yellow
$('#stockArt_img').removeClass().addClass('stock_art_yebg2');
}
else if(selectStock_Art == '33441-RB-emb2')
{ // gold
$('#stockArt_img').removeClass().addClass('stock_art_gobg3');
}
else {
$('#stockArt_img').removeClass();
}
returnValue = selectStock_Art;
return returnValue;
}
var stockArtValue = stockArt();
function prod_actname(stockData){
//User stockData as needed
// assign the value to a variable, so you can test to see if it is working
var selectActivity_Name = $('#prod_actname :selected').val();
//alert(selectActivity_Name);
if(selectActivity_Name == 'Baseball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg1');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg1');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg1');
}
}
else if(selectActivity_Name == 'Basketball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg2');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg2');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg2');
}
}
else if(selectActivity_Name == 'Boys Basketball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg3');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg3');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg3');
}
}
else if(selectActivity_Name == 'Girls Basketball')
{
$('#activityName_img').removeClass();
if(selectStock_Art == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg4');
}
else if(selectStock_Art == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg4');
}else if(selectStock_Art == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg4');
}
}
}
});
One way is to store the output of the stockArt() in a variable and then pass that as an argument to the prod_actname(). For this, you would need to modify the function signature of the prod_actname() function to accept an argument. Something like this
var stockArtValue;
$('#stock_art').change(function() {
stockArtValue = stockArt();
});
$('#prod_actname').change(function() {
prod_actname(stockArtValue);
});
function prod_actname(val){
....
}
For some cases, it might be useful to consider that the stockArtValue variable has indeed been changed. You can typically use another state variable to indicate. Alternatively, if you know the set of likely input values, then you initialize it with a value outside of that input value set and check against it.
You could save its value in a property...
jQuery( document ).ready(function($) {
var StockArtResult = null;
$('#stock_art').change(function() {
StockArtResult = stockArt();
});
$('#prod_actname').change(function() {
if(StockArtResult != null)
{
prod_actname(StockArtResult);
}
});
});