I want to create an api proxy which returns different set of columns for different query param / class

Suppose, there are four columns returned by my proxy - "red", "green", "blue", "white".

For query param / class "student", I want to hide "red" and show rest three.

For query param / class "teacher", I want to hide "blue" and "green".

I tried below code, but it is not working (tried using query param in place of class also)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-Remove-Param1">
    <DisplayName>AM-Remove-Param1</DisplayName>
    <Properties/>
    <Remove>
        <Class ref="request.queryparam.userType">
            <Remove class="teacher">
                <FormParams>
                    <FormParam name="blue"/>
                    <FormParam name="green"/>
                </FormParams>
            </Remove>
            <Remove class="student">
                <FormParams>
                    <FormParam name="red"/>
                </FormParams>
            </Remove>
        </Class>
     </Remove>


    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
Solved Solved
0 3 195
1 ACCEPTED SOLUTION

yeah, it’s not going to work with your approach. You should actually use JavaScript for this work.

However, since you want to use AM policy, you can do it by creating two different policies and then set a condition on each policy to execute only when the specific condition is hit.

So in your use case, create the assign message policy for one scenario, such as queryParam.userType=“teacher” and then in your flow add the condition on the policy. Then create another policy and remove whichever fields are needed. Make sure to add the condition on your second policy so it only executes on queryParam.userType=“student”

Here’s a small example for a condition on one of the policies:

<Step><Condition>request.queryParam.userType = "student"</Condition><Name>yourPolicyNameHere</Name></Step>

Also, be sure to remove all that class stuff from your policy.

Make sense?

View solution in original post

3 REPLIES 3

yeah, it’s not going to work with your approach. You should actually use JavaScript for this work.

However, since you want to use AM policy, you can do it by creating two different policies and then set a condition on each policy to execute only when the specific condition is hit.

So in your use case, create the assign message policy for one scenario, such as queryParam.userType=“teacher” and then in your flow add the condition on the policy. Then create another policy and remove whichever fields are needed. Make sure to add the condition on your second policy so it only executes on queryParam.userType=“student”

Here’s a small example for a condition on one of the policies:

<Step><Condition>request.queryParam.userType = "student"</Condition><Name>yourPolicyNameHere</Name></Step>

Also, be sure to remove all that class stuff from your policy.

Make sense?

@Robert Johnson has said correctly you could choose both option however using javascript policy would be much better and performant. in JS resource file you could do similar to this

 switch(userType) {
      case 'teacher':
        // code block
        payload = {
        "colorname" : "blue",
        };
        break;
      case 'student':
        // code block
         payload = {
        "colorname" : "red",
        "colorname1" : "green",
        };
        break;
      default:
        // code block
    }

Find out the attached demo proxy which basically returns the response on query param - userType

usertype-demo-rev1-2019-07-12.zip

however if you want to send the condition request to target endpoint, you could do it easily with Assign message policy. with type="request" in <AssignTo> property.

you can also return the response from JS also but if you are further processing your request, its better to use assign message policy.