# If-Else Condition with arc:case

**URL:** <https://community.cdata.com/t/if-else-condition-with-arc-case/601>\
**Category:** CData Arc\
**Tags:** question\
**Created:** [January 17, 2024, 3:43am UTC](https://community.cdata.com/t/if-else-condition-with-arc-case/601 "2024-01-17T03:43:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pradeep](https://avatars.discourse-cdn.com/v4/letter/p/f0a364/32.png) [@Pradeep](https://community.cdata.com/u/Pradeep)\
**Post date:** [January 17, 2024, 3:43am UTC](https://community.cdata.com/t/if-else-condition-with-arc-case/601/1 "2024-01-17T03:43:01Z")

</div>

Dear All,

I have a business logic, where i need to select value for RSN field , based on below Condition

IF&nbsp; TypeCode = WriteOff&nbsp; then

{

if&nbsp; RsnCode = “1004” then

Rsn = “925”

elseif RsnCode = “1006” then

Rsn = “200”

elseif RsnCode = “1003” then

Rsn = “935”

}

ElseIf&nbsp;TypeCode = WriteOn then

{

if&nbsp; RsnCode = “1004” then

Rsn = “950”

elseif RsnCode = “1006” then

Rsn = “250”

elseif RsnCode = “1003” then

Rsn = “935”

}

to achieve i tried to add the arc:case within the If condition as below,

\<arc:if exp=“‘TypeCode’==‘StockWriteOff’”\>  
&nbsp; \<arc:select attr=“RSNCode”\>  
&nbsp; \<arc:case value=“1006”\>  
&nbsp; &nbsp; \<arc:set attr=“Rsn” value=“200”/\>  
&nbsp; \</arc:case\>  
&nbsp; \<arc:select attr=“RSNCode”\>  
&nbsp; \<arc:case value=“1004”\>  
&nbsp; &nbsp; \<arc:set attr=“Rsn” value=“925”/\>  
&nbsp; \</arc:case\>  
&nbsp; \<arc:select attr=“RSNCode”\>  
&nbsp; \<arc:case value=“1003”\>  
&nbsp; &nbsp; \<arc:set attr=“Rsn” value=“935”/\>  
&nbsp; \</arc:case\>  
&nbsp; arc:else  
&nbsp; &nbsp; \<arc:select attr=“RSNCode”\>  
&nbsp; \<arc:case value=“1006”\>  
&nbsp; &nbsp; \<arc:set attr=“Rsn” value=“250”/\>  
&nbsp; \</arc:case\>  
&nbsp; \<arc:select attr=“RSNCode”\>  
&nbsp; \<arc:case value=“1004”\>  
&nbsp; &nbsp; \<arc:set attr=“Rsn” value=“950”/\>  
&nbsp; \</arc:case\>  
&nbsp; \<arc:select attr=“RSNCode”\>  
&nbsp; \<arc:case value=“1003”\>  
&nbsp; &nbsp; \<arc:set attr=“Rsn” value=“935”/\>  
&nbsp; \</arc:case\>  
&nbsp; \</arc:else\>  
\</arc:if\>

\<arc:set attr=“result.text” value=“[Rsn]”\>\</arc:set\>

But i am getting invaild script error message, kindly help to shed some light to eliminate the error and achieve the results.

---

<div class="post-metadata">

**Author:** ![Rohit](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/rohit/32/638_2.png) [@Rohit](https://community.cdata.com/u/Rohit)\
**Post date:** [January 18, 2024, 9:39am UTC](https://community.cdata.com/t/if-else-condition-with-arc-case/601/2 "2024-01-18T09:39:46Z")

</div>

Hi Pradeep,

As you raised the ticket for the same and that is resolved already. I am suggesting the 2 different solutions here as well.

In your script, there is repetition of the **select** &nbsp;element for each case. To optimize this, you can use a single select statement for the if block and another for the else block.

Additionally, note that arc:select&nbsp;works on the value, so you should use \<arc:select value\>&nbsp;instead of \<arc:select attr\>

When referencing elements from the source file, ensure to utilize the xpath() instead of directly passing element names as strings within double quotes. Here is an example:

**\<arc:select value=“[xpath(/Items/Data/RSNCode)]”\>**

This ensures proper xpath() usage to reference the source file elements.

Achieving this can be done through two methods. The first one involves using Arc script with the Arc select&nbsp;and case keywords.

**Below is the corrected version of the script:**

```auto
<arc:if exp="[xpath(/Items/Data/TypeCode) | equals('StockWriteOff')]">    <arc:select value="[xpath(/Items/Data/RSNCode)]">        <arc:case value="1006">            <arc:set attr="Rsn" value="200"/>        </arc:case>        <arc:case value="1004">            <arc:set attr="Rsn" value="925"/>        </arc:case>        <arc:case value="1003">            <arc:set attr="Rsn" value="935"/>        </arc:case>    </arc:select>        <arc:else>          <arc:select value="[xpath(/Items/Data/RSNCode)]">            <arc:case value="1006">                <arc:set attr="Rsn" value="250"/>            </arc:case>            <arc:case value="1004">                <arc:set attr="Rsn" value="950"/>            </arc:case>            <arc:case value="1003">                <arc:set attr="Rsn" value="935"/>            </arc:case>          </arc:select>        </arc:else></arc:if><arc:set attr="result.text" value="[Rsn]" />

```

**------------------------------------------Alternative Approach-------------------------------------------------**

Another approach to achieve this use case is by using the **IF-Else** condition on your **Rsn** element. Within each condition, you can include multiple **IF** &nbsp;conditions to handle various edge cases, as demonstrated below:

![d9c94d46-fcd1-4081-b504-ebe1e7e1c87d.png](https://us1.discourse-cdn.com/cdata/original/1X/2e7504fdbafdf8a575994e2382837814c1dcd776.png)

**IF :**

 ![a51a5ec9-855d-4c72-8e10-90e09c263150.png](https://us1.discourse-cdn.com/cdata/original/2X/a/a877421ca1dd0678fafc4276168494ed4a743c41.png)

**Else:**

 ![36b7fa18-5d11-45b6-9b9f-db2637a1e278.png](https://us1.discourse-cdn.com/cdata/original/1X/e1845852998ac670260adecdf29b39516eaeea91.png)

**Please find the attached connector Arc flow(2nd approach) for your reference.**

[INV\_ADJ\_XML.arcflow.zip](https://community.cdata.com/uploads/short-url/8blYGBVEoErhpMJuWnL6cPIeAx4.zip) (3.54 KB)

---

<div class="post-metadata">

**Author:** ![Pradeep](https://avatars.discourse-cdn.com/v4/letter/p/f0a364/32.png) [@Pradeep](https://community.cdata.com/u/Pradeep)\
**Post date:** [January 19, 2024, 1:07am UTC](https://community.cdata.com/t/if-else-condition-with-arc-case/601/3 "2024-01-19T01:07:26Z")

</div>

Hi Rohit,

Thanks for the response with alternative approach.

I have posted here few hours ago before raising ticket, since i need to complete the change i raised the ticket to get fast response.

Thanks for kind understanding and supportive.
