Pass variables between topics

ayman_h
Kilo Sage
Kilo Sage

Hi,

Does anyone know how to pass variables between VA Topics? 

 

I have tried using session variables below, I just get a null response in the 2nd topic. It works fine both the set and get methods are within the same topic.

Topic 1:

var session = gs.getSession(); session.putClientData('var1, 'test');

 

Topic 2:

var value = session.getClientData('var1');

gs.info(value);

1 ACCEPTED SOLUTION

ayman_h
Kilo Sage
Kilo Sage

After a bit of digging, I have finally found out a way to do this.

 

  • First, you need to create a Context variable, by navigating to All > Conversational Interfaces > Settings
  • Once the Context variable is in place, you set it using 'vaVars.[name of context variable] = '[value]' inside your topic
  • To retrieve the variable, simple use 'vaVars.[name of context variable]' in your Script action

 

You can check if the Context value has been set correctly in the background, by navigating to the Interaction record.

 

  • Firstly, get the Sys ID of the Interaction Record. On your topic use 'vaVars._interaction_record_sysid'
  • Navigate to Interaction > All and search with your Sys ID
  • On the Interaction record, you can update the form layout to make the 'Context' field visible.
  • Clicking onto the Context field will take you to the Remote Interaction Context table where you can view all the Context variables 

Hope this helps.


Regards,

Ayman

View solution in original post

3 REPLIES 3

ayman_h
Kilo Sage
Kilo Sage

After a bit of digging, I have finally found out a way to do this.

 

  • First, you need to create a Context variable, by navigating to All > Conversational Interfaces > Settings
  • Once the Context variable is in place, you set it using 'vaVars.[name of context variable] = '[value]' inside your topic
  • To retrieve the variable, simple use 'vaVars.[name of context variable]' in your Script action

 

You can check if the Context value has been set correctly in the background, by navigating to the Interaction record.

 

  • Firstly, get the Sys ID of the Interaction Record. On your topic use 'vaVars._interaction_record_sysid'
  • Navigate to Interaction > All and search with your Sys ID
  • On the Interaction record, you can update the form layout to make the 'Context' field visible.
  • Clicking onto the Context field will take you to the Remote Interaction Context table where you can view all the Context variables 

Hope this helps.


Regards,

Ayman

aakashps
Tera Contributor

@ayman_h will this solution work even when switching between the topics? like we do call different topics via the switch topic and call topic within another topic. So, here from topic 1 when am calling topic 2, via the context variable will we be able to pass the selection done/hardcode a selection from topic 1 to topic 2? Could you please let me know if this can be done.

@aakashps - Yes, this should work as this is a global variable that will exist for the entire interaction session for the user.