0

I have to create a landing page that allows the modification of an existing record and for that, I have to generate the information about the records so he can update it. I already finished the page with HTML and JS and when I add the AMPScript code I'm getting the following error message:

Invalid value specified for function parameter.

Function Name: DatePart
Parameter Name: Date
Parameter Ordinal: 1
Parameter Type: Date
Submitted Value: System.Data.DataRow
ClientID: 7221705
JobID: 0
ListID: 15425
BatchID: 0
SubcriberID: 327073156
Data Source Type: List

This is my AMP Script code:

%%[
  /* Set Variables here for easy editing */ 
  SET @uid = AttributeValue("UID_TARGET")
  SET @rows  = LookupRows("ENT.CUSTOMER_LOT_6", "UID_TARGET", @uid)
  SET @count = RowCount(@rows)
  IF (@count == 1) THEN
    SET  @row = row(@rows,1)
    SET @sexe = Uppercase(field(@row,"GENDER"))
    SET @firstname = field(@row,"FIRSTNAME")
    SET @lastname = field(@row,"SURNAME") 
    SET @email = field(@row,"EMAIL")
    SET @tel = field(@row,"PHONENUMBER")
    SET @date = field(@date,"BIRTHDATE")
    /*  SET @langue = field(@row,"PREFERRED_LANGUAGE" */
    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                   
  ENDIF
]%%
2

You made a mistake when reading the date-value into your variable, as you used the data-variable for the first parameter which should be the row to read from.

Instead of SET @date = field(@date,"BIRTHDATE") you need to use SET @date = field(@row,"BIRTHDATE")

Furthermore I think you might want to change the following if-statement from IF EMPTY(@date) AND ISNULL(@date) THEN to IF EMPTY(@date) THEN as the empty-function returns true if the variable is an empty string or null and therefore your current if-statement would only be true if date is null and changing to "OR" would lead to the same result as omitting ISNULL(@date).

Complete code:

%%[
  Var @uid, @rows, @count, @row, @sexe, @firstname, @lastname, @email, @tel, @date, @DateString, @year, @month, @day
  /* Set Variables here for easy editing */ 
  SET @uid = AttributeValue("UID_TARGET")
  SET @rows  = LookupRows("ENT.CUSTOMER_LOT_6", "UID_TARGET", @uid)
  SET @count = RowCount(@rows)
  IF (@count == 1) THEN
    SET  @row = row(@rows,1)
    SET @sexe = Uppercase(field(@row,"GENDER"))
    SET @firstname = field(@row,"FIRSTNAME")
    SET @lastname = field(@row,"SURNAME") 
    SET @email = field(@row,"EMAIL")
    SET @tel = field(@row,"PHONENUMBER")
    SET @date = field(@row,"BIRTHDATE",0)
    /*  SET @langue = field(@row,"PREFERRED_LANGUAGE") */   
    IF EMPTY(@date) THEN
      SET @DateString=""
    ELSE
      SET @year = DatePart(@date,"Y")
      SET @month = DatePart(@date,"M")
      SET @day = DatePart(@date,"D") 
      SET @DateString=CONCAT(@day,"/",@month,"/",@year)                 
    ENDIF                   
  ENDIF
]%%

Related documentation:

2
  • thank you Markus for your update but i still have the same error message: Invalid value specified for function parameter. Function Name: DatePart Parameter Name: Date Parameter Ordinal: 1 Parameter Type: Date Submitted Value: System.Data.DataRow ClientID: 7221705 JobID: 0 ListID: 15425 BatchID: 0 SubcriberID: 327073156 Data Source Type: List – Wassim Jun 16 '17 at 19:06
  • Another thing I can think of is that there is a problem with having one @date and another @Date variable, maybe rename one of them (I did this in my answer). From the error message it seems like you are passing a variable containing a date to the Field-function, which should be fixed in the code presented in my answer. Furthermore I moved construction of the dateparts into the else as it can only be done if date is set. – Markus Slabina Jun 16 '17 at 19:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.