首页 > 解决方案 > 是否有适用于 ELSE 函数的行计数计数函数?

问题描述

我有一个代码应该显示凭证详细信息。如果没有凭证,则应显示任何内容。我们使用 RowCount > 0 但如果 Data Extension 中没有任何内容,RowCount 似乎不会返回 0。

如何更改 If 语句或 ELSE 语句。


%%[
SET   @voucherXML = AttributeValue("Vouchers")    
// build a rowset from the XML
SET @voucherRows        = BUILDROWSETFROMXML(@voucherXML, "//voucher", 1)
SET @voucherNames       = BUILDROWSETFROMXML(@voucherXML, "//voucher//name", 1)
SET @voucherAmounts      = BUILDROWSETFROMXML(@voucherXML, "//voucher//amount", 1)      
]%%


%%[If RowCount(@voucherRows) > 0 Then
FOR @index = 1 TO RowCount(@voucherRows) DO
// retrieve the items form the rowset from 1 to the count of rows   
]%%



      <p class="bdetails__bill__title" style="font-family: sans-serif; font-weight: 400; letter-spacing: 0.07em; line-height: 1.8em; Margin: 0; font-size: 11px;">
        %%=FIELD(ROW(@voucherNames,@index),
          "Value")=%%
        </p>


      <p class="bdetails__bill__value" style="font-family: sans-serif; font-size: 13px; font-weight: 400; letter-spacing: 0.07em; line-height: 1.8em; Margin: 0; text-align: right;">
        -%%=FIELD(ROW(@voucherAmounts,@index),
          "Value")=%%
       </p>


  <!--
%%[
NEXT @index
]%% -->
 <!--%%[ELSE]%%-->

<h2 class="bdetails__title" style="color: #0b0b0b; font-family: sans-serif; font-weight: 600; line-height: 1.385em; Margin: 0; font-size: 24px; text-transform: uppercase; width: 100%; min-width: 100%; text-align: center;">
        Bestelldetails
      </h2>
 <!--%%[ENDIF]%%
--> </p> 

标签: salesforceampscriptsalesforce-marketing-cloud

解决方案


您可以通过先将值分配给变量然后引用该临时变量来解决此问题。尝试更改您的代码以执行以下操作:

SET @rowcount = RowCount(@voucherRows)
IF @rowcount >= 1 THEN

这应该可以解决问题。如果没有,您可以简单地使用该ISNULL功能。


推荐阅读