I'm fairly new here so apologies for asking a possibly stupid question.
I'm trying to get Google Sheets to send an email based on the information in columns B and O
Here is my code thus far...
function confirmationEmail(e) {
var sheet = SpreadsheetApp.getActiveSheet(BIKE2)
var orderNumber = e.values[2];
var subject = "Order is Ready to be Confirmed";
var body = "An order from the bike shop is ready to be confirmed! Order Number: " + orderNumber;
if (e.values[14] == NOT NULL);
if (e.values[1] == 'Order Entry');
MailApp.sendEmail("dylan.bassett#activesportsinc.com", subject, body)
}
Currently when I try to run the code I get an error saying:
"Missing ) after condition. (line 6, file "Confirmation Emails")"
I'm not sure how far off I am here, I was able to get a similar code to work without a condition but things got dicey when I started trying to tell it when to do things.
Any help is appreciated! I'm sure this is a rookie problem :)
I assume your using a form Submit. I don't send much email so not sure about the syntax for that but BIKE2 needs to be in quotes and the semicolons after the if's are not wanted. So try this.
function confirmationEmail(e) {
var sheet = SpreadsheetApp.getActiveSheet('BIKE2')
var orderNumber = e.values[2];
var subject = "Order is Ready to be Confirmed";
var body = "An order from the bike shop is ready to be confirmed! Order Number: " + orderNumber;
if (e.values[14] && e.values[1] == 'Order Entry')
{
MailApp.sendEmail("dylan.bassett#activesportsinc.com", subject, body);
}
}
Related
need some help with script on google sheets
I'm having some issues to try to use "setVisibleValues" and I got an error saying "Exception: Visible values are not currently supported. As an alternative specify a list of hidden values that excludes the values that should be visible.". But my problem is, I've a huge number of employee names on a list, and I wanna filter just based in one person.
I cant show some information, but the thing is: "I just wanna filter one value, and I don't know how to do it using "setHiddenValues".
function Filtersheet() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A3:S').activate();
spreadsheet.getRange('H3').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues([''])
var criteria = SpreadsheetApp.newFilterCriteria()
.setVisibleValues(['tayzer'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(8, criteria);
}
Lets say that the names of the Employees are : jorge, lucas, nuno, fernando, marta, beatriz, tayzer, larissa, and I wanna use the filter script to only show on the column the information related to tayzer
But my way to change the filter employee will be on a cell outside the script (cause I've around 200 employees)
Thanks in advance for the help
try this
function setFilter() {
// replace 'sheet name' with you sheet
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet name');
var range = ss.getDataRange();
var filter = range.getFilter() || range.createFilter()
var criteria = SpreadsheetApp.newFilterCriteria().whenTextContains('tayzer');
filter.setColumnFilterCriteria(8, criteria);
}
if i am not wrong if you put "jorge" in cell_C4 you want it to filter "jorge" in column E, if so try below code.
function setFilter() {
// replace 'sheet name' with you sheet
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet name');
var range = ss.getDataRange();
var filter = range.getFilter() || range.createFilter()
var criteria = SpreadsheetApp.newFilterCriteria().whenTextContains(ss.getRange('C4').getValue()).build();
filter.setColumnFilterCriteria(8,criteria)
}
Below is the code for the custom button. The objective is to store different gender and rating for different button:
var gender='Ladies';
var rating='Good';
setRating(gender, rating);
The method implementation for setRating(gender, rating) is wrote on the client script as follow. The objective is to tell browser javascript to activate sendRating(gender, rating) function.
function setRating(gender, rating){
google.script.run
.withFailureHandler(function(error) {
// An error occurred, so display an error message.
status.text = error.message;
})
.withSuccessHandler(function(result) {
// Report that the email was sent.
status.text = 'Thank you for the feedback';
})
.sendRating(gender, rating);
}
Below is the sendRating(gender, rating) implementation wrote on the server script. The objective is to tell AppMaker javascript to activate .saveRecords API to save the gender and rating records to the datasource called ToiletRating. The datasource contain field such as 'Gender' and 'Rating'.
function sendRating(gender, rating){
var db = app.models.ToiletaRating.newRecord();
person.Gender = gender;
person.Rating = rating;
app.saveRecord([db]);
}
Can you help me why I get this error saying that newRecord method is undefined while I have declare it in the Server script line no. 3 .
E
Wed Feb 28 09:47:42 GMT+800 2018
TypeError: Cannot call method "newRecord" of undefined. at sendRating (NewScript:3)
It seems that you have a typo in your script (Toileta vs Toilet):
// your version with typo
var db = app.models.ToiletaRating.newRecord();
// version without typo
var db = app.models.ToiletRating.newRecord();
But your script will fail even if you fix the typo. You need to use the variable you defined to make things work:
function sendRating(gender, rating) {
// define variable
var newRecord = app.models.ToiletRating.newRecord();
// use variable
newRecord.Gender = gender;
newRecord.Rating = rating;
// Note that in original script you have one more typo:
// app.saveRecord vs app.saveRecords
app.saveRecords([newRecord]);
}
Also keep in mind, that you can improve this script further:
Associate ratings with users to prevent adding multiple ratings from the same people
Add permission checks to prevent users adding ratings on behalf of other users
...
Take a look at Vendor Ratings and Q&A Forum templates, they have very similar functionality
I am using IFTTT to push forms sent to my email address to a Google Sheet. The contents get pasted into column A in one big clump, and I can't figure out how to split the text into columns in a way that formats well. Ideally, I'd like to only include the answers to questions on the form in the columns to the right of column A.
Here is a sample of what gets pasted into column A:
New customer message on May 9, 2017 at 12:15 PM
You received a new message from your Online Store's contact form.
Name:
Jon Snow
Email:
sample#gmail.com
Q1:
Yes
Q2:
No
Q3:
yes
Q4:
no
Q5:
no
Is there some sort of script I could use to display the name, email address, and answers to the 5 questions in the 7 columns to the right of column A?
I have a rudimentary solution that you can build on if you like.
My solution assumes a few things, firstly the name is always going to be two words, secondly the answers are always going to be yes or no.
This will work for any number of rows in column A.
The whole solution is based on splitting up the string in a particular way, and it's not very fluid as it assumes the amount of spaces and the formatting will always be the same. It's a start :)
function myFunction() {
var ss = SpreadsheetApp.getActiveSheet();
var dataRangelength = ss.getDataRange().getLastRow();
var strRef = ss.getRange("A1:A" + dataRangelength);
var str = strRef.getValues();
for (var i = 0; i < dataRangelength; i++) {
var row = str[i];
var A1ref = i + 1
var rowRef = ss.getRange("A" + A1ref);
if (row != "") {
var arr = row.toString().split(" ");
var arr1 = arr[20].toString().split("\n");
var arr2 = arr[21].toString().split("\n");
rowRef.offset(0, 1).setValue(arr1[4] + " " + arr2[0]);
rowRef.offset(0, 2).setValue(arr2[4]);
rowRef.offset(0, 3).setValue(arr2[8]);
rowRef.offset(0, 4).setValue(arr2[12]);
rowRef.offset(0, 5).setValue(arr2[16]);
rowRef.offset(0, 6).setValue(arr2[20]);
rowRef.offset(0, 7).setValue(arr2[24]);
}}
}
I want to email form responses to a help desk email once they are "approved" and a "work order #" is assigned, meaning I open the spreadsheet and assign initials to the approved column and assign a work order number to the new work order column. I've modified many scripts to try to achieve this. I do not want the responses sent immediately upon form submission, as they need at least a work order attached. Below is the script I've attempted to modify (shown below without any modification). It works fine IF I want the form submissions to go directly to the email when a user hits submit. Again, I need them emailed ONLY when a work order is attached to the respective line item in the spreadsheet.
function nl2br_(input_string){
return input_string.replace(/(\r\n|\r|\n)/g,'<br />');
}
function RequestNWOMailer(e) {
try {
var recipient = 'test-area#efriends44221.org';
var timestamp = e.values[0];
var name = e.values[1];
var contactmethod = e.values[2];
var emailphone = e.values[3];
var building = e.values[4];
var room = e.values[5];
var reason = e.values[6];
var description = e.values[7];
var approval = e.values[8];
var nwo = e.values[9];
var subject = building+' <'+reason+'> <'+name+'>';
var body = name+' <'+emailphone+'> sent the following: '+description;
var bodyHTML = '\
<p>NWO #: '+nwo+'</p>\
<p>'+name+' sent the following: </p>\
<p>Contact Method: '+contactmethod+'</p>\
<p>Email of Phone#: '+emailphone+'</p>\
<p>Building: '+building+'</p>\
<p>Room #: '+room+'</p>\
<p>Reason for NWO: '+reason+'</p>\
<p>Description: '+nl2br_(description)+'</p>';
var advancedArgs = {htmlBody:bodyHTML , replyTo:emailphone};
MailApp.sendEmail(recipient, subject, body, advancedArgs);
} catch(e){MailApp.sendEmail(recipient, "Error - Request for New Work Order Form", e.message);
}
}
Some pseudo-code of the model I'm working with:
User { int Id, string Username }
Activity { int Id, string Name }
Place { int Id, string Name }
Basically I have a bunch of Users and they belong to certain places (many to many relationship in RDBMS world). What I'd like to do now that I've created all of the nodes already is create the relationship between them. To do that I believe I need to get references to each node and then simply create the relationship between them.
Note: So far no relationships exist. It does look like in some of the examples they have added the User nodes with a relationship that points to the RootNode but I have no idea why. I'm not sure if I need to do that or not.
More pseudo-code:
var userRef = _graphClient...GetUserNodeWhereIdEquals(user.Id);
// or something like _graphClient.OutV<User>("[[id={0}]]", user.Id)
// or even just _graphClient.V<User>(id == user.Id)
var placeRef = _graphClient...GetPlaceNodeWhereIdEquals(place.Id);
_graphClient...CreateRelationshipBetween(userRef, placeRef, "belongs_to");
Unfortunately the documentation starts off pretty great then goes south when you get to relationships.
Update 3/29/12
Here's the code I have so far:
foreach (var a in _activityTasks.GetAll())
{
_graphClient.Create(a, new ActivityBelongsTo(_graphClient.RootNode));
}
foreach (var p in _placeTasks.GetAll().Take(1))
{
var placeNode = _graphClient.Create(p, new PlaceBelongsTo(_graphClient.RootNode));
foreach (var activity in p.Activities)
{
Activity activity1 = activity;
var activityNode = _graphClient.RootNode.In<Activity>(ActivityBelongsTo.TypeKey, a => a.Id == activity1.Id).SingleOrDefault();
_graphClient.CreateRelationship(placeNode, new PlaceHasActivity(activityNode.Reference));
}
}
The activity nodes are created fine. The place node is created fine. An error is now being thrown when trying to get the activityNode. It's a rather large stack trace so I'll try to paraphrase here:
Received an exception when executing the request.
The query was: g.v(p0).in(p1).filter{ it[p2] == p3
}.drop(p4).take(p5)._()
The exception was: Value cannot be null. Parameter name: key
System.ArgumentNullException: Value cannot be null.Parameter name: key
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue
value, Boolean add) ... The raw response body was: [ {
"outgoing_relationships" :
"http://localhost:7474/db/data/node/2/relationships/out", "data" : {
"Name" : "Aerobics", "Id" : 2 }, "all_typed_relationships" :
"http://localhost:7474/db/data/node/2/relationships/all/{-list|&|types}",
"traverse" :
"http://localhost:7474/db/data/node/2/traverse/{returnType}", "self"
: "http://localhost:7474/db/data/node/2", "property" :
"http://localhost:7474/db/data/node/2/properties/{key}",
"outgoing_typed_relationships" :
"http://localhost:7474/db/data/node/2/relationships/out/{-list|&|types}",
"properties" : "http://localhost:7474/db/data/node/2/properties",
"incoming_relationships" :
"http://localhost:7474/db/data/node/2/relationships/in", "extensions"
: { }, "create_relationship" :
"http://localhost:7474/db/data/node/2/relationships",
"paged_traverse" :
"http://localhost:7474/db/data/node/2/paged/traverse/{returnType}{?pageSize,leaseTime}",
"all_relationships" :
"http://localhost:7474/db/data/node/2/relationships/all",
"incoming_typed_relationships" :
"http://localhost:7474/db/data/node/2/relationships/in/{-list|&|types}"
} ]
Something to do when adding a item to a Dictionary when the key is null. Problem is, I don't see any nulls when I debug on my end, activity1 is there, RootNode is there, TypeKey is a const string.
I'm almost wondering if I should just keep the created nodes within a array or Dictionary myself and then just working with the NodeReference. That's what I'm going to try next.
Later that morning
This seems to load everything into the graph database fine:
var activityNodes = _activityTasks.GetAll().ToDictionary(a => a.Id, a => _graphClient.Create(a, new ActivityBelongsTo(_graphClient.RootNode)));
foreach (var p in _placeTasks.GetAll())
{
var placeNode = _graphClient.Create(p, new PlaceBelongsTo(_graphClient.RootNode));
foreach (var activity in p.Activities)
{
_graphClient.CreateRelationship(placeNode, new PlaceHasActivity(activityNodes[activity.Id]));
}
}
foreach (var u in _userTasks.GetAllUserGraph())
{
var userNode = _graphClient.Create(u, new UserBelongsTo(_graphClient.RootNode));
foreach(var activity in u.Activities)
{
_graphClient.CreateRelationship(userNode, new UserParticipatesIn(activityNodes[activity.Id]));
}
}
Now the problem is similar to what I had before. Now I want to get an activity that has a relationship to the RootNode:
Node<Activity> activity = _graphClient
.RootNode
.In<Activity>(ActivityBelongsTo.TypeKey, a => a.Id == 1)
.SingleOrDefault();
Throwing the key value can't be null exception again. I think I need to investigate the gremlin syntax more. I'm guessing the problem is there.
This afternoon
Started to experiment with Gremlin queries:
g.v(0).inE.filter{it.label=="ACTIVITY_BELONGS_TO"}.outV.filter{it.Id==1}.Name
works fine. I tried to replicate that using neo4jClient syntax:
_graphClient.RootNode.InE(ActivityBelongsTo.TypeKey).OutV(b => b.Id == 1).SingleOrDefault();
Same null exception, it spits out:
g.v(p0).inE.filter{ it[p1].equals(p2) }.outV.filter{ it[p3] == p4 }.drop(p5).take(p6)._()
which looks right to me, except for the end. Ran this though:
g.v(0).inE.filter{it.label=="ACTIVITY_BELONGS_TO"}.outV.filter{it.Id==1}.drop(0).take(1)._()
And that works fine. Something stinks here...maybe I should try the other library although I liked the de/serialization support. Sigh...
Thought maybe a raw query would work. Nope! This method no longer accepts a string and the required GremlinQuery I have no idea how to you. Grooooooooooooooooan.
var users = graphClient.ExecuteGetAllNodesGremlin<IsCustomer>("g.v(0).out('IsCustomer'){it.'Name' == 'BobTheBuilder'}");
Update 3/30/12
Created a new project, everything below works fine. Super confused why it will work here... :( Maybe version differences, I have no idea.
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
client.Create(new User { Id = 1, Username = "joe" }, new UserBelongsTo(client.RootNode));
client.Create(new User { Id = 2, Username = "cloe" }, new UserBelongsTo(client.RootNode));
client.Create(new Activity { Id = 1, Name = "Bocce Ball" }, new ActivityBelongsTo(client.RootNode));
client.Create(new Activity { Id = 2, Name = "Programming" }, new ActivityBelongsTo(client.RootNode));
var user = client.RootNode.In<User>(UserBelongsTo.TypeKey, u=>u.Id == 1).SingleOrDefault();
var activity = client.RootNode.In<Activity>(ActivityBelongsTo.TypeKey, a=>a.Id == 1).SingleOrDefault();
client.CreateRelationship(user.Reference, new Plays(activity.Reference));
user = client.RootNode.In<User>(UserBelongsTo.TypeKey, u => u.Id == 1).SingleOrDefault();
activity = client.RootNode.In<Activity>(ActivityBelongsTo.TypeKey, a => a.Id == 1).SingleOrDefault();
I'm just getting started too. I would suggest you check out this blog:
http://romikoderbynew.com/2011/07/30/neo4jclient-primer/
Also, check http://frictionfree.org and its source code (in the about section) for more examples.
Creating relationships on existing - as I understand, this is possible. However, it appears to be easier to associate nodes as you create them. From the blog:
You can also create relationships between existing nodes.
graphClient.CreateRelationship(customerNodeReference, new
Speaks(languageNode.Reference));
RootNode - I believe you need to start a query from a node, I don't think you can do a
SELECT * FROM ... WHERE
Therefore, it would make sense that you need to attach nodes to the root node. This is an example from the FrictionFreeApp:
var node = graphClient.Create(
user,
new UserBelongsTo(rootNode));