• Categories
    • Recent
    • Tags
    • Popular
    • Register
    • Login

    Control/display operations via script

    Scheduled Pinned Locked Moved Scripts
    operationscustom widgetscriptjavascript
    1 Posts 1 Posters 3.1k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jkandasaJ Offline
      jkandasa
      last edited by

      To list operations on Dashboard.

      Script: JavaScript
      var myImports = new JavaImporter(java.io, java.lang, java.util);
      
      with(myImports) {
        var filters = new HashMap();
        filters.put("orderBy", "name");
        filters.put("order", "asc");
        filters.put("pageLimit", new Long(10));
        //Get operations data
        var operations = mcApi.operation().getAll(filters);
      }
      
      Template:
      <table class="table table-hover table-bordered table-striped mc-table">
        <thead>
          <th>{{ 'STATUS' | translate }}</th>
          <th>{{ 'ID' | translate }}</th>
          <th>{{ 'NAME' | translate }}</th>
          <th>{{ 'OPERATION' | translate }}</th>
          <th>{{ 'LAST_EXECUTION' | translate }}</th>
        </thead>
        <tbody>
          <#list operations.data as item>
            <tr ui-sref="operationsAddEdit({id: ${item.id} })">
              <td class="text-center">
                <#if item.enabled>
                  <i class="text-success fa fa-circle fa-lg" uib-tooltip="{{ 'ENABLED' | translate }}"></i>
                <#else>
                  <i class="text-danger fa fa-circle-o fa-lg" uib-tooltip="{{ 'DISABLED' | translate }}"></i>
                </#if>
              </td>
              <td>${item.id}</td>
              <td>${(item.name)!}</td>
              <td ng-bind-html="'${(item.operationString)!}' | mcResourceRepresentation"></td>
              <td><span uib-tooltip="{{ ${(item.lastExecution?c)!"Never"} | date:mchelper.cfg.dateFormat:mchelper.cfg.timezone}}" tooltip-placement="left" am-time-ago="${(item.lastExecution?c)!"Never"}"></span></td>
            </tr>
          </#list>
        </tbody>
      </table>
      

      To enable/disable list of operations:

      JavaScript

      Script bindings: {options:{name:"operation-name", enable:false}}
      Important: It is important to pass Script bindings when executing this script. In the binding you can include your operation name to filter. Please note in Mycontroller all filters are working with case sensitive. In the name filed you can put any words where operation name contains.

      For example I want to enable or disable following operations,

      • my send email notification operation
      • notification: pushbullet

      In the above names I have notification word in common. So I can use this name in filter to get these operations exactly.

      To disable:

      {options:{name:"notification", enable:false}}

      To enable:

      {options:{name:"notification", enable:true}}

      var myImports = new JavaImporter(java.io, java.lang, java.util);
      
      with(myImports) {
        var filters = new HashMap();
        var names = new ArrayList();
        names.add(options.name);
      
        filters.put("orderBy", "name");
        filters.put("order", "asc");
        filters.put("pageLimit", new Long(10));
        filters.put("name", names)
      
        //Get operations data
        var operations = mcApi.operation().getAll(filters);
        
        var operationIds = new ArrayList();
        for(var count =0 ; count<operations.data.length;count++){
          //You can do some filter here
           operationIds.add(operations.data[count].id);
        }
        
        if(options.enable){
         mcApi.operation().enableIds(operationIds);
        }else{
         mcApi.operation().disableIds(operationIds);
        }
      }
      

      SOURCE: refer this issue for complete details.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post

      0

      Online

      587

      Users

      529

      Topics

      3.4k

      Posts
      Copyright © 2015-2025 MyController.org | Contributors | Localization