• header.categories
    • header.recent
    • header.tags
    • header.popular
    • register
    • login

    Control/display operations via script

    scheduled pinned locked moved Scripts
    operationscustom widgetscriptjavascript
    1 posts 1 posters 3.2k views 1 watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • jkandasaJ offline
      jkandasa
      global: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.

      one-reply-to-this-post last-reply-time reply quote 0
      • first-post
        last-post

      0

      online

      644

      users

      532

      topics

      3.4k

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