Skip to main content

widget: get RITMs linked to HR case

RITMs generated from HR workflow via an order guide, where a common hr_case_ref variable is in use on the RITMs and populated via the HR workflow (passed from order guide to child RITM)



 
HTML
___________________________

<title>Check RITMs for the HR Case</title>
<div class='container'>
<!-- your widget template -->
 <table width="100px" border="0">
 
   <tr><td>
     <br/>
     <label>Enter HR Case number here:</label>
     <input value='HRM0000126' id='hr_case'/>
     <br/>
   </td></tr>
   <tr><td>
     <label>Enter order guide name here (optional):</label>
     <input id='order_guide' ng-model="inputOG">
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <button ng-click="blankOrderGuideField()" class="btn btn-danger action-btn pull-center">Blank</button>
   <tr><td>
     <br/><br/><br/><br/><br/>
 <button ng-click="runtheoperation()" class="btn btn-danger action-btn pull-left">Click to check RITMs</button>
   </td></tr>
     <tr><td><br/><br/>
   <label><b>Results:</b></label>
  <br/><br/>
   <textarea id='results_q' rows="10" cols="100">{{c.ritmsList}}</textarea>
</td></tr>
  </table>
</div>

___________________________
CSS
___________________________


.container {
  clear: both;
  text-align:left;
  align-content: left;
}

.container input {
  width: 100px;
  clear: both;
}

.container label {
  width: 150px;
  clear: both;
}

.container textarea {
  color:black;
}

.container td {
  text-align: left;
}

.container td2 {
  width:20%;
}

.container table {
  width:100%;
}




___________________________
client script
___________________________


function($scope) {
  /* widget controller */
  var c = this;
   
    c.ritmsList='click to see results';
  $scope.inputOG='Staff Joiner - ICT';
 
    $scope.runtheoperation = function() {
        //console.log("message", 'run the op');

  if (angular.element($('#hr_case')).val()==''){
alert('missing hr case');
}else{

             c.server.get({
             action: "get_ritms",
             msg : "Checking for RITMs...",
             hrCase : angular.element($('#hr_case')).val(),
   orderGuide : angular.element($('#order_guide')).val()
           }).then(function(r){
             
            var ritmsResult=r.data.ritmsList;
            c.ritmsList=ritmsResult.join('\n');
        });
     }
  };
___________________________
server script
___________________________

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
    data.ritmsList=[];
  //data.ritmsTotal=0;
    if (input && input.action === "get_ritms"){
//gs.addInfoMessage(input.hrCase);
// gs.addInfoMessage(input.orderGuide);
        data.ritmsList=(checkRitms(input.hrCase, input.orderGuide));
  // gs.addInfoMessage(data.ritmsList.length);
}
function checkRitms(hrCase, orderGuide){
var ritmsArr=[];
var grvars=new GlideRecord('item_option_new');
   //var sQuery='name=hr_case_ref';
  var sQuery=gs.getProperty('sp.variablename.query');
   grvars.addQuery(sQuery);
var ritmsURL='url:\n';
ritmsURL+=gs.getProperty('glide.servlet.uri');
ritmsURL+='nav_to.do?uri=sc_req_item_list.do?sysparm_query=numberIN';

grvars.query();
   var sEncQuery='variables.';
   var bLocated=false;
var iCounter=0;
   while (grvars.next()){
      var gr= new GlideRecord('sc_req_item');
      gr.addQuery('variables.' + grvars.sys_id + 'LIKE' + hrCase);
      if (!gs.nil(orderGuide)){
      gr.addQuery('order_guide.name='+orderGuide);
      }
  gr.query();
      if(gr.next()){
     bLocated=true;
         ritmsArr.push(gr.number + ': ' + gr.short_description + ' [orderGuide: ' + gr.order_guide.name + ']');
ritmsURL+=gr.number;
ritmsURL+=',';
iCounter++;
      }
    }
if (!bLocated){
ritmsArr.push('No RITMs as yet. Check the HR Case workflow has progressed?')
}else{
ritmsArr.push('Total records: ' + iCounter);
     var ritmsURL=ritmsURL.slice(0, -1);//--remove the last ,
ritmsArr.push(ritmsURL);
}
return ritmsArr;
}
 
})();

Comments

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){...

Code a pause/wait - gs.sleep or gs.wait alternative, pause script for specified seconds (timer)

Code a pause/wait - gs.sleep / gs.wait alternative, pause script for specified seconds (timer)  e.g. 10 seconds: do_sleep ( 10000 ); function do_sleep ( milliseconds ) { var start = new Date (). getTime (); for ( var i = 0 ; i < 1e7 ; i ++) { if (( new Date (). getTime () - start ) > milliseconds ){ gs . print ( 'waking up!' ); break ; } } }