Search code examples
javascriptxpagesprofile

Alternative for profile document


I'm following the article that tells us how to store global parameters, how profile documents work for classic Notes applications. I followed the steps of the article and implemented the classes according to the necessary globular parameters, however when I call a method of the javascript object the error below happens. I'm kind of confused because calling this same method elsewhere in the application works normally. Below is the code for the javascript object, implemented as the example in the article.

Script interpreter error, line=12, col=21: [TypeError] Error calling method 'getDbRH()' on an object of type 'java.util.HashMap [Dynamic Java Wrapper, java.util.HashMap]'

var dbFotoConfig = { 

getDbFoto : function ( ) { 

    var cache = this. getCacheObject ( ) ; 

    var result = cache.get( "DbFoto" ) ; 

    if (result == null ) {

        // Here is where you would do @DBSomething or worse
        var visao:NotesView=database.getView("Configuracoes")
        var doc:NotesDocument=visao.getFirstDocument();
        if (doc!=null)
        {

            result=  [doc.getItemValueString("servidor_foto"),doc.getItemValueString("base_foto"),doc.getItemValueString("visao_foto")]
            cache.put("DbFoto",result)
             sessionScope.put ( "dbFotoConfig" ,cache )
        }
        else
        {

        cache.put("DbFoto",null)
         sessionScope.put ( "dbFotoConfig" ,null )
        }           

    } 

    return result ; 
} , 


    /* Here would be much more of these functions */ 


    /* Utility functions for cache management */ 

/* Retrieves the configuration object from a cache store. 
   There are many ways to do that */ 
getCacheObject : function ( ) { 
    // Consider carefully where to cache. Typical places 
    // are sessions or applications 
    var curCache = sessionScope. get ( "dbFotoConfig" ) ; 
    if (curCache == null ) { 
        curCache = new java. util. HashMap ( ) ; 
        sessionScope. put ( "dbFotoConfig" ,curCache ) ; 
    } 

    return curCache ;     
} , 

/* Resets the cache */ 
reset : function ( ) { 
    var curCache = new java. util. HashMap ( ) ; 
    sessionScope. put ( "dbFotoConfig" ,curCache ) ; 
} 
}
var dbRHConfig = {

getDbRH : function ( ) { 

var cache = this. getCacheObject ( ) ;

var result = cache. get ( "DbRH" ) ;

if (result == null ) {

    // Here is where you would do @DBSomething or worse
    var visao:NotesView=database.getView("Configuracoes")
    var doc:NotesDocument=visao.getFirstDocument();
    if (doc!=null)
    {

        result=[doc.getItemValueString("servidor_RH"),doc.getItemValueString("base_RH"),doc.getItemValueString("visao_RH")]
        cache.put("DbRH",result)
         sessionScope.put ( "dbRHConfig" ,cache )
    }
    else
    {

        cache.put("DbRH",null)
     sessionScope.put ( "dbRHConfig" ,null )
    }


} 

return result ; 
} , 


/* Here would be much more of these functions */ 


/* Utility functions for cache management */ 

/* Retrieves the configuration object from a cache store. 
There are many ways to do that */ 
getCacheObject : function ( ) { 
// Consider carefully where to cache. Typical places 
// are sessions or applications 
var curCache = sessionScope. get ( "dbRHConfig" ) ; 
if (curCache == null ) { 
    curCache = new java. util. HashMap ( ) ; 
    sessionScope. put ( "dbRHConfig" ,curCache ) ; 
} 

return curCache ;     
} , 

/* Resets the cache */ 
reset : function ( ) { 
var curCache = new java. util. HashMap ( ) ; 
sessionScope. put ( "dbRHConfig" ,curCache ) ; 
} 
}

Solution

  • My preferred option is to create a normal document, save it, then call setUniversalID() to change it to something custom using session.evaluate("@Password(\"whateverYouWant\")"). @Password hashes the value to a 32-character hexadecimal string (i.e. a valid UNID). This allows you to easily retrieve the document (a normal document, so avoiding the caching issues of Profile documents) using Database.getDocumentByUnid() which is one of the quickest ways to access a document. You can store the "UNID" in an applicationScope variable if you want to avoid calculating it every time.