Search code examples
if-statementconditional-statementsimacros

Trying If else condition in EVAL in imacros gives error


This is the link from where I m extracting data

TAG POS=1 TYPE=DIV ATTR=CLASS:sLB&&TXT:* EXTRACT=TXT
SET pqr {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=R1 TYPE=INPUT ATTR=TYPE:HIDDEN&&TXT:* EXTRACT=TXT
SET abc {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=R1 TYPE=INPUT ATTR=TYPE:HIDDEN&&TXT:* EXTRACT=TXT
SET def {{!EXTRACT}}
SET !EXTRACT NULL
PROMPT "{{abc}} BHK {{def}}"

SET VAR7 EVAL("if (\"{{!abc}}\" == ' ') PROMPT "{{abc}} {{def}}"; else \"PROMPT "{{abc}} BHK {{def}}\";")
PROMPT {{VAR7}}

Here I'm checking the condition if the value of the variable abc is null or blank, then print data of two variable i.e abc and def else print data of abc and def concatenated with BHK in between the both. But this gives me error

MacroSyntaxError: wrong format of SET command, line 71 (Error code: -910)

Any suggestion where I'm going wrong. Any help would be much appreciated. Thanks


Solution

  • Let me see if I understand your question...

    If variable abc is null or blank,
    then return abc and def (why bother returning abc if it's blank/null?)
    else return abc + "BHK" + def

    Since I don't really understand exactly what you're extracting even though you provided a link, I created a test case below with the answer:

    'Set test values
    SET abc "100"
    SET def "Apartment"
    
    'Evaluation below, will abc = ' '?
    SET VAR7 EVAL("('{{abc}}'==' ')?\"{{abc}} {{def}}\" : \"{{abc}} BHK {{def}}\";")
    'return results of evaluation
    PROMPT {{VAR7}}
    
    'test abc with blank value
    SET abc " "
    SET VAR7 EVAL("('{{abc}}'==' ')?\"{{abc}} {{def}}\" : \"{{abc}} BHK {{def}}\";")
    'return results of evaluation
    PROMPT {{VAR7}}
    

    Remember, you can't use Javascript to control flow/logic for Imacros. It looked like you were trying to create Imacro commands via javascript. If this answer helped, please mark as such. Thanks!