【问题标题】:Is there an Count Function for Row Counts which works with ELSE Function?是否有适用于 ELSE 函数的行计数计数函数?
【发布时间】:2019-04-02 15:19:23
【问题描述】:

我有一个代码应该显示凭证详细信息。如果没有凭证,则应显示任何内容。 我们使用 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> 

【问题讨论】:

    标签: salesforce ampscript salesforce-marketing-cloud


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      这可以写成

      IF NOT EMPTY (@voucherRows) THEN
      
      // No of statements 
      
      ELSE 
      // statements
      
      ENDIF
      

      谢谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多