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.
Switch Calculation - If Variable don't exist
- magnussandstrom
- Advanced member
- Posts: 510
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Switch Calculation - If Variable don't exist
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.
Like this:
<Version></Version>=<Version>1</Version>
<Version/>=<Version>1</Version>
Maybe not the most clean solution but it works.
- magnussandstrom
- Advanced member
- Posts: 510
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Switch Calculation - If Variable don't exist
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"]"]
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
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
It was a bit tricky but it works.
Thanks magnussandstrom
