Invalid value specified for function parameter. Function Name: DatePart Parameter Name: Date Parameter - ampscript

I have a landing page that allows you to insert the contact data modifier. For the modification on I must first retrieve the contact information dynamically. That I want to launch the page I am displayed an error message that relates to the date:
Invalid value specified for the function parameter. Function Name: DatePart Parameter Name: Date Parameter
This is my code AMPScript:
/* SET #date = field(#date,"BIRTHDATE")*/
SET #year = DatePart(#date,"Y")
SET #month = DatePart(#date,"M")
SET #day = DatePart(#date,"D")
IF
EMPTY(#date) AND ISNULL(#date) THEN SET #Date=""
ELSE
SET #Date=CONCAT(#day,"/",#month,"/",#year)
ENDIF

Related

How to add current datetime in POST API request?

I want the start and end date to be in current datetime. I don't know whether it is possible. I need that because I want to trigger the data everyday using my pipeline.
You can create an environment variable in the pre-request-script of the request and then use that variable in the body
var now = new Date();
var timestamp = now.toISOString(); //or whatever format you want.
pm.environment.set("timestamp", timestamp);
You could use moment to make this easier for you. Add this to the pre-request script:
let moment = require('moment');
pm.variables.set('startOfDay', moment().utc().startOf('day').format('YYYY-MM-DD HH:mm:ss'));
pm.variables.set('endOfDay', moment().utc().endOf('day').format('YYYY-MM-DD HH:mm:ss'));
The use the {{startOfDay}} and {{endOfDay}} variables where you need them.
You can remove "start" and "end" from the body of the request and then using Postman's Pre-request Script section (next to Body), add the following lines:
// Gets current UTC time in the format "yyyy-MM-dd"
const UTCDate = (new Date()).toISOString().split("T")[0];
// Removes manually set values for "start" and "end", if present
pm.request.body.urlencoded.remove(param => param.key === "start" || param.key === "end");
// Adds a parameter "start" set to UTC midnight
pm.request.body.urlencoded.add({ key: "start", value: `${UTCDate}T00:00:00.000Z` });
// Adds a parameter "end" set to just before UTC midnight of the next day
pm.request.body.urlencoded.add({ key: "end", value: `${UTCDate}T23:59:59.999Z` });

How to add a dynamic variable value inside a param field as a String in Karate?

I have an API, wherein the Param field, I need to pass the current date as a string.
And param filter = 'ORDER_DATE:"2021-01-31"'
I am trying to pass the current date for the ORDER_DATE field form a java method:
* def todaysDate = helper.getTodaysDate()
And print todaysDate // Prints 2021-02-04
Now I need to pass this "todaysDate " valuein the param filter field.
Following what I have tried so far:
And param filter = 'ORDER_DATE:#(todaysDate )'
And param filter = 'ORDER_DATE:<todaysDate>'
From example table value.
In Both cases, it printed "todaysDate " instead of its value "2021-02-04"
It is just JavaScript:
And param filter = 'ORDER_DATE:"' + todaysDate + '"'
This can improve in the 1.0 version BTW:
And param filter = `ORDER_DATE:"${todaysDate}"`
Further reading: https://github.com/intuit/karate#rules-for-embedded-expressions

how to set current month as default value on simple parameter on pentaho cde?

I have a simple parameter where I should pass the first day of current month.
What should I write on property value?
You can create a custom parameter, which allows you to set it to the return value of a Javascript function:
function(){
var now = new Date();
return now.getMonth() + 1;
}
When you load the dashboard the parameter will be calculated and will have an integer value between 1 and 12.
If you want the parameter to have as value the date string for day 1 of this month you can instead use
function(){
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth()+1;
m = (m<10 ? '0' : '') + m;
var d = '01';
return y + '-' + m + '-' + d;
}
This will return the date as a string in the format yyyy-MM-dd for day 1 of the current month.
As far as i know, the properties file cannot have a formula that will calculate on run time when you use the value.
What you can do instead, is in the beggining of your Job have a KTR that will set this variable for you.
You KTR should look something like this:
Set the parameter date_mois (exact same name) in your Root Job, and this variable will be passed down to subsequent KTR / JOB calls (This is default unless uncheked).

.NET SqlParameter constructor inconsistent?

Can anyone tell me what is going on in this function??
In the following code snippet, user.Id = 0, id.Value = 0 and id.SqlDbType = Int.. as expected since user.Id is an int field.
However, error.Value = null and error.SqlDbType = BigInt. What gives? If I use non-zero it detects an int and the correct value.
Note: the Value properties are the same before and after declaring the parameter direction.
public static long InsertUpdate(User user) {
SqlParameter id = new SqlParameter("#id", user.Id);
id.Direction = ParameterDirection.InputOutput;
cmd.Parameters.Add(id);
SqlParameter error = new SqlParameter("#error_code", 0);
error.Direction = ParameterDirection.Output;
cmd.Parameters.Add(error);
.... other stuff
}
As well, if #SET #error_Code = 0 in the sproc, error.Value = NULL and error.SqlDbType = NVarChar AFTER the procedure runs. If I set it to an integer I get an Int type.
UPDATE:
After specifying SqlDbType.Int the parameter now has the correct SqlDbType before and after the command... however the stored procedure is still setting #error_code = null when I in fact set it to 0.
UPDATE:
When the sproc executes the SELECT statement the #error_code parameter is always returned as null, regardless of when or not it has been set... this only happens when there's a select statement...
Here is the procedure to reproduce:
ALTER PROCEDURE [dbo].[usp_user_insert_v1]
#username VARCHAR(255),
#password VARCHAR(255),
#gender CHAR(1),
#birthday DATETIME,
#error_code INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE #default_dt DATETIME
EXEC #default_dt = uf_get_default_date
DECLARE #dt DATETIME = GETUTCDATE()
INSERT INTO users(username, password, gender, birthday, create_dt, last_login_dt, update_dt, deleted)
VALUES(#username, #password, #gender, #birthday, #dt, #default_dt, #default_dt, 0)
SELECT * FROM users WHERE id = SCOPE_IDENTITY()
SET #error_code = 3
RETURN
END
SOLUTION?
http://forums.asp.net/t/1208409.aspx?Interesting+problem+with+getting+OUTPUT+parameters+from+SQL+Server+using+C+
Found this link on the ASP forums... apparently you can't read the output parameter until you have read all the results from the SqlDataReader... very unfortunate for me since I decide whether or not I even WANT to read the results based on the output param...
From SqlParameter.Value on MSDN
For output and return value parameters, the value is set on completion of the SqlCommand
i.e. I wouldn't rely on type inference to set the return type implicitly.
I would explicitly set the type of the output parameter:
var error = new SqlParameter("#error_code", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
Edit
After some reflection of SqlParameter:
The BigInt is easy to explain - it is the default SqlDbType, and the SqlParameter(string parameterName, object value) ctor doesn't overwrite this value.
public enum SqlDbType
{
BigInt = 0,
...
Re: #error_code is returned as NULL
The only thing I can think of is that the PROC fails to complete cleanly. Try moving the SET #error_code = 0 above the EXEC #default_dt = uf_get_default_date ?
Edit
Confirmed, #Damien's point is correct
SqlParameter error = new SqlParameter("#error_code", 0);
Actually calls this ctor:
public SqlParameter(string parameterName, SqlDbType dbType)
whereas
SqlParameter error = new SqlParameter("#error_code", 1234);
calls
public SqlParameter(string parameterName, object value)
Reason : 0 is implicitly castable to enum.
Both of the current answers are slightly incorrect because they're based on the assumption that the constructor being called for your error object is the (string,object) one. This is not the case. A literal 0 can be converted to any enum type1, and such a conversion would be preferred over a conversion to object. So the constructor being called is the (string,SqlDbType) constructor.
So the type is set to BigInt because that's the 0 value for the SqlDbType enumeration, and the Value is null because you have no code that attempts to set the value.
SqlParameter error = new SqlParameter("#error_code", (object)0);
should cause it to select the correct overload.
Demo:
using System;
using System.Data;
namespace ConsoleApplication
{
internal class Program
{
private static void Main()
{
var a = new ABC("ignore", 0);
var b = new ABC("ignore", (object)0);
var c = new ABC("ignore", 1);
int i = 0;
var d = new ABC("ignore", i);
Console.ReadLine();
}
}
public class ABC
{
public ABC(string ignore, object value)
{
Console.WriteLine("Object");
}
public ABC(string ignore, SqlDbType value)
{
Console.WriteLine("SqlDbType");
}
}
}
Prints:
SqlDbType
Object
Object
Object
1From the C# Language specification, version 5, section 1.10 (that is, just in the introduction to the language, not buried deep down in the language lawyery bits):
In order for the default value of an enum type to be easily available, the literal 0 implicitly converts to any enum type. Thus, the following is permitted.
Color c = 0;
I'd have also thought this important enough to be in the Language Reference on MSDN but haven't found a definitive source yet.
Well, it looks like the most reliable way of doing it is by using this overload:
SqlParameter error = new SqlParameter("#error_code", SqlDBType.Int);
error.Value = 0;
The overload you're using takes an object as a parameter, and for some reason which I can't divine, it's not picking the right type.

Dapper SqlDateTime overflow using GETDATE() in SQL Server

I have the following code which gets the input from a form and calls a stored procedure to store it in a database.
[HttpPost]
public ActionResult Index(GuestMessage model)
{
if (ModelState.IsValid)
{
using(IDbConnection conn = DatabaseAcess.OpenConnection())
{
const string storedProcedure = "dbo.InsertMessage";
conn.Execute(storedProcedure, new GuestMessage { Name = model.Name, Email = model.Email, Message = model.Message }, null, null, CommandType.StoredProcedure);
return View("ThankYou");
}
}
return View();
}
There are three fields, Name, E-mail and Message that have to be filled in by the user. In the database I store the data that the user enters, from these three fields, and the time of the entry using a stored function called dbo.Insert Message.
BEGIN
BEGIN TRAN
SET NOCOUNT ON;
DECLARE #GuestID int;
INSERT INTO Guest(Name, Email) VALUES (#Name, #Email);
SELECT #GuestID = scope_identity();
INSERT INTO Message (EntryDate, GuestID, Message, Status)
VALUES (GETDATE(), #GuestID, #Message, 2);
COMMIT TRAN
END
Notice that I do not pass the entry date and time as an input parameter to the stored procedure since there is no need for that. I use the built-in function GETDATE() in SQL Server to determine the time a user has entered a message.
However, whenever I try to enter a message I get the following error:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00AM and 12/31/9999 11:59:59PM
I would suggest the following change:
conn.Execute(storedProcedure,
new { Name = model.Name, Email = model.Email, Message = model.Message },
commandType: CommandType.StoredProcedure);
The only actual change there is that I have swapped new GuestMessage { ... } for new { ... }. What I suspect is happening is that your GuestMessage type has additional properties that aren't needed, but which it is sending as parameters. A DateTime left at its default value is "00:00:00.0000000, January 1, 0001". By swapping to just new { ... }, we have explicitly limited the members we are sending to Name, Email and Message, because those are the only things defined.
Note: when using plain-text, dapper does use some voodoo to try to see which parameter names are actually used in the SQL, and it doesn't send anything that it knows isn't referenced in the SQL - however, it cannot do this with a stored procedure.