Pandora - Sample - Generate level two list view with web page view button

From SmartWiki
Jump to: navigation, search

Sample - Generate Level Two List View with Web Page View Button

The following function can be used to generate a level two list view from level one record with Web Page View buttons or Read-Only System Variable custom field types.

Sample Code

// leveloneid: Level One record ID
function getLevelTwoListView(leveloneid) {
  ss_developer_key="DEVELOPER_KEY";  // to be replaced with developer key generated in Pandora Configuration page
  var appid=123456;  // UTA ID
  var fields="eventid,$custom field 1$,$custom field 2$";  // fields to retrieve from level 2 using Pandora
  var filter="objectid="+leveloneid;  // filter to be set for getting level 2 records from a given level one record ID
  var order="eventid";  // order by clause
  var rs=level23_find(false,"",appid,2,fields,filter,order,0,50);  // Pandora function to retrieve level 2 objects
  var htmlcontent="";
  if (rs.recordcount>0) {  // check if there is any level 2 record retrieved
    // generating list view for level 2s retrieved
    for (var i=1; i <= rs.recordcount; i++) {
      htmlcontent+="<tr>";
      htmlcontent+="<td>"+rs.getfieldbyname(i,"$custom field 1$")+"</td><td>"+rs.getfieldbyname(i,"$custom field 2$")+"</td>";
      htmlcontent+="<td>"+getWebPageView(rs.getfieldbyname(i,"eventid"))+"</td>";  // add web page view to row
      htmlcontent+="</tr>";
    }
  }
  document.getElementById("contentdiv").innerHTML=htmlcontent;
}

// variables_replace() is a Pandora function to process variables from a given object and content
// objectid: ID value of the object that is to be referenced
// Objecttype: 23=UTA level one; 8=UTA level two and three; 30=company; 40=user/contact; 78=transaction; 122=UTA Invoices; 5=Sales opportunity
function getWebPageView(objectid) {
  var objecttype=8;  // id to indicate what kind of object to retrieve custom field from
  var content="@custom field name@";  // content storing syntax to get web page view button from the desired object
//var content="@#customfieldid#@";  // OR Use Custom field ID of the web page view

  var rs=variables_replace(false,"",objecttype,objectid,content);  // Pandora function called to process the web page view button for the given level two
  return rs.getfieldbyname(1,"msg");  // returns HTML code for web page view button
}