I have an Assign message as which has payload. This AM then calls target endpoint.
Payload is set in AM, where data is retrieved using a query. The where clause in the query is dynamic and changes as per the queryparam we pass to the API endpoint.
For example, if I pass queryparam as 'emplid' then the where clause in the query in the payload should be 'WHERE EMPLID = '{request.queryparam.emplid}''
if I pass queryparam as 'FIRST_NAME' then the where clause in the query in the payload should be 'WHERE FIRST_NAME= '{request.queryparam.firstname}''
So the where clause must be dynamic based on queryparam.
For now, if I have ten queryparams then, I have to write ten different AM and each AM has to called based in some condition.
Is there a way where I can make it more generic and dynamic. Below is my AM
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="AM-GetEmplID">
<DisplayName>AM-GetEmplID</DisplayName>
<Properties/>
<Set>
<Headers>
<Header name="Authorization">Bearer {WDAccess_token}</Header>
</Headers>
<Payload contentType="application/json">
{
"query" : "SELECT ASOFDATE, EMPLID, EMPL_RCD, NAME_PREFIX, FIRST_NAME, LAST_NAME cds_WD_MMC_ActiveEE_TBL WHERE EMPLID = '{request.queryparam.emplid}'"
}
</Payload>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo type="request" createNew="false" transport="http"/>
</AssignMessage>
Solved! Go to Solution.
Sounds like a perfect use case for a JavaScript Policy. Using JavaScript policy in front of your AM policy, you can effectively and flexibly generate dynamic fragments of the payload using the full might of javascript and set them into context variable(s).Then AM would reference those context variables using {} syntax.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |