Loop through String List and assign the nth element to out variable

I have a string list which has 13 elements in it as shown below.

I need to loop through this and get the nth element and assign it to an out variable.
eg: I need to map and assign as below.
PropertyValues[1] to an out variable var1
PropertyValues[4] to an out variable var2
PropertyValues[6] to an out variable var3
PropertyValues[8] to an out variable var4
PropertyValues[10] to an out variable var5

Please help me on how to achieve this. I am using WM 10.3.

Hi,

is this a static association or does this differ from invocation to invocation?

Depending on this there are several possible approaches:

  • Loop over the list and check for temporary variable $iteration (only available inside the loop) and use branches then to map the value to the correct target.
  • use pub.xml-Service XQuery to directly access the needed values (see IS Built-In-Services Reference for details).
  • …

Regards,
Holger

1 Like

“PropertyValues” as a var name infers that this was read from a file perhaps? Do you have control of that file and its content/format? If so, there are likely ways to read these settings into vars in a more direct manner.

You can use variable substitution. It has some caveats to be aware of (repeating the substitution string multiple times, impacting maintenance; if the list isn’t full, target vars will have the variable substitution string assigned as a value, etc.). If the positioning of which index goes to which var changes, then this approach silently breaks.

Here is the result of a sample where one of the variables references an index that is larger than the list size.

image

If you can share what this is intended for perhaps someone can suggest an approach that is a bit less brittle.

1 Like

Hi reamon,
That is correct. This is read from an XML config file which has the name/value pairs stored for URL, username, Passwords for different environments. And yes, I have control of this file and it won’t be changed. The positioning of the parameters will not change in the config file even though the values inside might change.
So, basically the purpose of this is, I have a config file (xml) which has the URL, Username and Password properties stored with values for three different environments.
In my flow service, I am branching out based on the environment and fetch the URL, Username and Password values for the corresponding environment.

example of xml file is below:

Hi Holger,
Thank you, I tried the below suggestion of yours’s and it worked.

  • Loop over the list and check for temporary variable $iteration (only available inside the loop) and use branches then to map the value to the correct target.

This structure is forcing the parsing and assumptions about positions. There is an easier way.

<properties>
  <TestURL>testurl.com</TestURL>
  <QualURL>qualurl.com</QualURL>
  <ProdURL>produrl.com</ProdURL>
  ...
  <ProdPassword>789</ProdPassword>
</properties>

(There is no need to declare any namespaces for this simple XML.)

Define a document type in IS:

properties (document)
  TestURL (string)
  QualURL (string)
  ProdURL (string)
  ...
   ProdPassword (string)

I assume you’re using xmlStringToXMLNode and xmlNodeToDocument. With the config file as above and the document type, you don’t need to loop, index or do anything else – just map from the applicable fields in the properties document variable.

1 Like

Thank you. Both the solutions worked.

1 Like

Hi,

looks like your are using one single instance in a “multiple purpose” manner.
This is not considered a best practice, at least the production should be separated from the others.
Might be worth to check out for the “Global Variables” substitution feature and only define those parameters directly in the IS Admin UI.

You won´t have to bother to update the xml file on all instances when there a changes to it.
You will only edit the values on the affected instance and the others don´t need to know about it.

Regards,
Holger

1 Like

Agreed with Holger. You’re doing more than should be done in a single file.

  • Everyone will be able to see every URL, username and password for every environment. Audit and security teams are likely to take issue with that.
  • Storing passwords in a plain-text file is something audit teams will likely flag. You might consider using the outbound password facility that IS provides.
  • Global vars may be a reasonable approach too but be sure to keep those managed otherwise entropy/chaos can ensue. :slight_smile:

There is a general guideline we follow: never have code/steps that are environment specific or branch on “which environment am I running in”. It is almost never really necessary to do so (other solution designs can easily address) and almost always leads to a fire drill where something “bad” happens in production because the code thought it was running in non-prod.

1 Like

Thank you so much for the solutions and your suggestions reamon and Holger :slight_smile:

Hi,

Could you please elaborate on how to use the “outbound password facility that IS provides” for storing the connection credentials of an external application and also using the global variables?

I have the requirement to store the connection credentials like password, client secret and ID info and these should be stored as key after encrypting in either database/file and then decrypt this from a flow service while using these.

Can you please provide me any examples or the process on how to achieve this or other better ways?

Thanks!

Hi,

when password fields are defined in the global variables section they will be automatically be encrypted and stored in the outbound password store. The field in the IS Admin UI is then a masked field with asterisks.
These fields will then be decrypted internally upon usage.

This applies to password fields in AdapterConnections as well.

You might want to check the IS Administrators Guide (as well as the IS Built-In-Services Reference) for further details on this facility.

Regards,
Holger

Hi,

I defined the connection properties as global variables and these are stored as asterisks.
How can I read these global variables from a java service? or is there any in-built WM service to read these from flow service?
I am looking at Integration_Server_Built_In_Services_Reference guide but can’t find anything related to this.

You can read global variables through variable substitution, similar to pipeline variables.

For example, to put the global variable my.global.variable into the pipeline variable myVar, create a map step and, in the output side, add myVar and set the value to “%my.global.variable%”. In the lower left corner of the set window, check the “Perform global variable substitution” checkbox.

image

The webMethods Service Development Help has a section on using Global Variables in flow services (p. 298 for v10.1).

1 Like

Thanks a lot. That helps and works perfect!

Refer to the Built-In Services Reference for the pub.security.outboundPasswords:* servcies. These provide the building blocks you can use for your own helper services. We created a couple of helpers and DSP pages to help us create/update entries in the store and read them from services.

I again urge caution when using global vars for what seems like will be your primary configuration facility for many things. Entropy can quickly make that hard to manage. Also, be conservative when using Java. Most things do not need to use Java. And if you need a Java service for something, pass the parameters you read from global vars to it – don’t have the Java code (also) read from global vars.

1 Like

ok, thank you!

This topic was automatically closed after 1083 days. New replies are no longer allowed.