Search code examples
javascriptmicrostrategy

Triggering a context menu click in Microstrategy + Javascript


I am currently working in Microstrategy which is a BI tool platform and I am trying to do an automatic click from a context menu. For some reason I am not able to trigger the click automatically with the code. I was hoping I can get assistance to figure out the value of "this" that way I can pass it through. The ultimate goal is to pass any of the grid_K47 to be remove and the page refresh. Below on the click of the menuClick in real life force the page to refresh which is what I want it to do.

Here is what I know.

The object before the right click is in the table and display this. Please keep in mind that this is all MSTR rendered code.

This is the spot that I right click on

<td id="grid_K47_0_1_1_1" class="c4_K47" dpt="1" dg="TRUE" ds="Area" oid="4216C7074826CF50BC81B8BDEFB99603" style="cursor: pointer; opacity: 0.5;" frmid="CCFBE2A5EADB4F50941FB879CCF1721C" title="Area. Drag object to perform pivot. Right-click for more options" frmlist="ID45C11FA478E745FEA08D781CEA190FE520DESCCCFBE2A5EADB4F50941FB879CCF1721C1-1" or="V" sty="ATT" fe="h1;4216C7074826CF50BC81B8BDEFB99603;UK & Ireland" ax="1" frmname="DESC" oty="12" mx="1" cx="[11,15,16,17,18,19,20,4,26,4,4,29,30,31,32,33,36,37,38]">Area</td>

Then the context menu pulls up and has this section

<tr id="cm1r10" height="18" style="cursor: pointer;" li="var bone = microstrategy.findBone(microstrategy.activeCXMenu); bone.processContextMenus('x');;" onclick="menuClick(this, 'grid_K47_0_GM1');" onmouseout="menuOff(this);" onmouseover="clearTimeout(oSubCTimer); menuOn(this); hideContextSubMenus(1);" ac="true" class="menu-row">

So far I have tested different value for "this" that is in the menuclick function. Here is my latest

HTML

<div style="background-color:#E1E1E1;"> <input type="button" name="RemoveGrid"  id="RemoveGrid" value="Submit" ></div>

Javascript

<script>

$(document).ready(function() {
$("#RemoveGrid").on("click", function (e) {

RemoveGridjs();

});
});
</script>
<script>
function RemoveGridjs() {
var bone = microstrategy.findBone(microstrategy.activeCXMenu); 
bone.processContextMenus('x');;
menuClick('#grid_K47_0_1_1_1', 'grid_K47_0_GM1');
}
</script>

Solution

  • I did some JavaScript customization for MicroStrategy and it was quite a nightmare to figure out how to do things. MicroStrategy, as company, doesn't support JavaScript customization, so there is no documentation for it, also online there is not much you can find.

    I'm not sure which version of MicroStrategy and which visualization you are using (interactive works differently from express mode), anyway my suggestion is to modify the onclick to log this so that you can have an idea about this object is that.

    Something like that:

    jQuery('#cm1r10').click(
      function(){
                  console.log(this)
      }
    );
    

    Another way to tackle the problem is not to try to run the function associated to the menu item, but to simulate the button click on it.

    jQuery("#RemoveGrid").on("click", 
                             function (e) {
                                    jQuery('#cm1r10').trigger('click');
                             }
    );
    

    Not sure if this works if the context menu is not showing on the screen, but I think it's worth a try.

    Anyway I suggest you to use jQuery instead of $ when you are customizing someone else code