Date formatting in Google Scripts/Mail - Method not found Error - google-apps-script

I'm using a script to send mails from a spreadsheet and like to format the date. I'm using Utilities.formatDate and this works but gives me also an error: "Method formatDate(string,string,string) not found"
var message = "<p><b>Ressort: </b>" + CurrentRow[5] + "</p>" + "<p><b>Textart: </b>" + CurrentRow[7] + "</p>" + "<p><b>Domain: </b>" + CurrentRow[6] + "</p>" + "<p><b>Thema: </b>" + CurrentRow[8] + "</p>" + "<p><b>Deadline: </b>" + Utilities.formatDate(CurrentRow[2], "GMT+2" , "dd.MM.yyyy") + "</p>";
How can I avoid this error?

You need Utilities.formatDate(Date, String, String).
CurrentRow[2] is coming up as type String, instead of Date.
If CurrentRow[2] is of a format that the Date object can parse, then try wrapping it in new Date(CurrentRow[2]).

Related

SSRS Expression Assistance

So I have an expression that does a good job of outputting data on a report. However, I want to be able to sum/combine the fields.
Here is the original expression.
= trim(Fields!Cost_Element_User_Define_1.Value)
+ " " + FormatCurrency(Fields!Billable_Equipment.Value)
+ " " + trim(Fields!Cost_Element_User_Define_2.Value)
+ " " + FormatCurrency(Fields!Billable_Material.Value)
+ " " + trim(Fields!Cost_Element_User_Define_3.Value)
+ " " + FormatCurrency(Fields!Billable_Labor.Value)
What I would like to do is combine group/sum billable_material.value.
How would I go about doing that?

How to convert datetime which is in Text format in Excel to yyyy-mm-dd HH-MM-ss in ssis derived column Expression

I was trying this expression but still getting error
((DT_STR,4000,1252)(LEFT(TOKEN([Date] ,"/",1),4) + "-" + RIGHT("0" + TOKEN([Date] ,"/",2),2) + "-" + RIGHT("0" + TOKEN([Date] ,"/",3),2) + " " ++ " " + TOKEN([Date] ,":",4)+ "-" + RIGHT("0" + TOKEN([Date] ,":",5),2) + "-" + RIGHT("0" + TOKEN([Date] ,":",6),2)))
Personally, I would use a script task. This assumes your string will always Parse to a DateTime. If not, look into TryParse().
Also, ParseExact() is even better but you didn't provide an example.
DateTime dt = DateTime.Parse(your date string);
string dtFormatted = dt.ToString("yyyy-MM-dd hh:mm:ss");
I will add one more caveat. You should probably treat this as a date and only format the date on the presentation layer.

Wrap Gmail body text when using app script

I have the app script below and it is working fine except sometimes it wrap the text when it sends the email to the requester however, this is not happening when I try it on my email. It's only happening on clients emails
https://i.stack.imgur.com/rK0PM.jpg
It doesn't happen when I try it on my personal email. See below:
https://i.stack.imgur.com/CPEOV.jpg
let msg = "Your leave for " + n + " from (" + d + ") to (" + o + ") for " + days + " day(s) has been approved by your supervisor on " + now;
Logger.log(msg);
GmailApp.sendEmail(email, "Your Leave Has Been Approved", msg)}

Enclosing the content of object in double quotes in VBA

It probably sounds simple, but I can not find a way out.
I'm trying to create a more or less dynamic json and I need to convert the content of object to a string between double quotes. Something like that :
""" + object + """ gives the following result "object" and the expected result would be "content of object".
Here is my code, will probably be more clear, about what it's about.
Dim jsTest As String
jsTest = """ + CStr(Msg.Subject) + """ + """ + CStr(Msg.Body) + """
Msg.Subject and Msg.Body are objects from Email. I can do that this way(with single quotes):
Dim smry, descrp, jsTest As String
smry = """summary"""
descrp = """description"""
jsTest = "{" + smry + ":" + "'" + CStr(Msg.Subject) + "'" + "," + descrp + ":" + "'" + CStr(Msg.Body) + "'" + "}"
but then I get content of object as String with single quotes and I cant put it in my JSON like so:
{"summary": 'Release 18.20 Produktion', "description": 'Guten Tag Sie erhalten diese Terminanfrage'}
How can I get result like (Note double quotes):
{"summary": "Release 18.20 Produktion", "description": "Guten Tag Sie erhalten diese Terminanfrage"}
If you replace this:
jsTest = "{" + smry + ":" + "'" + CStr(Msg.Subject) + "'"
with
jsTest = "{" + smry + ":" + """" + CStr(Msg.Subject) + """"
and so on, you will get your quotes.

SSRS - Expression to create string for reporting heading

I have a report which has 6 parameters within it. What I would like to do is make these parameters part of my report heading. My parameters are as follows:
#BMDataType1 Text
#BMDataComp1 Float
#BMDataType2 Text
#BMDataComp2 Float
#BMDataType3 Text
#BMDataComp3 Float
There will always be an #BMDataType1 and #BMDataComp1 parameter passed, the others can be null. What I need the heading to look like is if only #BMDataType1 and #BMdataComp1 are passed then the heading should be for example:
Benchmark1 100% Benchmark Constituents
So far I have coded for this below:
=Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " Benchmark Constituents"
However if #BMDataType2 and #BMDataComp2 are populated then I need the heading to look like this:
Benchmark1 50% Benchmark2 50% Benchmark Constituents
Same for if 3 are passed then:
Benchmark1 50% Benchmark2 30% Benchmark3 20% Benchmark Constituents
There will never be say a Benchmark 1 and Benchmark 3. It will only be ever 1, or 1 and 2 or 1, 2 and 3.
Can someone point me in the right direction of how to write the IIF statement for this checking to see if Benchmark2 and Benchmark3 parameters are NULL?
Thanks
EDIT:
After some work on this I came up with the following code, but I'm still getting:
"Object reference not set to an instance of an object"
My code is the following:
=IIF(
IIF(IsNothing(Parameters!BMDataType1.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=1 AND IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=1
, Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " Benchmark Constituents"
, IIF(
IIF(IsNothing(Parameters!BMDataType1.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=1
, Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " Benchmark Constituents"
, IIF(
IIF(IsNothing(Parameters!BMDataType1.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=0
, Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " " + Parameters!BMDataType3.Value + " " + Parameters!BMDataComp3.Value.ToString + "%" + " Benchmark Constituents"
, " ")))
However if all 3 parameters are not null it returns no error and it populates the heading as I would like it displayed. How can this be?
I have not been using SSRS since May, but string concatination in SSRS use VB syntax. So instead of concat strings with a + sign, you have to use the & sign.
=Parameters!BMDataType1.Value & " " & Parameters!BMDataComp1.Value.ToString & "%" & " Benchmark Constituents"
I found the solution to this and my code is as of below:
=Parameters!BMDataType1.Value + " " + CStr(Parameters!BMDataComp1.Value) + "% "
+ IIF(IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=0,Parameters!BMDataType2.Value + " " + CStr(Parameters!BMDataComp2.Value)+"%","") + " "
+ IIF(IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=0,Parameters!BMDataType3.Value + " " + CStr(Parameters!BMDataComp3.Value)+"%","") + " Benchmark Constituents"
For whatever reason it was not liking the .ToString which was returning "Oject reference not set to an instance of an object". By wrapping this in CStr I was able to remove the error and get the solution I required.
Thanks for all the responses, they all helped.
Something like this should work for you:
=Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + IIf(IsNothing(Parameters!BMDataType3.Value) OR IsNothing(Parameters!BMDataComp3.Value), IIf(IsNothing(Parameters!BMDataType2.Value) OR IsNothing(Parameters!BMDataComp2.Value), " Benchmark Constituents", " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " Benchmark Constituents"), " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " " + Parameters!BMDataType3.Value + " " + Parameters!BMDataComp3.Value.ToString + "%" + " Benchmark Constituents")