javascript - Add label to emails in Gmail fails -


We are trying to add labels to Gmail in threads. Versace added the same output "2014 / October / Sent" but only SentLabel2 works, if we set the centered label to thread [i] .addLabel (SentLabel); This fails.

We need to get it to St.Label. We have done an auto-month job like this (which is available in the calendar month, thus we need to go to the script manually every month and do not need to change variables. Is):

  var SentLabel = "2014 /" + month order [d.getMonth ()] + "/ sent";  

It looks like now:

  function wtf2 () {var SentLabel = "2014 / October / Sent"; Var sentLabel2 = GmailApp.getUserLabelByName ("2014 / October / Sent"); Var thread = GmailApp.getInboxThreads (0, 5); (Var i = 0; i & lt; threads.length; i ++) for {var labels = thread [i] .getLabels () [0]; Formula [i] .addLabel (SentLabel); }}   

The reason your statement fails below is because SentLabel is a string variable , Not a GmailLabel variable

thread [i] .addLabel (SentLabel);

To fix this, you can conditionally create a GmailLabel variable (I will call this variable label) depending on if it already exists. Here's how you can do it:

  var label = GmailApp.getUserLabelByName (SentLabel); // declares a variable called a label and starts it for the price that is similar to the string as the string when searching GmailApp for any label if (label) {// if the Gmail mailing label Logger finds .log ('label exists'.); } Else {Logger.log ('The label does not exist. Make it.'); Label = GmailApp.createLabel (SentLabel); }  

Once it moves, you will have a label variable and your statement will work if you change it to:

  thread [ I] .addLabel (label);  

You can read about GmailLabel class here,


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -