Visokio website     Downloads     Video tutorials     KnowledgeBase  
Modifying Field Data using Scripts - Visokio Forums
Modifying Field Data using Scripts
  • sjhstott August 31, 2012 7:14AM
    Hi there - I'm trying to write a small piece of Javascript in Omniscope which reads in a list of names, and then scans a field of strings for any strings that contain any of those names, and then adds another little piece of text onto the end of the string so that those records will not be deleted by a record filter later on in the process. My problem is that I cannot seem to modify the records in the script (as required) no matter what method I try. I had thought that the function "Replace" would work, but this is not supported by the scripting module. Help please! Code is below (I am not much of a programmer)

    script(`
    var array1 = subset_uniquesList("Operator");
    var array2 = subset_uniqueslist("Con_L2Callstackdesc");
    for (var i in array2) {
    for (var j in array1) {
    var str=array2[i];
    var n=str.search(array1[j]);
    if (n != -1) {
    subset("Con_L2Callstackdesc",array2[i]) += "DINGDING"
    }
    }
    }
    `,[Con_L2Callstackdesc],[Operator])
  • 6 Comments
  •     michael August 31, 2012 10:07AM
    Hi Justin - Can you attach here an example file with some abstract dummy data (1,2,3..), the script and describe in which part of Omniscope you are using the script and the result you are trying to achieve (do you want to change the actual data in the DataManager or you want to show the result in the Content View?).
  • sjhstott August 31, 2012 10:23AM
    Hi Michael - Attached is the Excel file. Column A is the list of names and Column B is the list of records. What I need to do is scan all the records (there are 10,000+ of them) for any of the (currently 28) names and keep the entries where there is a match. In the excel example attached, this would return only 2 results,

    I am attempting to use the above script (which is correct apart from the "subset("Con_L2Callstackdesc",array2[i]) += "DINGDING" " bit - con_L2etc is the name of the call stacks field. The script is in a formula in a field organiser operation, being performed on "Operators" field. I don't need to modify the source data, just publish a spreadsheet at the end with all teh callstacks that have names in them, and none of those without.

    I have successfully done this by entering all 28 names into a record filter and using the "contains" operator - but this process is not automatics, and should a name be added that record filter would have to be changed manually. Rather, we want to read them in from a spreadsheet (hence "var array1 = subset_uniquesList("Operator");") so its automatic.

    What I wanted to do with the above script is essentially what I did with the record filter in the manual version - but I can't seem to do it. HELP! I only started using Omniscope 3 days ago, and my Java is... non-existent, though my c++ is reasonable.
  •     tjbate August 31, 2012 11:56AM
    Justin - Currently, record filter only supports single-value filtering, but Merge/Join works just as well for filtering against defined lists since you can branch/keep only the matching records.

    Try simply defining a DataManager flow that uses a List of Values input block (paste the current values for the 28+ names from Excel) and then a Merge block to find the matching records in the main data set...channel only the matching names to another Field Organiser block for further formula text processing e.g. concatenating more text strings using "+" or "&"....then Appending the target names data sets (as changed) back on the bottom of the non-matching main data set....
  • sjhstott September 3, 2012 4:08AM
    TJ - Thanks, but I've tried using "merge" as my filter.... I can't find a way to make the merge operator do anything other than perform an exact match, whereas I need to match the name to only a part of the string - the "contains" in the record filter, or "InStr" in many languages, if you will. The Merge operator either brings all 10,000 or it only brings the unique values from one of the lists...
  •     michael September 3, 2012 10:07AM
    Hi Justin - Use the demo IOK file in the attachment as an example.
    There are two records with true value in the "New field". You can filter them by adding another DM block.


    SCRIPT("

    function foo(checkList, val) {
    var checkList = checkList.split(',');

    for (var i in checkList) {
    var str=checkList[i];
    var n=val.search(str);
    if (n != -1) {
    return true;
    }
    }
    return false;
    }

    foo(checkList, val);

    ", "checkList", SUBSET_UNIQUESLIST([Operators]), "val", [Callstacks (reports)], 1000)


    image
  • sjhstott September 3, 2012 10:50AM
    Hi Michael,

    Thanks that's great. I managed to solve the problem in 2 other ways eventually, first by reading all the names in, aggragating them, using search and replace to remove the commas from the aggregated string and replacing them with "|" ("or" operator for regular expressios) and then using the regular expression search to filter all the correct entries. Alternatively, creating a configuration table for batch publishing using the list of names and then running a "contains" filter in the batch publish achieves the same result.

    Many thanks,
    Justin
This discussion has been closed.
← All Discussions

Welcome!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Tagged