Zapier change quantity on line item to 0.30 from 1.0 - zapier

I have the attached Zap setup on my Zapier account and I need to change the quantity line for each line item to be 0.30. Can this be hard coded somehow?
At the moment the quantity is showing as 1.0 on each line item (1.0,1.0). We need to dynamically change the quantity to always be 0.30 for each line item.
Thanks in advance.

The simple way of doing this is by using a zapier code step. Write a generic Loop to run through the line-items and assign the number to the list of your new line-item variable. e.g
for (let i = 0; i < lineitem.length ; i++) {
lineitem[i]=0.3
}

Related

How can I output a number based on IF conditionals in different cells?

I am sorry if I made the wrong question, I'm getting started with Google Sheets and wanted to figure out how to work on some kind of score calculator based on IF conditionals. Here is the example:
It's going to be used on a Form Responses sheet (I don't want to use the Google Form's Quiz option) where I'll need to answer some Y/N questions, in the "Total" column, there is going to be a final score out of 100 based on the "Yes" or "No" answer.
Let's say that the Row # 2 is a submission from a Google Form, and let's say that every submission has by default a score of 100. What the "No" is doing is deducting 10 points from that initial score of 100.
I started with something like =MINUS("100", IF(A2= "No", 10)) but it only works with one cell.
Thank you so much!
Try this formula in E2:
=MINUS(100, COUNTIF(A2:D2, "No") * 10)
Output:
Update:
If you want to use the column header as reference for deduction points, You can use this Custom Function:
To write a custom function:
Create or open a spreadsheet in Google Sheets.
Select the menu item Tools > Script editor.
Delete any code in the script editor.
For this case, simply copy and paste the code below into your script editor
Click Save save.
Code:
function SCORE(range) {
var map = range.shift();
var data = range;
var result = [];
for(var i = 0; i < data.length; i++){
var tally = 0;
for(var j = 0; j < data[0].length; j++){
if(data[i][j] == "No"){
tally = tally + map[j];
}
}
result.push([100+tally])
}
return result;
}
To call the custom function
Click the cell where you want to use the function.
Type an equals sign (=) followed by the function name and any input value — for example, =SCORE(A1:D4) — and press Enter.
The cell will momentarily display Loading..., then return the result.
Example Usage:
Note: You must always include the column header(deduction points) in your range.
Reference:
COUNTIF
Custom Function

How to generate random data of birth dates using google spreadsheets for a specific years?

I want a formula to generate random data of birth dates for a specific years (Example: 1995 to 2002) and make it Array like this:
Sheet URL: https://docs.google.com/spreadsheets/d/1XHoxD-hNmpUOMVm_u-cz-4ESrabodsrS0fIfaN-n4js/edit
That might not be the best approach but it will get you closer to what you want:
=DATE(RANDBETWEEN(1995,2002),RANDBETWEEN(1,12),RANDBETWEEN(1,31))
There are two issues with this approach:
you might get a day that does not exist for the particular month. For example, 2/28/2021 exists, but 2/29/2021 does not exist.
I wasn't able to generate an array but only drag down formulas. When I generate an array, the same random numbers are used and as a result the dates are the same.
For the first issue, you can use isdate to check if the random date returned is correct. For example, 2/29/2021 is a wrong date (I hardcopied that date).
but I guess you can filter out the FALSE cases.
I really hope other people can come up with a better approach.
You could try (as I demonstrated in your sheet):
=ARRAY_CONSTRAIN(SORT(SEQUENCE(DATE(1992,12,31)-DATE(1900,1,1),1,DATE(1900,1,1)),RANDARRAY(DATE(1992,12,31)-DATE(1900,1,1)),1),COUNTA(A2:A),1)
SEQUENCE(DATE(1992,12,31)-DATE(1900,1,1),1,DATE(1900,1,1)) - Is used to create an array of valid numeric representations of true dates between 1-1-1900 and 31-12-1992.
SORT(<TheAbove>,RANDARRAY(DATE(1992,12,31)-DATE(1900,1,1)),1) - Is used to sort the array we just created randomly.
ARRAY_CONSTRAIN(<TheAbove>, COUNTA(A2:A),1) - Is used to only return as many random birth-dates we need according to other data.
Note that this is volatile and will recalculate upon sheet-changes and such. Also note that this is just "slicing" a given array and may fall short when you try to use it on a dataset larger than the given array.
As Google Sheets can deal with dates as integers (~ number of days since 1900), choosing a random date between two dates can be a single call to RANDBETWEEN (with the output formatted as Date).
With your initial date written in B1 and your end date in B2, the formula is simply:
=RANDBETWEEN($B$1,$B$2)
You can paste this formula in as many cells as you want, to generate N different random dates.
Of course, as other answers involving random generators in your sheet, the formula will be recomputed at each change. My suggestion to overcome this would simply be to copy/paste the output, using the "Paste special > Values only" option (right click or "Edit" menu).
Script Solution
Just for sake of completeness, here is a solution using a script
Initial Considerations
This cannot function like a in sheet function/formula.
https://developers.google.com/apps-script/guides/sheets/functions
Custom function arguments must be deterministic. That is, built-in spreadsheet functions that return a different result each time they calculate — such as NOW() or RAND() — are not allowed as arguments to a custom function. If a custom function tries to return a value based on one of these volatile built-in functions, it will display Loading... indefinitely.
A custom function cannot affect cells other than those it returns a value to. In other words, a custom function cannot edit arbitrary cells, only the cells it is called from and their adjacent cells. To edit arbitrary cells, use a custom menu to run a function instead.
So a normal script is needed.
The Script
/**
* Sets the values of a range to random dates.
*/
function generateRandomBdays(range, start, end) {
let height = range.getHeight();
let width = range.getWidth();
let output = [];
for (let i = 0; i != height; i++) {
let row = [];
for (let j = 0; j != width; j++) {
row.push(randomBday(start, end));
}
output.push(row)
}
range.setValues(output);
}
/**
* Generates a random date beween start and end
*/
function randomBday(start, end) {
if (start < 2000) start = start - 1900
start = new Date(`${start}`);
if (end < 2000) end = end - 1900
end = new Date(`${end}`);
let bday = new Date(
start.getTime() + (Math.random() * (end.getTime() - start.getTime()))
);
return bday;
}
/**
* Gets active selection and fills with random dates
*/
function main(){
let file = SpreadsheetApp.getActive();
let sheet = file.getActiveSheet()
let range = sheet.getActiveRange();
// ============
generateRandomBdays(range, 1995, 2002); // Change these years to your liking
// ============
}
/**
* Creates menu when sheet is opened.
*/
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Generate Birthdays')
.addItem('Generate!', 'main')
.addToUi();
}
Which works like this:
Installation
You will have to copy it into your script editor and then run one of the functions to authorize the script with the permissions it needs. Then next time you open the sheet you should have the menu available.
Alternatively you can delete the onOpen function and just use it from the script editor.
Within the main function, customize the range of years you need.
References
Apps Script
Overview of Spreadsheet Service in Apps Script

Selecting an item from a listbox to show more items in another listbox?

Alright, so i have a problem with my programming, i have three checkedlistboxes, one called "lstShows" 2nd is called "lstSeasons" and third is called "lstEpisodes" and i have two comboboxes that have seasons and episodes in them, one combobox is called "cbSeasons" and 2nd is called "cbEpisodes. so what i'm trying to do is, when i press on an item in lstshows, i want to be able to assign to it items from lstSeasons, and when i want to click on an item in seasons i want to be able to assign items to it in lstepisodes
So for example lets say, a tv shows contains 10 seasons, so i add that tv shows and assign 10 seasons for it, then season 1, has 20 episodes, and seasons 2 has 15 episodes, i want to be able to add items to each different show, and season. i have been looking every where but i could not find anything.
Here is the layout https://www.dropbox.com/s/u6xc3sb43ksq8qr/Capture.PNG?dl=0
and i tried to do the code, i done this but it does not work.
Dim item As String = lstSeasons.SelectedItem
lstEpisodes.Items.Add(item)
I really need help with this.
Thank you.
First of all, your data must be stored somewhere.
For example, you can have one worksheet per show, have the seasons in column A and for each season have the episodes in the same row (starting at column B). If you don't want this data to be seen, just hide the sheets.
So if I understood correctly, first you want to select a show, then the seasons of this show appear in the 2nd listbox, and then when you select a season the episodes of this season appear in the 3rd listbox.
First, you need to add all you shows to the 1st listbox. Here, I'll assume that you have 10 shows, that their corresponding worksheets are Worksheets(1) to Worksheets(10), and that the name of the worksheet is the name of the show (but you can do as you wish, for example storing the show's name in a particular cell).
Dim showName as String
For i = 1 To 10
showName = Worksheets(i).Name
lstShows.AddItem showName
Next i
Then, to get the seasons listbox to change when you select a particular show, you can do this :
Private Sub lstShows_Change()
Call Me.lstSeasons.Clear
showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row
Dim i As Integer
For i = 1 To rowCount
Me.lstSeasons.AddItem sh.Cells(i,1).Value
Next i
End Sub
And to get the episodes listbox to change when you select a particular season, you can do this :
Private Sub lstSeasons_Change()
Call Me.lstEpisodes.Clear
showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row
Dim colCount As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To rowCount
If Me.lstSeasons.Value = sh.Cells(i,1).Value Then
colCount = sh.Cells(i, sh.Columns.Count).End(xlToLeft).Column
For j = 2 To colCount
Me.lstEpisodes.AddItem sh.Cells(i,j).Value
Next j
Next i
End Sub
Hope this will help !
First thing I believe you need to do is to put a multi dimensional array to store your information.
More details about jagged arrays: https://msdn.microsoft.com/en-us/library/hkhhsz9t(v=vs.90).aspx
so you can use it this way for example:
Dim shows(50)(50) As string
This will give you 50 "shows" with 50 episodes each. now you can change those using the program as needed.
Now into the next part which is inserting those in. You can modify them by assigning a value by
shows(1)(12) = "ep12nameofshow1"
Where you can assign the string as a variable if you want to be able to manually change the name during runtime
Now you want to add the items to your listbox! So lets go over that with a great little for-loop
For Each episode As String In shows(1) 'show number here
lstEpisodes.Items.Add(episode)
Next
please note that I didn't test this since I don't have access to most of your code so please inform me if there are any problems you are facing.
Update This code should be working:
1- Add this at top of your page (below class declaration)
Dim showEpisodes(99)(99)() As String
think of it as showEpisodes(Show#,Season#,Ep#)
2- Add values to your array. How you do that is up to you (use a file, database or just predetermined values. You can even put them in run time. But that's another thing for another question!)
3- Add this part to your season's code
For Each element As String In showEpisodes(lstShows.SelectedIndex)(lstSeasons.SelectedIndex)
lstEpisodes.Items.Add(element)
Next

How do I update the content selected from a dropdown cell if the source subsequently changes? (Insert cell reference instead of literal value.)

I have two sheets used to track a construction project.
On the first sheet, a list of tasks is incorporated into a timeline with cost projections, etc. The tasks are something like the following:
Cut Concrete
Pour new pad
Frame
Roof
The second sheet is for tracking individual purchases, each of which is associated with a task from the first sheet (e.g., Cut Concrete). It looks something like the following:
DATE PAYEE ITEM CATEGORY COST
----- ---------- ---------- -------- ------
10/25 Home Depot (10) 2x4's Frame ▽ $54.00
Using Data Validation, the Category dropdown in the second sheet references the list of items from the first sheet. This is working perfectly. Here's the problem...
If I change the item on the first sheet (for instance, "Frame" to "Framing"), although the dropdown is updated, any previously entered rows (such as the one shown above), just show a validation error (i.e., a red indicator in the right corner of the cell).
Since a construction project can easily have hundreds of items purchased, rather manually looking for data validation errors, is there a way to have the second sheet's values updated? For instance...
Add a script that watches for content changes in the first sheet. When the user starts editing a "task" cell, its original value is noted; and upon exiting the cell, if the value has changed, the script looks through the second spreadsheet for the original value and replaces it with the new one. (Seems like a lot of hassle.)
Find some way for the dropdown to insert a cell reference to the first sheet instead of the actual value. That way, the dropdown cell is always referencing the source item (i.e., the "task" cell's current content).
A more obvious feature I don't know about.
As per my favored possibility noted in my question, I figured out how to write a script that would run after a value was selected from the dropdown, thus overwriting the literal value with a cell reference.
The following script runs after the user makes a selection in the dropdown menu:
function onEdit(event){
var activeSheet = event.source.getActiveSheet();
var activeSheetName = activeSheet.getName();
var activeCell = activeSheet.getActiveCell();
var activeColumn = activeCell.getColumn();
if (activeSheetName == "Envelope (Spent)" && activeColumn === 4) {
var destinationCell = activeCell;
var destinationContent = destinationCell.getValue();
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var sourceSheetName = sourceSheet.getName();
var sourceRange = sourceSheet.getRange("D:D");
var sourceValues = sourceRange.getValues();
for (var i = 0; i < sourceValues.length; i++) {
if (sourceValues[i] == destinationContent) {
var sourceRow = sourceSheet.getRange("D" + i + ":D" + i).getRow() + 1;
destinationCell
.setValue("='" + sourceSheetName + "'!D" + sourceRow)
.setNote(destinationContent)
;
}
}
}
}
To allow for an easy recovery in case the two sheets somehow get out of sync, the originally selected value, derived from the dropdown's data validation, is inserted as a note. I figured it was easier to clear all the notes in the future than to find myself with a bunch of entries that don't correspond with the source list of tasks.
The data validation in Google sheets is always inserting the Literals you type or pick so you can't link it to the original cell. You have to solve the whole thing through scripts
Get a list of all data validation items through onOpen()
Create an onEdit() function that runs if the data validation range is edited, checks which field is changed and then goes through the purchases, checks which purchases have the old value and replaces them with the new one.

Issue with inserting rows automatically and then referencing in another tab

I am using Zapier to insert external content into a Google Spreadsheet tab automatically and it appears to insert a row directly under the last non-empty row rather than replacing the content in the next empty row.
So if row 7 was the last row, Zapier inserts a new row under 7 and the old row 8 becomes row 9.
I then have two other tabs, both viewable on the web (where the first isn't) that reference the content in the first tab but as new content is added, these references in the format of data!a8 also gets moved. If I use data!$a$8 then I have to change 500 rows manually.
With or without coding, is there a way to allow Zapier to insert the rows but still reference that row automatically?
For those attempting to do this without script, it appears it is not possible.
Script
Create a function like the one below. Note we are reading one sheet (AutomaticImport) and writing to the sheet WebData
function fncUpdateWebData() {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sheet = ss.getSheetByName("AutomaticImport"),
sheetWeb = ss.getSheetByName("WebData"),
arrRides = sheet.getDataRange().getValues(),
row,col,iOutputRow,strURL;
iOutputRow = 2;
for ( iRow = 1; iRow < arrRides.length; iRow++) {
sheetWeb.getRange(iOutputRow,1).setValue(arrRides[iRow][5]); // date
strURL = '=HYPERLINK("' + 'https://www.strava.com/activities/' + arrRides[iRow][7] + '","' + arrRides[iRow][8] + '")';
sheetWeb.getRange(iOutputRow,2).setValue(strURL); // start & link
sheetWeb.getRange(iOutputRow,3).setValue(arrRides[iRow][4]); // Distance
sheetWeb.getRange(iOutputRow,4).setValue(arrRides[iRow][0]); // Avg Speed
iOutputRow++;
}
}
In Resources/Current Project Triggers and a new trigger and use your new function name, "from Spreadsheet" and select "onChange"
I hope his helps get you over the hurdle.
I know this is a really, really late answer, but I was having the same issue and almost used the accepted solution before realizing there's a much better and easier way.
It's actually in the Zapier docs, right here. The solution is to create two Google Sheets, one for Zapier and the other for your formulas. Hook Zapier up to the first sheet, and then use the IMPORTRANGE command to copy the necessary columns into the second sheet. Write your formulas in the second sheet, and you'll notice that the extra layer of indirection stops Google from rewriting them when a row is added to the source range!
Tl;dr: RTFM, as usual.

Resources