Page 1 of 1

Switch Calculation - If Variable don't exist

Posted: Tue Aug 06, 2024 4:37 pm
by schmitzdp
Hello,

I would like to obtain a calculation with these 2 variables.

[Switch.Calculation:Expression="[Metadata.Text:Dataset="Xml",Model="XML",Path="/xml/Quantity"]*[Metadata.Text:Path="/xml/Version",Dataset="Xml",Model="XML"]"]

Some of our products do not include the "Version" variable because of their characteristics.

If the variable is not found, is there a way or a function to replace it with the value '1' for example ?

Thanks.

Re: Switch Calculation - If Variable don't exist

Posted: Wed Aug 07, 2024 2:09 pm
by magnussandstrom
I had a similar case and solved it by using the app String replace before XML pickup, to set the value to 1 if the XML-field is not populated.

Like this:

<Version></Version>=<Version>1</Version>
<Version/>=<Version>1</Version>

Maybe not the most clean solution but it works.

Re: Switch Calculation - If Variable don't exist

Posted: Wed Aug 07, 2024 2:22 pm
by magnussandstrom
This might be a better solution (especially if the field Version does not exist):

1. Set the Version value as private data:
Version=[Metadata.Text:Dataset="Xml",Model="XML",Path="//Version"]

2. Use the app Private Data Magician to set the value to 1 if no value is present (this will only affect if there is no value):
*** Version
= 1

3. Then calculate with the Private data value instead:
[Switch.Calculation:Expression="[Metadata.Text:Dataset="Xml",Model="XML",Path="/xml/Quantity"]*[Job.PrivateData:Key="Version"]"]

Re: Switch Calculation - If Variable don't exist

Posted: Thu Aug 08, 2024 10:38 am
by schmitzdp
I finally used the app String replace to standardise this data for all my products.

It was a bit tricky but it works.

Thanks magnussandstrom ;)