Cognos tree prompt automatic search function



1) add html tag "json2.js",

input  json2.js source file, can download from google.

2) upload json file to server, the search function will search data from json file

3) add html tag "JsonData" and input file as

<script type="text/javascript" src="../common/json/jsonfilename.json"></script>

4) add html tag "prompt function"

<script type="text/javascript" >
function setTreevalue1(){
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
  if (fW)
 {

if (fW.elements["cv.id"] ) {  if (fW.elements["cv.id"].value == "RS") {
  //alert('RS');
 var end = '\',CVId:\'RS\'}'; //edit mode
}
 else
 {
 //alert('NS');
 var end = '\',CVId:\'_NS_\'}';//nomarl mode
 }
 } else {
    var end = '\',CVId:\'\'}';
    //alert('null');
    }
 }
//oCV_NS_.promptAction('reprompt');
var str = document.getElementById("searchPromptName").getElementsByTagName("input")[1].value;
var res =str.split(",");
var nodeStr ="";
var nodePStr ="";
var tableId=document.getElementById("treePromptName").getElementsByTagName("div")[0];
var id_str = tableId.id.replace("PRMT_", "");
var start= '{_id_:\'';
var then = start.concat(id_str );
var max = then .concat(end );
var obj = eval("(" + max + ')');// tree ID
//----this part need to change -----------------
var promptType ='MG';
var promptName ='[Presentation View]...-\\\\U003E[all]';
var treeName = 'treeName';
var treeParameterName ='treeName';
var queryName ='treePromptQueryName';

//alert('1111111111111111');

 var MGPData= JSON.parse(data1);
//----this part need to change -----------------
//check imput value length
if (res.length>10) {
alert('The maximum number of 10 DSMT Ids has been exceeded. Please resubmit with 10 or less' ); 
}
//alert('2222222222');

//---Get node
  for (var j=0;j<MGData.length;j++){
  var nodeElement = MGData[j].K;
    for (var i = 0; i < res.length; i++){
    var element= res [i];
     if (MGData[j].K ==element) {
       if (nodeStr==""){
       nodeStr ='{n:\'selectOption\',\"@useValue\":\"'+'[Presentation View]...'+MGData[j].V.replace('_]','_NAME]-\\\\U003E[all]') +'\"\,\"@nullDisplay\":\"1\"}';
       } else{
       nodeStr ='{n:\'selectOption\',\"@useValue\":\"'+'[Presentation View]...'+MGData[j].V.replace('_]','_NAME]-\\\\U003E[all]') +'\"\,\"@nullDisplay\":\"1\"},'+nodeStr ;
      }
     }
    }
  }
//alert(nodeStr );  
//--get parent node
for (var j=0;j<MGPData.length;j++){
  var nodeElement = MGPData[j].K;
  
  for (var i = 0; i < res.length; i++){
    var element= res [i];
    if (MGPData[j].K ==element) {
    var matchElement = MGPData[j].V;
    
          if (nodePStr.indexOf(matchElement)==-1){
       nodePStr ='{n:\'selectOption\',\"@useValue\":\"'+'[Presentation View]...'+MGPData[j].V.replace('_]','_NAME]-\\\\U003E[all]') +'\"},' +nodePStr ;  }
     
      
       }
    }
  }
//alert(nodePStr);
//console.log(nodePStr);
jsonObj =
  '{n:\'selectWithTree\',\"@layoutClass\":\"selectWithTree\",\"@name\":\"'+treeName+'\",\"@parameter\":\"'+treeParameterName+'\",\"@required\":false,\"@hideAdornments\":false,\"@multiSelect\":true,\"@refQuery\":\"'+queryName +'\",\"@prePopulateIfParentOptional\":false,'+
'\"@rowsPerPage\":\"5000\",\"@refDataItem\":\"'+promptType+'\",\"@canExpand\":true,\"@style\":\"width:350px;height:250px\",'+
'c:[{n:\'selectChoicesAncestry\','+
'c:['+  nodePStr  + '{n:\'selectOption\',\"@useValue\":\"'+promptName+'\"}'+']'+
'},'+
'{n:\'selectChoices\','+
'c:['+nodeStr+']},'+
'{n:\'selectOptions\',\"@memberDisplayCountDefault\":\"50\",\"@memberDisplayCountLimit\":\"100\",\"@maximumValueCount\":\"50\",\"@skipValueCount\":\"0\",\"@moreData\":false,'+
'c:[{n:\'selectTreeOption\',\"@layoutClass\":\"selectWithTreeItem\",\"@refDataItem\":\"'+promptType+'\",\"@useValue\":\"'+promptName+'\",\"@displayValue\":\"'+promptType+'\"}]'+
'}]}';
//alert(jsonObj);
//console.log(jsonObj);
var part1='{n:\'selectWithTree\',\"@layoutClass\":\"selectWithTree\",\"@name\":\"'+treeName+'\",\"@parameter\":\"'+treeParameterName+'\",\"@required\":true,\"@hideAdornments\":false,\"@multiSelect\":true,\"@refQuery\":\"'+queryName +'\",\"@prePopulateIfParentOptional\":false,'+
'\"@rowsPerPage\":\"5000\",\"@refDataItem\":\"'+promptType+'\",\"@canExpand\":true,\"@style\":\"width:350px;height:250px\",'+
'c:[{n:\'selectChoicesAncestry\','+
'c:['+  nodePStr  + '{n:\'selectOption\',\"@useValue\":\"'+promptName+'\"}'+']'+
'},';
var part2='{n:\'selectChoices\','+
'c:['+nodeStr+']},';
var part3='{n:\'selectOptions\',\"@memberDisplayCountDefault\":\"50\",\"@memberDisplayCountLimit\":\"100\",\"@maximumValueCount\":\"50\",\"@skipValueCount\":\"0\",\"@moreData\":false,'+
'c:[{n:\'selectTreeOption\',\"@layoutClass\":\"selectWithTreeItem\",\"@refDataItem\":\"'+promptType+'\",\"@useValue\":\"'+promptName+'\",\"@displayValue\":\"'+promptType+'\"}]'+
'}]}';
// console.log(part1);
 //console.log(part2);
// console.log(part3);
var objMy = eval("(" + jsonObj + ')')
if (fW)
 {
  if (fW.elements["cv.id"] ) {
    if (fW.elements["cv.id"].value == "RS") {
   //alert('RS');
   G_PMRS.F_Add(objMy ,obj);

    }
 else
 {
   //alert('NS');
  G_PM_NS_.F_Add(objMy ,obj);
 }
 }else {
  //alert('this');
  G_PM_THIS_.F_Add(objMy ,obj);

}
}
}
</script>


5 add html tag "button"

<button style="" class="bp"
onmouseover=""
onmouseout="" onClick="setTreevalue1();">Search</button>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章