How to: Custom Action - Set variable value for QlikSense
Store TRUECHART's current mode in a variable
This code sets the variable' vB_EditMode' with a string value. In this case, it gets the current edit mode from a TRUECHART instance and sets this to the variable.
Step-by-step guide
Get current TRUECHART edit mode
var editMode = "'" + HiCo.DataObjects.DocumentDO.getDocSettings().documentMode.value + "'";
Set the variable' vB_EditMode' with a string value
qlik.currApp().variable.setStringValue('vB_EditMode', editMode);
Store the title of a current sheet in a variable
Following code may be used in a custom action (usually in combination with an onLoad trigger) to store the title of the current sheet in a variable.
var app = qlik.currApp(); var sheetId = qlik.navigation.getCurrentSheetId().sheetId; var currentSheet = (qlik.navigation.sheets || []).filter(function(sheet){return sheet.qInfo.qId === sheetId})[0]; if(currentSheet){ // set the value of the current sheets title to 'vH_Selector' variable app.variable.setStringValue('vH_Selector', currentSheet.qMeta.title); }else{ // set a "Fallback" value in case where the current sheet could be not properly determined (like in a mashup for example) app.variable.setStringValue('vH_Selector', 'Fallback'); }
Qlik Sense developer documentation
- Variable API: http://help.qlik.com/en-US/sense-developer/Subsystems/APIs/Content/CapabilityAPIs/qlik-variable-interface.htm
- StringValues: http://help.qlik.com/en-US/sense-developer/Subsystems/APIs/Content/CapabilityAPIs/VariableAPI/setStringValue-variable-method.htm
- NumValues: http://help.qlik.com/en-US/sense-developer/Subsystems/APIs/Content/CapabilityAPIs/VariableAPI/setNumValue-variable-method.htm
Related articles