How to reference properties in the returned objects from a PowerShell web service with Object properties
There is a fairly new function in AP enabling you to write more powerful PowerShell WebServices (PSWS). In older versions, if you wanted to retrieve more than one property from the result in a PSWS you needed to call the PSWS more than once, referencing the same PSWS every time but selecting different properties on the return object. Using a PSWS that maybe took 2 seconds to execute would cause bad performance issues if you called it multiple times. With the new functionality you call the PSWS once but use the result as many times you want.
Running this function manually looks like this. It returns a object with a number of properties:
The old solution to actually use all the properties in your workflow would look something like this.
For getting the user id of the logged in user:
For getting the first name of the logged in user:
…and for every property we wanted to show we would do the same procedure again and again. Let’s assume that the PSWS takes 3 seconds to execute every time. Getting all the attributes (first name, surname, display name, mail address, userid and title) and displaying them on the checkout would then take 18 seconds (3x6).
Now, let’s review the object properties function of calling the PSWS once but referencing different properties. First, we need to edit the PSWS and tell AP what properties we want to publish every time the PSWS is run. You simply select the tab “Object properties” and write every property in the textbox.
Now, let’s use this. First step is the same as before. We need to call the PSWS from somewhere. But this is the only time we actually call it.
Next step, getting the rest of the properties is what differs. For getting the user’s first name we choose a “Readonly” and press “Add Reference”:
Then we just repeat for all the other properties. So, instead of calling the PSWS 6 times taking up 18 seconds, we call it once taking only 3 seconds!
In conclusion: It is strongly recommended to start using Object properties every time you need to call a PowerShell web service more than once.