ContextGetPathForString

Searches for string in context and returns context path, returns null if not found.

javascript · Common Scripts

Source

var path = args.path
var str = args.str;
var flat = {};

function searchString(obj) {
    flattenFields(obj,undefined,flat);
    keysArr = Object.keys(flat);
    for (i = 0; i < keysArr.length; i++) {
        if (flat[keysArr[i]] === str) {
            return keysArr[i]
        }
    }
    return null;
}

if (!path) {
    return searchString(invContext);
}

var contextObject = dq(invContext, path);

if (!contextObject) {
    throw 'Path ' + path + ' is not in the context.';
}

return searchString(contextObject);


README

Searches for a string in context and returns the context path, it will return null if nothing is found.

Script Data


Name Description
Script Type javascript
Tags  

Inputs


Argument Name Description
path The path in context to search the string in. If the path is not given, the search will be in the whole context.
str The string to search for in context.

Outputs


There are no outputs for this script.