DATA EXTENSION LOOKUP FUNCTIONS

 DATA EXTENSION LOOKUP FUNCTIONS


LET'S CONSIDER WE HAVE A DATA MODEL FOR ORDERS AS DEPICTED ABOVE AND WE WOULD LIKE TO PERSONALIZE OUR EMAIL FOR ORDERS

LookUp

Returns specified value from a data extension.



AMPSCRIPT BLOCK : LOOKUP PRODUCT WHERE ORDER  ID =1

%%[
SET @subscriberkey=_subscriberkey
SET @email=emailaddr
SET @Orderid=1
SET @customerId=LookUp('ORDERS','CUSTOMERID','ORDERID',@Orderid)
SET @productId=LookUp('ORDER_DETAILS','PRODUCTID','ORDERID',@Orderid)
SET @ContactName=LookUp('CUSTOMERS','CONATACTNAME','CUSTOMERID',@customerId)
SET @productName=LookUp('PRODUCTS','PRODUCTNAME','PRODUCTID',@productId)
SET @productPrice=LookUp('ORDERS','UNITPRICE','ORDERID',@Orderid)
SET @productPackagingDate=LookUp('ORDERS','SHIPDATE','ORDERID',@Orderid)
]%%

 %%=v(Concat('Hello ',@ContactName,','))=%%
<p>Please find your invoice details</p>
<div><b>Product Details</b></div>
<div></div>
<div><b>Name </b>: %%=v(UPPERCASE(@productName))=%%</div>
<div><b>Price</b> :%%=v(FORMATCURRENCY(@productPrice,'en-US',3))=%%</div>
<div><b>Packaging Date </b>:
            %%=v(FORMATDATE(@productPackagingDate,'MMM DD, YYYY'))=%%</div>



AMPSCRIPT BLOCK : LOOKUP PRODUCT WHERE ORDER ID =1 AND EMPLOYEE ID=12345


%%[
SET @subscriberkey=_subscriberkey
SET @email=emailaddr
SET @Orderid=1
SET @customerId=LookUp('ORDERS','CUSTOMERID',
                        'ORDERID',@Orderid,
                        'EMPLOYEEID',12345)
SET @productId=LookUp('ORDER_DETAILS','PRODUCTID','ORDERID',@Orderid,'DISCOUNT',20)
SET @ContactName=LookUp('CUSTOMERS','CONATACTNAME','CUSTOMERID',@customerId)
SET @productName=LookUp('PRODUCTS','PRODUCTNAME','PRODUCTID',@productId)
SET @productPrice=LookUp('ORDERS','UNITPRICE','ORDERID',@Orderid)
SET @productPackagingDate=LookUp('ORDERS','SHIPDATE','ORDERID',@Orderid)
]%%

 %%=v(Concat('Hello ',@ContactName,','))=%%
<p>Please find your invoice details</p>
<div><b>Product Details</b></div>
<div></div>
<div><b>Name </b>: %%=v(UPPERCASE(@productName))=%%</div>
<div><b>Price</b> :%%=v(FORMATCURRENCY(@productPrice,'en-US',3))=%%</div>
<div><b>Packaging Date </b>:
            %%=v(FORMATDATE(@productPackagingDate,'MMM DD, YYYY'))=%%</div>

AMPSCRIPT BLOCK : LOOKUP PRODUCT WHERE  ORDER ID =1 AND EMPLOYEE ID=12345 AND SHIPDATE IS TODAY

%%[
SET @subscriberkey=_subscriberkey
SET @email=emailaddr
SET @Orderid=1
SET @customerId=LookUp('ORDERS','CUSTOMERID',
                        'ORDERID',@Orderid,
                        'EMPLOYEEID',12345,
                        'ORDERDATE',NOW())
SET @productId=LookUp('ORDER_DETAILS','PRODUCTID','ORDERID',@Orderid,'DISCOUNT',20)
SET @ContactName=LookUp('CUSTOMERS','CONATACTNAME','CUSTOMERID',@customerId)
SET @productName=LookUp('PRODUCTS','PRODUCTNAME','PRODUCTID',@productId)
SET @productPrice=LookUp('ORDERS','UNITPRICE','ORDERID',@Orderid)
SET @productPackagingDate=LookUp('ORDERS','SHIPDATE','ORDERID',@Orderid)
]%%

 %%=v(Concat('Hello ',@ContactName,','))=%%
<p>Please find your invoice details</p>
<div><b>Product Details</b></div>
<div></div>
<div><b>Name </b>: %%=v(UPPERCASE(@productName))=%%</div>
<div><b>Price</b> :%%=v(FORMATCURRENCY(@productPrice,'en-US',3))=%%</div>
<div><b>Packaging Date </b>:
            %%=v(FORMATDATE(@productPackagingDate,'MMM DD, YYYY'))=%%</div>

 %%=v(Concat('Hello ',@ContactName,','))=%%
<p>Please find your invoice details</p>
<div><b>Product Details</b></div>
<div></div>
<div><b>Name </b>: %%=v(UPPERCASE(@productName))=%%</div>
<div><b>Price</b> :%%=v(FORMATCURRENCY(@productPrice,'en-US',3))=%%</div>
<div><b>Packaging Date </b>:
            %%=v(FORMATDATE(@productPackagingDate,'MMM DD, YYYY'))=%%</div>


AMPSCRIPT BLOCK : 
LOOKUP PRODUCT WHERE PRODUCT ID =1 AND GENDER='WOMEN' AND SEASON='WINTER'  , IF NO PRODCT IS FOUND RAISE ERROR


%%[
SET @subscriberkey=_subscriberkey
SET @email=emailaddr
SET @Orderid=1
SET @customerId=LookUp('ORDERS','CUSTOMERID',
                        'ORDERID',@Orderid,
                        'EMPLOYEEID',12345,
                        'ORDERDATE',NOW())
SET @productId=LookUp('ORDER_DETAILS','PRODUCTID','ORDERID',@Orderid,'DISCOUNT',20)
SET @ContactName=LookUp('CUSTOMERS','CONATACTNAME','CUSTOMERID',@customerId)
SET @productName=LookUp('PRODUCTS','PRODUCTNAME','PRODUCTID',@productId)
SET @productPrice=LookUp('ORDERS','UNITPRICE','ORDERID',@Orderid)
SET @productPackagingDate=LookUp('ORDERS','SHIPDATE','ORDERID',@Orderid)
]%%



%%[IF EMPTY(@productName) THEN
INSERTDE(
    'PERSONALIZATIONLOG',
   'ERRORMESSAGE','No Products found',
   'ERRORCODE','E003',
   'ERRORNUMBER','1234',
   'SUBSCRIBERKEY',_SUBSCRIBERKEY,
   'JOBID',JOBID
   )
   RAISEERROR('No Products found',1,'SHIPPING ERROR','1234',0) ]%%
%%[ ELSE ]%%
 %%=v(Concat('Hello ',@ContactName,','))=%%
<p>Please find your invoice details</p>
<div><b>Product Details</b></div>
<div></div>
<div><b>Name </b>: %%=v(UPPERCASE(@productName))=%%</div>
<div><b>Price</b> :%%=v(FORMATCURRENCY(@productPrice,'en-US',3))=%%</div>
<div><b>Packaging Date </b>:
            %%=v(FORMATDATE(@productPackagingDate,'MMM DD, YYYY'))=%%</div>

 %%=v(Concat('Hello ',@ContactName,','))=%%
<p>Please find your invoice details</p>
<div><b>Product Details</b></div>
<div></div>
<div><b>Name </b>: %%=v(UPPERCASE(@productName))=%%</div>
<div><b>Price</b> :%%=v(FORMATCURRENCY(@productPrice,'en-US',3))=%%</div>
<div><b>Packaging Date </b>:
            %%=v(FORMATDATE(@productPackagingDate,'MMM DD, YYYY'))=%%</div>
%%[ ENDIF ]%%






Comments


Knowledge Article

Most Viewed

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Journey Builder REST API Documentation

Preference Center Demystified

Popular Posts

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Journey Builder REST API Documentation

Preference Center Demystified

SEND LOG EANBLEMENT

Share with Friends

Disclaimer:

The information provided on this technical blog is for general informational purposes only. As a SFMC (Salesforce Marketing Cloud) Technical Architect, I strive to offer accurate and up-to-date content related to SFMC and its associated technologies. However, please note that technology is constantly evolving, and the information provided may become outdated or inaccurate over time.

The content published on this blog represents my personal views and experiences as a SFMC Technical Architect and does not necessarily reflect the official views or opinions of any organization or employer I may be affiliated with.

While I make every effort to ensure the accuracy and reliability of the information presented, I cannot guarantee its completeness, suitability, or applicability to your specific circumstances. Therefore, it is essential to verify any information provided and make your own independent assessments or seek professional advice if needed.

Furthermore, any actions taken based on the information provided on this blog are at your own risk. I shall not be held liable for any damages, losses, or inconveniences arising from the use of the information presented here.

Please keep in mind that SFMC and its associated technologies are complex and require technical expertise for proper implementation and management. It is recommended to consult with qualified professionals or official SFMC documentation for comprehensive guidance.

Finally, please note that any product or company names mentioned on this blog are trademarks or registered trademarks of their respective owners. The mention of these trademarks or registered trademarks does not imply any endorsement or affiliation with the blog.

By accessing and using this blog, you agree to the terms of this disclaimer. If you do not agree with any part of this disclaimer, please refrain from using this blog.