cancel
Showing results for 
Search instead for 
Did you mean: 

IF else Condition in Mapper

pranil2k2
Contributor

Hi ,
I have a requirement to write multiple IF/ELSE conditions and generate an output column. but i am getting syntax error, please someone correct me

$section == “Presentation” && $action_field == “Product Short Name” ? $EMA_PRODUCTSHORTNAME:
$section == “Presentation” && $action_field == “Product INN/Common Name” ? $EMA_PRODUCTGENERICNAME:
$section == “Presentation” && $action_field == “Product Strength Name” ? $EMA_PRODUCTSTRENGTH:
$section == “Presentation” && $action_field == “Full Presentation Name” ? $EMA_PRODUCTNAME:
$section == “Presentation” && $action_field == “Product Form Name” ? $EMA_PRODUCTFORM:
$section == “Authorisation” && $action_field == “Orphan Drug” ? $ORPHANDRUG:
$section == “Authorisation” && $action_field == “Authorisation Number” ? $EMA_AUTHORISATIONNUMBER:
$section == “Presentation” && $action_field == “Product Company Name” ? $EMA_PRODUCTCOMPANYNAME: null

Thannks

1 ACCEPTED SOLUTION

del
Contributor III

To follow up with a little additional help (barring any typos)…


1 ) The ternary code you provided above needs parenthetical grouping:

$section == "Presentation" && $action_field == "Product Short Name" ? $EMA_PRODUCTSHORTNAME:
($section == "Presentation" && $action_field == "Product INN/Common Name" ? $EMA_PRODUCTGENERICNAME:
($section == "Presentation" && $action_field == "Product Strength Name" ? $EMA_PRODUCTSTRENGTH:
($section == "Presentation" && $action_field == "Full Presentation Name" ? $EMA_PRODUCTNAME:
($section == "Presentation" && $action_field == "Product Form Name" ? $EMA_PRODUCTFORM:
($section == "Authorisation" && $action_field == "Orphan Drug" ? $ORPHANDRUG:
($section == "Authorisation" && $action_field == "Authorisation Number" ? $EMA_AUTHORISATIONNUMBER:
($section == "Presentation" && $action_field == "Product Company Name" ? $EMA_PRODUCTCOMPANYNAME: null)))))))

2 ) Here is an example of the same in a match statement(s):

match $section {
    "Presentation" => match $action_field {
        "Product Short Name" => $EMA_PRODUCTSHORTNAME,
        "Product INN/Common Name" => $EMA_PRODUCTGENERICNAME,
        "Product Strength Name" => $EMA_PRODUCTSTRENGTH,
        "Full Presentation Name" => $EMA_PRODUCTNAME,
        "Product Form Name" => $EMA_PRODUCTFORM,
        "Product Company Name" => $EMA_PRODUCTCOMPANYNAME,
        _ => null
    },
    "Authorisation" => match $action_field {
        "Orphan Drug" => $ORPHANDRUG,
        "Authorisation Number" => $EMA_AUTHORISATIONNUMBER,
        _ => null
    },
    _ => null
}

3 ) Here is a sample pipeline showing the Conditional Snap compared to the ternary and match mapper options: Community.9753.slp (15.6 KB)

View solution in original post

6 REPLIES 6

tlikarish
Employee
Employee

You could try using the match operator as it can handle these kinds of expressions more clearly than the ternary (?) one. Give it a shot and see if it’s easier to write. If you’re having trouble, reach out and I can help you design the expression.

Thanks for the reply, i am not getting correct example on match that uses multiple columns. please can you share me some example and also in mapper if i use match, it is giving error. please can you share me some example on match that use multiple columns.

Thanks again

del
Contributor III

@prinil2k2, If I’m interpreting your intention correctly, I think I would recommend the Conditional snap in your case.

del
Contributor III

To follow up with a little additional help (barring any typos)…


1 ) The ternary code you provided above needs parenthetical grouping:

$section == "Presentation" && $action_field == "Product Short Name" ? $EMA_PRODUCTSHORTNAME:
($section == "Presentation" && $action_field == "Product INN/Common Name" ? $EMA_PRODUCTGENERICNAME:
($section == "Presentation" && $action_field == "Product Strength Name" ? $EMA_PRODUCTSTRENGTH:
($section == "Presentation" && $action_field == "Full Presentation Name" ? $EMA_PRODUCTNAME:
($section == "Presentation" && $action_field == "Product Form Name" ? $EMA_PRODUCTFORM:
($section == "Authorisation" && $action_field == "Orphan Drug" ? $ORPHANDRUG:
($section == "Authorisation" && $action_field == "Authorisation Number" ? $EMA_AUTHORISATIONNUMBER:
($section == "Presentation" && $action_field == "Product Company Name" ? $EMA_PRODUCTCOMPANYNAME: null)))))))

2 ) Here is an example of the same in a match statement(s):

match $section {
    "Presentation" => match $action_field {
        "Product Short Name" => $EMA_PRODUCTSHORTNAME,
        "Product INN/Common Name" => $EMA_PRODUCTGENERICNAME,
        "Product Strength Name" => $EMA_PRODUCTSTRENGTH,
        "Full Presentation Name" => $EMA_PRODUCTNAME,
        "Product Form Name" => $EMA_PRODUCTFORM,
        "Product Company Name" => $EMA_PRODUCTCOMPANYNAME,
        _ => null
    },
    "Authorisation" => match $action_field {
        "Orphan Drug" => $ORPHANDRUG,
        "Authorisation Number" => $EMA_AUTHORISATIONNUMBER,
        _ => null
    },
    _ => null
}

3 ) Here is a sample pipeline showing the Conditional Snap compared to the ternary and match mapper options: Community.9753.slp (15.6 KB)