Home > Domino Tips > Developer > JavaScript > Ajax code equivalent of the @DBColumn formula for Lotus Notes
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVASCRIPT

Ajax code equivalent of the @DBColumn formula for Lotus Notes


VIKRAM SOLANKI
04.24.2007
Rating: -2.42- (out of 5)


Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Here is the most recent and updated Ajax code equivalent of the @DBColumn formula for Lotus Notes. By using this, you can select the column of your choice and return the results.

Paste the code below on the event that you'd like it to execute -- for example, onClick, onLoad, etc.

ObjCombo1=document.forms[0].combo1;
ObjCombo2=document.forms[0].combo2;

viewname = "testvik";
//dbColumn("serverName","DbName",
viewname,1,Combo1)
keyVal=ObjCombo1.options[
ObjCombo1.selectedIndex].text;

ObjCombo2.length = 0
dbLookup("http://127.0.0.1","R&D/testing.nsf",
 viewname , keyVal , 2, ObjCombo2 )


//Paste the below code on JS Header of the form...

n=0;         // This is for dblookup
 var dbkey = 0;                // This is for dbcolumn

/*---------------------------
Dbcolumn function start here
-------------------*/

function dbColumn(server,path,view,column,Subject)
{
 ObjCombo1=Subject   
 
//Put your first combo name
//here to get dbcolumn result
 var pos=0;

 currURL = (document.location.href).toLowerCase();
 
   if (trim(server) == "")
  {
  pos = currURL.indexOf('://');
  if (pos < 0 )
// Put your server name here,   the server name used 
here is basically for local machine or else not required.
   server = "http://127.0.0.1"  

  else
  {
   pos += 3;
   pos = currURL.indexOf('/', pos);
   server = currURL.substring(0, pos)
 
   }
   }

  if( trim(path) == "" )
  {
   if( pos > 0 )
   {
    newPos = currURL.indexOf('.nsf',pos);
    if (newPos > 0)
    {
path = currURL.substring(pos+1,newPos+4)
        }
    }
    }

  if( !isNaN(column) )
  column -= 1;
  dbkey = column ;


vurl = trim(server)+"/"+trim(path)+
"/"+view+"?Readviewentries"

//checking whether browser is Mozila 
or Netscape
if (window.XMLHttpRequest) 
 {
 req = new XMLHttpRequest();
 req.overrideMimeType('text/xml');
 req.onreadystatechange = 
processReqChange_Col;
 req.open("GET", vurl , true);
 req.send(null);
      } 
//checking whether browser is IE 
else if (window.ActiveXObject)
{
req = new ActiveXObject
("Microsoft.XMLHTTP");
 if (req) 
 {
  req.onreadystatechange
 = processReqChange_Col;
  req.open("GET", vurl, true);
  req.send();
           }
        }
 }


/* Function used to check whether XML file 
loaded completely or not */

function processReqChange_Col() 
{
  if (req.readyState == 4)         
 /*Only process if XML  
file is loaded completely:4="Complete" */
  {
         if (req.status == 200)        
/*Only process if everything is ok*/
    {
  response  = 
req.responseXML.documentElement;   
  populateColumn(response)
        } 
    else 
   {
  alert("There was a problem 
retrieving he XML data:n " + req.statusText);
           }
       }
}

/* Function used to extract value one 
by one from XML file */

function populateColumn(responseXML)
{
 NodeList = 
responseXML.getElementsByTagName("viewentry") 
 
 for (var k=0; k<NodeList.length; k+=1)
  { 
 child = responseXML.
getElementsByTagName('text')[k].
firstChild   
 filterNode = 
responseXML.getElementsByTagName("viewentry") 
 
var filterItem = filterNode.item(k); 
  
  posNumber = 
filterItem.getAttribute("position"); 
  if (( child.nodeType == 3) 
&& (posNumber.indexOf(".")==-1)) 
  { 
  NodeList1 = filterNode[
k].getElementsByTagName("entrydata") 
  for (var m=0; m<
NodeList1.length; m++)
  {
  if (dbkey  == NodeList1[
m].attributes.getNamedItem
("columnnumber").value)
      {   
resultColXML[k] = trim(NodeList1
[m].getElementsByTagName("text")
[0].childNodes[0].nodeValue )
 }
 } 
       }
         }
         var finalresult= 
new Array()
        var tmpstr="";
        var sep="";
           var Duplicateflag =
 " " ;  // This string variable is used to get the 
duplicate values..
    
   for (var p=0;p<
resultColXML.length;p++)
    {  
     if (resultColXML[
p] != '' && resultColXML[p] != null )
      {  
     if ( Duplicateflag.toUpperCase() != 
resultColXML[p].toUpperCase() ) 
// This is to get if the previous value was the 
same as the current one
    
   {

    tmpstr =tmpstr+sep+trim
(resultColXML[p])
 sep="#"
  }
 Duplicateflag= resultColXML[p];          
    } 
    Duplicateflag = 
resultColXML[p];
   }
  finalresult = tmpstr.split("#")
  writeInCombo(finalresult.sort() ,ObjCombo1)
  }

/* Function used to trim string */

function trim(str)
{
return str.replace(/^s+/g, '').replace(/s+$/g, '');
 } 

/*--------------------------- 
writing in combo function start here
 -------------------*/

function writeInCombo(data,fldCombo)
{ 
 fldCombo.length=0
 fldCombo.length +=1
 fldCombo[fldCombo.length-1]
.text = "--Select--"
 
 for(iCount=0;iCount < data.length;iCount++)
 {
  fldCombo.length +=1
  strText=data[iCount]  
  if (strText !=undefined && strText != null)
  { 
    fldCombo[fldCombo.length-
1].text = trim(strText) 
    }
  } 
  }

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • Learning Guide: Ajax
  • Article: The what, how and when of Ajax development
  • Tip: LotusScript version of @DbColumn
  • Tip: JavaScript version of @DBLookup and @DBColumn
  • Reference Center: Notes/Domino Web development tips and resources

    This tip was submitted to the SearchDomino.com tip library by member Vikram Solanki . Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    Rate this Tip
    To rate tips, you must be a member of SearchDomino.com.
    Register now to start rating these tips. Log in if you are already a member.




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



    RELATED CONTENT
    Ajax for Lotus Notes Domino
    Display SharePoint data in a Lotus Notes Web application with Ajax
    Top 10 Lotus Notes Domino programming and development tips of 2007
    Ajax for Lotus Notes Domino
    Editing fields in a Lotus Notes view with Ajax
    A bevy of Notes/Domino development tips
    A smorgasbord of Notes/Domino development tips
    Latest Ajax tools from Nexaweb target SOA, Web 2.0
    Delete documents over the Web using Ajax and JavaScript
    Ajax threats worry researchers
    New chapter and verse on Ajax security

    JavaScript
    Trap JavaScript runtime errors in Domino Web apps
    JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
    Write HTML and JavaScript in Notes view rows and columns on the Web
    JavaScript detects Web browser type and version in Notes/Domino 8.0.2
    JavaScript creates a jump box on a Lotus Notes Web form
    How to create dynamic JavaScript in Notes Domino without formulas
    Trap an attachment path via the Domino file upload control field
    Converting Lotus Notes views to XML documents using JavaScript
    Prevent errors on iFramed pages with JavaScript
    How to add keyboard functionality for Lotus Notes documents

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts