Hi
@Steve Linn ,
I request your help in the below issue , Please guide me.
I am trying to set a runtime variable which I want to access in the set variable policy just after my gateway script , In my gateway script I have mentioned below code :
var originalAPIpath = "/proposalservice/v2/proposal";
var APIpath = originalAPIpath.replace("/proposalservice/v2", "");
context.set('APIpath', APIpath);
But I am getting an exception while doing this and it says in Datapower logs :
apim.gatewayscript: ReferenceError: context is not defined
Could you please let me know what I am doing wrong?
Also I will be accessing the variable APIpath in the set variable policy below , is it correct?
Thanks
Adarsh
------------------------------
Adarsh Thakur
------------------------------
Original Message:
Sent: Mon November 29, 2021 10:42 AM
From: Steve Linn
Subject: Switch condition on Context Variable
Hi Romil,
Referencing the context variable directly is all that is needed
- switch:
version: 2.0.0
title: switch
case:
- condition: (id = '2')
execute:
...
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Tue November 23, 2021 09:32 PM
From: Romil Garg
Subject: Switch condition on Context Variable
Hi,
In API Connect (v10.0.3 - API Gateway), I am trying to define a switch condition based on the context variable that I have defined in the previous gateway-script. context.set('id', '2');
In below example, I am checking for the value of 'id' when set as a header, and this works fine.
- How can I do the same when the 'id' is set as a context variable?
- How can I do this when 'id' is set within a JSON body ({"id": 2}) defined within a context variable?
- switch:
version: 2.0.0
title: switch
case:
- condition: ($header("id") = '2')
execute: []
------------------------------
Romil Garg
------------------------------