Inline AmpScript Help Needed - salesforce-marketing-cloud

Can the below 2 codes work as one inline ampScript on the html page? For example, the following is the copy I want to turn dynamic: Until 30 March 2023, you can get our boiler cover2 from £7.50 a month for your first 6 months. That’s half the usual price for the first 6 months, to help keep your boiler working safely and efficiently.
My two codes are :
'%%[
Set #field_energy_type = AttributeValue("energy_type")
If Empty(#field_energy_type) Or #field_energy_type = "" Then
Set #value_energy_type = " Until 30 March 2023..."
Else
Set #value_energy_type = ""
EndIf
]%%
%%[
SET #energy_type = "dual_fuel"
IF #energy_type == "electricity_only" THEN
SET #price = "£7.50"
ELSEIF #energy_type == "dual_fuel" THEN
SET #price = "£12"
ELSE
SET #price = "£7.50"
ENDIF
]%%'
And the following Ampscript based rules within the code I want to archive:
If the field energy_type is not empty then show the copy starting 'Until 30 March 2023... all the way until below the 'Sign me up' call to action.'
If the field energy_type = electricity_only then the price in the above paragraph should be £7.50 a month, if the field energy_type = dual_fuel then the price should be £12 per month.
Hope this helps.
Thanks in advance.
And the following Ampscript based rules within the code I want to archive:
If the field energy_type is not empty then show the copy starting 'Until 30 March 2023... all the way until below the 'Sign me up' call to action.'
If the field energy_type = electricity_only then the price in the above paragraph should be £7.50 a month, if the field energy_type = dual_fuel then the price should be £12 per month.
Hope this helps.
Thanks in advance.

Related

How do I query for the last 30 days of data in Power Query using JSON?

I would like to request the last 30 days of CrewHu Import data from today's date in this query. At the moment it is just set to get everything greater than the 25th September 2022 but I want to change this to be a dynamic value. Has anyone else had this problem / knows of a workaround?
let
Source = Json.Document(Web.Contents("https://api.crewhu.com/api" & "/v1/survey?query={""_updated_at"":{""$gte"":""2022-09-25T00:00:00.000Z""}}", [Headers=[X_CREWHU_APITOKEN="xxxxxxxxxxx"]])),
I've tried:
OneMonthAgo = Text.Replace(Text.Start (Text.From(Date.AddDays(DateTime.LocalNow(),-30)),10),"/","-") & "T00:00:00.000Z",
And calling this as a variable but because the string does not come with quotation marks it gives a syntax error when the variable is called in the 'Source = ' line.
Well, first you want
= Date.ToText(Date.From(Date.AddDays(DateTime.LocalNow(),-30)), [Format="yyyy-MM-dd"])& "T00:00:00.000Z"
since that returns 2022-09-28T00:00:00.000Z while yours returns 9-28-2022 T00:00:00.000Z which does not seem to be the original format
then try out this, which I cant test
let variable = Date.ToText(Date.From(Date.AddDays(DateTime.LocalNow(),-30)), [Format="yyyy-MM-dd"])& "T00:00:00.000Z",
Source = Json.Document(Web.Contents("https://api.crewhu.com/api" & "/v1/survey?query={""_updated_at"":{""$gte"":"""&variable&"""}}", [Headers=[X_CREWHU_APITOKEN="xxxxxxxxxxx"]]))
in Source

Code combination in microsoft access (yyxxxx format)

I'm struggeling with a part of code that I want to implement in Microsoft Access.
The required code is used for project asignments.
The code format contains the last 2 numbers of the year + 4 digits which add up until a new year, then the last 2 numbers of the year add up with 1 and the 4 digits start at 1 again.
For example:
2019:
190001 = first task;
190002 = second task;
etc...
2020:
200001 = first task;
200002 = second task;
etc...
Could anybody help me out how to code this in Microsoft Access, preferably by VBA?
This way I can asign the code to a "submit" button to avoid similar numbers.
Thanks!
Formatting your code given an integer could be achieved in several ways, here is one possible method:
Function ProjectCode(ByVal n As Long) As Long
ProjectCode = CLng(Format(Date, "yy") & Format(n, "0000"))
End Function
?ProjectCode(1)
200001
?ProjectCode(2)
200002
?ProjectCode(100)
200100
You probably need to assign the next task id to a project.
So, look up the latest id in use and add 1 to obtain the next task id:
NextTaskId = (Year(Date()) \ 100) * 10000 + Nz(DMax("TaskId", "ProjectTable", "TaskId \ 10000 = Year(Date()) \ 100"), 0) Mod 10000 + 1
Nz ensures that a task id also can be assigned the very first task of a year.

Is a "Try / Except ValueError UNLESS" possible?

I'm new to python and have been trying like hell for the past few hours to figure out how to get this to work properly...
It's very simple code I'm sure, but I'm just not getting it.
It should be pretty self-explanatory below in the code, but basically I'm asking a user to input the date of an event as an 'int' and if it's not a number, then ask them to try again... UNLESS it's a "?"
while True:
date = None
street = str(input('Name of street?: ').title())
city = str(input("In what city?: ").title())
while True:
try:
year = int(input("Date of event? (or '?'): "))
if date == "?":
break
except Exception:
print("That's not a date, try again!")
continue
break
It seems that it's not even getting to see IF because it gets caught by the 'except' before it can.
If you're going to display help or something when a '?' is input, then just call the function to display the help where you have the break currently.
if date == "?":
display_help()
continue
Then, split reading the input and processing it into two steps.
in = input("Date of event? (or '?'): ")
if in == "?":
display_help()
continue
year = int(in)
Also, you ask for a date but then assume that a year is entered, I'd be more explicit in your promt.
"Please enter the year of the event, ex: 1998"
or whatever form you actually want it in.
Trying using a valueError exception. Also I think in your post you mentioned you wanted to enter a date as integer, so I replaced year with the date. If you wanted the year to be an integer you can replace the variable date with year. If you wanted to the user to enter a year, day and month then this program needs to be redesigned a bit.
date = None
street = str(input('Name of street?: ').title())
city = str(input("In what city?: ").title())
while True:
date = input("Date of event? (or '?'): ")
if date == "?":
break
else:
try:
date = int(date)
except ValueError:
print("That's not a date, try again!")
continue
break

VBA code to analyze a HTML table based off certain conditions

So I need to screen scrape data off a website and return it to a spreadsheet based off if a charge amount matched as well the date was the most recent in the table. If there was simply one line in the table, the macro pulls that accordingly. So most of the code is good, I am connected to the website, pulling everything effectively. Where I am struggling is getting the logic to work where the two amounts match as well as the date being the most recent in the HTML table.
I guess what my question is how do I loop through Item(5) the column of that table and specify it to choose the most recent date, also setting the value so that it only finds the one equal to the charge amount. I only want a one to one match. I am new to this so if anyone wants to help me I would greatly appreciate it.
Set IHEC = iHTMLDoc.getElementsByTagName("TR")
If IHEC.Length > 2 Then
For index = 0 to IHEC.Length - 1
Set IHEC_TD = IHEC.Item(index).getElementsByTagName("TD")
Do Until IHEC.Length <2 Or index = IHEC.Length - 1
If IHEC.TD.Item(3).innerText = myBilledAmount Then
myItem1 = IHEC_TDItem(0).innerText
myItem2 = IHEC_TDItem(1).innerText
myItem3 = IHEC_TDItem(2).innerText
myItem4 = IHEC_TDItem(3).innerText
myItem5 = IHEC_TDItem(4).innerText
myItem6 = IHEC_TDItem(5).innerText
myItem7 = IHEC_TDItem(6).innerText
myItem8 = IHEC_TDItem(7).innerText
myItem9 = IHEC_TDItem(8).innerText
End If
End If
Loop
Next Index

get specific value from parameter

I have a multi-valued parameter TimeMonthOfYear(from cube) that contains January Februrary...December.
I want to set a default value showing current month using MonthName(Month(Today)) (I tried it and it didn't work) when running report...
If I do this [Time].[Month Of Year].&[October] it works! October is selected in dropdown after previous dropdown (Year) was selected.
I don't want to do it the "hard coded" way...I have tried
[Time].[Month Of Year].&[MonthName(Month(Today))] and
="[Time].[Month Of Year].&["&MonthName(Month(Today))&"]" without luck
Any help is very much appreciated!
Yup :) Well it's now working with may be a not so nice solution but will work for now with the help of vb code. in standard value I have ="[Time].[Month Of Year].&[" + Code.SetMonth() + "]" and custom code Function SetMonth() As String Dim x as STRING x =CStr(MonthName(Month(Today))) 'CStr not needed I think If x = "januari" Then x = "January" ElseIf x = "februari" Then x = "February" ... End If Return(x) End Function That is giving me the current month after selecting value in year drop-down :)