Skip to content

DeleteContext - added the ability to provide keys to keep #1787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Scripts/script-DeleteConext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ commonfields:
name: DeleteContext
script: |
var fieldsToDelete;
var shouldDeleteAll = (args.all === 'yes')
var shouldDeleteAll = (args.all === 'yes');
if(!shouldDeleteAll && !args.key) {
return {Contents: 'You must specify key or all=yes',
ContentsFormat: formats.text,
Type: entryTypes.error};
}
if(shouldDeleteAll) {
var keysToKeep = (args.keysToKeep) ? args.keysToKeep.split(',') : [];
fieldsToDelete = Object.keys(invContext);

// delete each field in context
var errorsStr = ""
var errorsStr = "";
for (var i = 0; i < fieldsToDelete.length; i++) {
var result = executeCommand('delContext', { key: fieldsToDelete[i], id: args.id });
if(!result || result.type === entryTypes.error) {
errorsStr = "errorsStr" + "\n" + result.Contents;
if (keysToKeep.indexOf(fieldsToDelete[i]) == -1) {
var result = executeCommand('delContext', { key: fieldsToDelete[i], id: args.id });
if(!result || result.type === entryTypes.error) {
errorsStr = "errorsStr" + "\n" + result.Contents;
}
}
}
if(errorsStr) {
if (errorsStr) {
return "Context cleared with the folloing errors:" + errorsStr;
} else {
return "Context cleared";
Expand All @@ -44,4 +47,8 @@ args:
- "yes"
- "no"
description: if you choose yes - all context will be deleted
- name: keysToKeep
description: Context keys (top-level keys) to keep when deleting all context. Use comma to specify multiple values
scripttarget: 0
runonce: false
releaseNotes: Added the ability to specify context keys to keep when deleting all context