commonfields:
  id: Set
  version: -1
name: Set
script: |-
  var ec = {};
  ec[args.key] = args.value;
  var result = {
      Type: entryTypes.note,
      Contents: ec,
      ContentsFormat: formats.json,
      HumanReadable: 'Key ' + args.key + ' set'
  };

  if (!args.append || args.append === 'false') {
      setContext(args.key, args.value);
  } else {
      result.EntryContext = ec;
  } 

  return result;
type: javascript
tags:
- Utility
comment: Sets a value into the context with the given context key
enabled: true
args:
- name: key
  required: true
  default: true
  description: The key to set
- name: value
  required: true
  isArray: true
  description: The value to set to the key. Can be an array. Usually, a dq expression.
- name: append
  description: If false then then the context key will be overwritten. If set to true then the script will append to existing context key
  auto: PREDEFINED
  predefined:
  - "true"
  - "false"
scripttarget: 0

commonfields:
  id: Set
  version: -1
name: Set
script: |-
  var ec = {};
  var value;
  try {
      value = JSON.parse(args.value);
  } catch(err) {
      value = args.value;
  }

  ec[args.key] = value;
  var result = {
      Type: entryTypes.note,
      Contents: ec,
      ContentsFormat: formats.json,
      HumanReadable: 'Key ' + args.key + ' set'
  };

  if (!args.append || args.append === 'false') {
      setContext(args.key, value);
  } else {
      result.EntryContext = ec;
  }

  return result;
type: javascript
tags:
- Utility
comment: Sets a value into the context with the given context key
enabled: true
args:
- name: key
  required: true
  default: true
  description: The key to set
- name: value
  required: true
  description: The value to set to the key. Can be an array. Usually, a dq expression.
  isArray: true
- name: append
  auto: PREDEFINED
  predefined:
  - "true"
  - "false"
  description: If false then then the context key will be overwritten. If set to true
    then the script will append to existing context key
scripttarget: 0
releaseNotes: "If object passed as string, Set will parse the value to JSON then set to context"

Set will parse value to json if needed and then set it to context
Set will parse value to json if needed and then set it to context
