首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IF语句的AmpScript问题

IF语句的AmpScript问题
EN

Stack Overflow用户
提问于 2015-02-19 20:01:21
回答 2查看 2.4K关注 0票数 1

我正在尝试使用ampscript在确切的target中查找两个不同的数据扩展。请找到我正在尝试的示例代码。

代码语言:javascript
复制
%%[
Var @rows
Set @rows=LookupRows("DataExtensionOne","Lead Owner","Nick")
FOR @y = 1 TO RowCount(@rows) DO 
    Set @currentRow = Row(@rows,@y)    
    Set @value = FIELD(@currentRow ,"LeadId")
    Set @secondDERows = LookupRows("DataExtensionTwo","Gender","Male")
    FOR @x = 1 TO RowCount(@secondDERows) DO 
        Set @currentRowInSecDE = Row(@secondDERows,@x)    
        Set @secValue = FIELD(@currentRowInSecDE ,"LeadId")
        IF @value == @secValue THEN
            Set @FirstName = FIELD(@currentRowInSecDE ,"FirstName")
        /* Need to break out of the loop */
]%%

If条件检查似乎失败@value == @secValue。它不会获取@FirstName的任何值。应该使用什么语句来跳出IF循环?

有没有人遇到过类似的问题?请务必让我知道。

EN

回答 2

Stack Overflow用户

发布于 2015-11-27 07:32:45

据我所知,ampscript没有break操作符。

在本例中,我将设置一个布尔值,该值在每次循环开始时检查为false,并在找到匹配项时设置为True。这样,一旦匹配成功,您仍然会遍历循环的其余部分,但在它们之间不会发生任何事情。

代码语言:javascript
复制
%%[
Var @rows
Set @found_result = False
Set @rows=LookupRows("DataExtensionOne","Lead Owner","Nick")
FOR @y = 1 TO RowCount(@rows) DO
    if not @found_result then
        Set @currentRow = Row(@rows,@y)    
        Set @value = FIELD(@currentRow ,"LeadId")
        Set @secondDERows = LookupRows("DataExtensionTwo","Gender","Male")
        FOR @x = 1 TO RowCount(@secondDERows) DO 
            if not @found_result then
                Set @currentRowInSecDE = Row(@secondDERows,@x)    
                Set @secValue = FIELD(@currentRowInSecDE ,"LeadId")
                IF @value == @secValue THEN
                    Set @FirstName = FIELD(@currentRowInSecDE ,"FirstName")
                    Set @found_result = True
                ENDIF
            endif
        NEXT @x
    endif
NEXT @y
]%%
票数 1
EN

Stack Overflow用户

发布于 2016-09-24 07:26:42

代码语言:javascript
复制
%%[
Var @rows
Set @found_result = False
Set @rows=LookupRows("DataExtensionOne","Lead Owner","Nick")
    FOR @y = 1 TO RowCount(@rows) DO
    if  @found_result == "TRUE" then
        Set @currentRow = Row(@rows,@y)    
        Set @value = FIELD(@currentRow ,"LeadId")

Set @secondDERows = LookupRows("DataExtensionTwo","Gender","Male")

        FOR @x = 1 TO RowCount(@secondDERows) DO 
            if @found_result == "TRUE" then
                Set @currentRowInSecDE = Row(@secondDERows,@x)    
                Set @secValue = FIELD(@currentRowInSecDE ,"LeadId")
                IF @value == @secValue THEN
                    Set @FirstName = FIELD(@currentRowInSecDE ,"FirstName")
                    Set @found_result = True
                ENDIF
            endif
        NEXT @x
    endif
NEXT @y
]%%
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28605861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档