Topic
  • 5 replies
  • Latest Post - ‏2012-12-10T04:38:07Z by SystemAdmin
BJordan
BJordan
25 Posts

Pinned topic trouble with lookup table creation script

‏2012-10-08T10:04:16Z |
Hi!

I'm having some difficulties populating lookup tables programmatically.
I could populate simple lookup table (id/name, id is sequence), like this:


put(
"MY LOOKUP", 
"", 
"My value 1"); put(
"MY LOOKUP", 
"", 
"My value 2");

The problem is, if i have a more complex lookup table, like (id/name/data), i couldn't populate it:

put(
"MY LOOKUP", 
"", 
"My name", 
"My data");

or

var values = []; values.add(
"My name", 
"My data"); put(
"MY LOOKUP", 
"", values);

or

var values = []; values.add(
"", 
"My name", 
"My data"); put(
"MY LOOKUP", 
"", values);

or

var lookup = getLkpByName(
"MY LOOKUP"); var values = []; values.add(
"My name", 
"My data"); lookup.addRow(lookup, 
"", values);


doesn't work.

Any example would be highly appreciated!

Thanks in advance.
Updated on 2012-12-10T04:38:07Z at 2012-12-10T04:38:07Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: trouble with lookup table creation script

    ‏2012-10-08T10:30:04Z  
    Hi,

    I have the following working code. It might you have to set PK to none empty value to add a row into a lookup table
    
    ... var lkpTable = getLkpByName(
    "Colarea codes"); var values = lookupValues(lkpTable, 
    "COLAREA_ADD_"+orgCode); var caName = checkString(values[2], 
    ""); 
    
    if(caName == 
    "") 
    { caName = colareaName; var newValues = []; newValues.add(orgCode); newValues.add(
    "Создание"); newValues.add(colareaName); newValues.add(
    "Классификация и заполнение атрибутов"); put(
    "Colarea codes", 
    "COLAREA_ADD_"+orgCode, newValues); 
    } ...
    
  • BJordan
    BJordan
    25 Posts

    Re: trouble with lookup table creation script

    ‏2012-10-09T08:02:33Z  
    Hi,

    I have the following working code. It might you have to set PK to none empty value to add a row into a lookup table
    <pre class="jive-pre"> ... var lkpTable = getLkpByName( "Colarea codes"); var values = lookupValues(lkpTable, "COLAREA_ADD_"+orgCode); var caName = checkString(values[2], ""); if(caName == "") { caName = colareaName; var newValues = []; newValues.add(orgCode); newValues.add( "Создание"); newValues.add(colareaName); newValues.add( "Классификация и заполнение атрибутов"); put( "Colarea codes", "COLAREA_ADD_"+orgCode, newValues); } ... </pre>
    I'm out of luck...

    Maybe i should open PMR?

    
    
    // building spec var spec = buildSpec(
    "TEST SPEC", 
    "LKP_SPEC");   
    // with key var node1 = 
    
    new SpecNode(spec, 
    "id", 1); node1.setAttribute(
    "TYPE", 
    "STRING"); node1.setAttribute(
    "MAXLENGTH", 
    "18");   
    // and two attributes var node2 = 
    
    new SpecNode(spec, 
    "name", 2); node2.setAttribute(
    "TYPE", 
    "STRING"); node2.setAttribute(
    "MAXLENGTH", 
    "255"); node2.setAttribute(
    "MIN_OCCURRENCE", 
    "1"); node2.setNodeIndexed(
    
    true);   var node3 = 
    
    new SpecNode(spec, 
    "value", 3); node3.setAttribute(
    "TYPE", 
    "STRING"); node3.setAttribute(
    "MAXLENGTH", 
    "255"); node3.setAttribute(
    "MIN_OCCURRENCE", 
    "1");   spec.setPrimaryKeyPath(
    "TEST SPEC/id");   spec.saveSpec();   
    // building lookup var atts = []; var spec = getSpecByName(
    "TEST SPEC");   var node  = spec.getNodeByPath(
    "TEST SPEC/name");   atts[
    "displayAttribute"] = node; 
    //atts["accessControlGroup"] = "Default"; atts[
    "isLookupTable"] = 
    
    true;   var tree = getCategoryTreeByName(
    "Default Lookup Table Hierarchy"); var lookup = 
    
    new Catalog(spec, 
    "TEST LOOKUP", tree, atts);   
    // adding elements to lookup: key:"MY KEY", row:("MY NAME", "MY VALUE") var myrow = [];   myrow.add(
    "MY NAME", 
    "MY VALUE");   put(
    "TEST LOOKUP", 
    "MY KEY", myrow);
    


    Could not put a row in a lookup table...
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: trouble with lookup table creation script

    ‏2012-10-09T08:33:33Z  
    • BJordan
    • ‏2012-10-09T08:02:33Z
    I'm out of luck...

    Maybe i should open PMR?

    <pre class="jive-pre"> // building spec var spec = buildSpec( "TEST SPEC", "LKP_SPEC"); // with key var node1 = new SpecNode(spec, "id", 1); node1.setAttribute( "TYPE", "STRING"); node1.setAttribute( "MAXLENGTH", "18"); // and two attributes var node2 = new SpecNode(spec, "name", 2); node2.setAttribute( "TYPE", "STRING"); node2.setAttribute( "MAXLENGTH", "255"); node2.setAttribute( "MIN_OCCURRENCE", "1"); node2.setNodeIndexed( true); var node3 = new SpecNode(spec, "value", 3); node3.setAttribute( "TYPE", "STRING"); node3.setAttribute( "MAXLENGTH", "255"); node3.setAttribute( "MIN_OCCURRENCE", "1"); spec.setPrimaryKeyPath( "TEST SPEC/id"); spec.saveSpec(); // building lookup var atts = []; var spec = getSpecByName( "TEST SPEC"); var node = spec.getNodeByPath( "TEST SPEC/name"); atts[ "displayAttribute"] = node; //atts["accessControlGroup"] = "Default"; atts[ "isLookupTable"] = true; var tree = getCategoryTreeByName( "Default Lookup Table Hierarchy"); var lookup = new Catalog(spec, "TEST LOOKUP", tree, atts); // adding elements to lookup: key:"MY KEY", row:("MY NAME", "MY VALUE") var myrow = []; myrow.add( "MY NAME", "MY VALUE"); put( "TEST LOOKUP", "MY KEY", myrow); </pre>

    Could not put a row in a lookup table...
    I think you don't need to open a PMR.
    try to use new LookupTable(Spec spec, String name) for a lookup table cteation instead new Catalog
  • BJordan
    BJordan
    25 Posts

    Re: trouble with lookup table creation script

    ‏2012-12-08T14:27:37Z  
    I think you don't need to open a PMR.
    try to use new LookupTable(Spec spec, String name) for a lookup table cteation instead new Catalog
    Alexander,

    Changing "Catalog" to "LookupTable" didn't change anything, i still cannot "put" multivalued rows... (
  • SystemAdmin
    SystemAdmin
    648 Posts

    Re: trouble with lookup table creation script

    ‏2012-12-10T04:38:07Z  
    • BJordan
    • ‏2012-12-08T14:27:37Z
    Alexander,

    Changing "Catalog" to "LookupTable" didn't change anything, i still cannot "put" multivalued rows... (
    Hi,

    I tested your code and also got a negative result. But after I set *Minimum Occurrence*=0 for spec attributes name and value it began work.