I am reading a document and sometimes it has invoice ID in it, sometimes it has Order ID? How to put an OR for a variable so that it won't come out as empty and give error?

I’ve kept it like this for orderInfo:
orderInfo= deseXMLDoc.Root.Descendants(“InvoiceIDInfo”)(0).Attribute(“invoiceID”).Value.ToString
but i also want to include Invoice ID.

Can anyone suggest the answer to it?

Hi @anjasing,

Have you tried using pipe symbol || or may be using Or keyword itself?

Does it work?

Regards
Sonali

1 Like

@anjasing - I think you can use If logic in an assign statement and achieve it.

Pseudo code

Orderinfo= if ( value equals InvoiceId, get the invoiceid, else get orderId)

Could you please provide a sample like I’ve shown in above… I want both thing into one variable only?

Hi

Use this expression in an assign activity

YourXDocVar.Root.Descendants(“ABC”).ToList

orderInfo= IF(deseXMLDoc.Root.Descendants(“InvoiceIDInfo”).ToList.Contains(“InvoiceID”), deseXMLDoc.Root.Descendants(“InvoiceIDInfo”)(0).Attribute(“invoiceID”).Value.ToString, deseXMLDoc.Root.Descendants(“orderrequestheader”)(0).Attribute(“OrderID”).Value.ToString)

Cheers @anjasing

Can you please suggest what should be type of orderInfo variable here ?

String type @anjasing

it’s giving the error image

If you can help here?

Sure
Can I have the xml file if possible
I can give you the flow
@anjasing

Hi,
Here’s the sample file
MainDocument.xml (543 Bytes)

@anjasing - Here you go…

  xeInvoiceIDInfo = xDoc.Root.Descendants("InvoiceIDInfo").toList

image

orderInfo = if(xeInvoiceIDInfo.ElementAt(0).tostring.Contains("invoiceID"),xeInvoiceIDInfo.ElementAt(0).Attribute("invoiceID").Value,xeInvoiceIDInfo.ElementAt(0).Attribute("orderID").Value)

Hope this helps…

1 Like

Thank you so much :slight_smile:

So you have already tested with both orderID and InvoiceID? just making sure…

Hi,
image
I was able to process for invoice ID but not for orderID…could you please help with this error which I am getting for orderID…
I was loaded with work, so couldn’t check properly

Please send the xml with the orderID.

MainDocument (16).zip (1.4 KB)

Thank you so much for helping

Please check this… orderID and InvoiceID are using two different desendants…So I created another List for OrderID, Please see below…

  xeOrderIDInfo = xDoc.Root.Descendants("OrderRequestHeader").toList

  orderInfo = if(xeInvoiceIDInfo.count > 0,xeInvoiceIDInfo.ElementAt(0).Attribute("invoiceID").Value,xeOrderIDInfo.ElementAt(0).Attribute("orderID").Value)

Output for InvoiceID

Hope this helps…

1 Like

Yeah, It is working perfectly fine for both…Thank you soo much :slight_smile:

1 Like