AnsweredAssumed Answered

How to fetch the required national id, if we have more than 2 elements??

Question asked by indrasena on Nov 7, 2017
Latest reply on Nov 16, 2017 by indrasena

Hi all, i am facing an issue in the scripting. we have an xml input for an employee having 2 national ids as below.

 

<person>

 <national_id_card>
 <card_type>SSN</card_type>
 <country>US</country>
 <isPrimary>true</isPrimary>
 <national_id>123.456</national_id>
 </national_id_card>
 <national_id_card>
 <card_type>AAD</card_type>
 <country>IND</country>
 <isPrimary>false</isPrimary>
 <national_id>1234-5678</national_id>
 </national_id_card>

</person>

 

my requirement is like, if country=IND is present then it should to send the national_id- 1234-5678 to out put, if the employee country element does not have IND, then it should check for isPrimary=''true" then should send the corresponding national_id.

 

i have written the below java script 

 

if (card_type == "AAD")
{
national_id_output = national_id;
}
else if (isPrimary=="true")
{
national_id _output= national_id;
}

 

but  i am getting 2 output rows for the same employee with each national id. but i need only one output row with correct national id.

Outcomes