REQUEST A DEMO

Customizing the executeCommand actions in fcClient

In a previous post, I covered how to have fcClient pop a page based on a URL. Now, we’ll cover how to customize this functionality to perform your own actions.

For this particular example, we’ll show how to have an existing fcQuery query get executed and the results posted.

1. In console.asp, we’ll add code to get the actual objid of the query based on the query name, for the current user. This is necessary because the query names are not unique across the system.  

In console.asp, after this existing code:

var CommandToExecute = Request(“command”) + ”;
var CommandParam1 = Request(“param1″) + ”;
var CommandParam2 = Request(“param2″) + ”;

We’ll add this:

if (CommandToExecute=="executeQuery"){
  //get the query objid
  //first, see if this user ownes this query
  var gen = FCSession.CreateGeneric('ce_query');
  gen.AppendFilter('ce_query2user','=',FCSession.Item('user.id'));
  gen.AppendFilter('query_name','=',CommandParam1);
  gen.Query();
  if (gen.Count() > 0){
    CommandParam1 = gen.Id - 0;
  }else{
    //see if this query was shared to this user
    gen.CloseGeneric();
    gen=null;
    var gen = FCSession.CreateGeneric('ce_query');
    gen.TraverseFromRoot(FCSession.Item("user.id"),"user","shared_queries2ce_query");
    gen.AppendFilter('query_name','=',CommandParam1);
    gen.Query();
    if (gen.Count() > 0){
      CommandParam1 = gen.Id - 0;
    }else{
      //Not found
      CommandToExecute = "";
      CommandParam1 = "";
    }
  }
  gen.CloseGeneric();
  gen=null;
}

2. In console.asp, there’s an ExecuteCommand function, which is responsible for executing the actual command.

We’ll add a new case statement in this function for our new command:

case “executeQuery”:
  var queryObjid = CommandParam1;
  OpenCEResults(queryObjid,’edit’);
  break;

 

3. In ce_results.asp, I made one additional change, so that it doesn’t try to close the console page:

function onload() {
  try {
    //changed the following line:
    //if(window.opener.name != 'explorer') {
    if(window.opener.name != 'explorer' && opener.name != 'console') {
      window.opener.close();
    }
  } catch(e) {};

  load_results();
}

 

4. Test

Pass in a command of executeCommand and set param1 equal to the name of the query
Examples:
http://localhost/fcclient/console/console.asp?command=executeQuery&param1=cases%20in%20last%2090%20days
http://localhost/fcclient/console/console.asp?command=executeQuery&param1=By Site Name

If there are changeable parameters, the query parameters page will be posted that prompts users for the parameters.

Have fun!