diff --git a/lib/Internal/CustomVariables.js b/lib/Internal/CustomVariables.js index e6db98765..0024fd37e 100644 --- a/lib/Internal/CustomVariables.js +++ b/lib/Internal/CustomVariables.js @@ -23,7 +23,7 @@ export default class CustomVariables extends CoreBase { constructor(registry, internalModule) { super(registry, 'internal', 'Internal/CustomVariables') - // this.internalModule = internalModule + //this.internalModule = internalModule } getActionDefinitions() { @@ -44,6 +44,22 @@ export default class CustomVariables extends CoreBase { }, ], }, + custom_variable_create_value: { + label: 'Custom Variable: Set or Create raw value if not exists', + options: [ + { + type: 'textinput', + label: 'Custom variable', + id: 'name', + }, + { + type: 'textinput', + label: 'Value', + id: 'value', + default: '', + }, + ], + }, custom_variable_set_expression: { label: 'Custom Variable: Set with expression', options: [ @@ -199,7 +215,7 @@ export default class CustomVariables extends CoreBase { const wrappedVariable = `\${$(${action.options.variable})}` action.options.expression = - action.options.order == 'variable_value' + action.options.order === 'variable_value' ? `\`${wrappedVariable}${wrappedValue}\`` : `\`${wrappedValue}${wrappedVariable}\`` @@ -210,7 +226,7 @@ export default class CustomVariables extends CoreBase { delete action.options.result return action - } else if (action.action == 'custom_variable_string_substring_operation') { + } else if (action.action === 'custom_variable_string_substring_operation') { action.action = 'custom_variable_set_expression' action.options.expression = `substr($(${action.options.variable}), ${wrapValue( @@ -231,6 +247,13 @@ export default class CustomVariables extends CoreBase { if (action.action === 'custom_variable_set_value') { this.instance.variable.custom.setValue(action.options.name, action.options.value) return true + } else if (action.action === 'custom_variable_create_value') { + if (this.instance.variable.custom.custom_variables[action.options.name]) { + this.instance.variable.custom.setValue(action.options.name, action.options.value) + } else { + this.instance.variable.custom.createVariable(action.options.name, action.options.value) + } + return true } else if (action.action === 'custom_variable_set_expression') { this.instance.variable.custom.setValueToExpression(action.options.name, action.options.expression) return true @@ -281,10 +304,10 @@ export default class CustomVariables extends CoreBase { this.instance.variable.custom.setValue(action.options.targetVariable, valueToSet) return true - } else if (action.action == 'custom_variable_reset_to_default') { + } else if (action.action === 'custom_variable_reset_to_default') { this.instance.variable.custom.resetValueToDefault(action.options.name) return true - } else if (action.action == 'custom_variable_sync_to_default') { + } else if (action.action === 'custom_variable_sync_to_default') { this.instance.variable.custom.syncValueToDefault(action.options.name) return true }