API Connect

 View Only
  • 1.  How to extract a variable from one gateway script policy to another

    Posted Tue May 07, 2024 02:00 AM
    Edited by Raja Kumar Tue May 07, 2024 06:44 AM

    Hello 

    I'm using 2 gatewayscript policies in my assembly flow. Now, when I try to extract the variable defined in gatewayscript policy 1. Its says that variable is undefined. can you please let me know how we can do this ?

    Gatewayscript policy 1

    let a = test;

    Gatewayscript policy 2

    //trying to print the variable value console.log('value of b is:', context.get('a'));

    in apic logs, it prints as value of b is: a is undefined

    P.S.
    I've tried context.set('') variable in gatewayscript policy 1 but still no luck.  



    ------------------------------
    Raja K
    ------------------------------



  • 2.  RE: How to extract a variable from one gateway script policy to another

    Posted Wed May 08, 2024 01:35 AM
    // In first Gw script do this
    var context = session.createContext("ctx-01");
    
    // Don't use URL based syntax. It will work but is not good here
    context.setVar("first-name", "Ajitabh");
    
    
    
    // In second Gw script do this
    var context = session.name("ctx-01");
    
    // Reading context variables
    console.error("First log: %s",context.getVar("first-name"));


    ------------------------------
    Ajitabh Sharma
    ------------------------------



  • 3.  RE: How to extract a variable from one gateway script policy to another

    Posted Thu May 09, 2024 10:20 AM

    Thank you Ajitabh.

    I have a token and along with token cdata is also formed. Now i want to remove the CDATA section and want only token content. how i can do this in gatewayscript ?

    <data contentType="application/x-www-form-urlencoded">

    <![CDATA[token]]> </data>



    ------------------------------
    Raja Kumar
    ------------------------------