Wednesday, May 17, 2017

UI Macro for the ProgressBar - Jelly Scripting

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="true" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<j:set var="jvar_renderer" value="SimpleProgressBar"/>

<g:evaluate var="jvar_choices" jelly="true" object="true">

    // get the api
    var api = new SNC.RendererAPI('$[jvar_renderer]');
    var showValue = api.getOption('showValue')+'';
   
    // build the full set of choices including subflows
    var choices = api.getParentWorkflowChoices(current, jelly.jvar_ref);
 
    choices;
</g:evaluate>

<g:evaluate var="jvar_increment" jelly="true" >
    var increment = 100.00 / choices.getSize();
    var percentComplete = 0;
    var atEnd = true;

    for (var i = 0; choices.getSize() > i; i++) {
        percentComplete += increment;
        if (choices.getChoice(i).getParameter('state')+'' === 'active') {
            atEnd = false;
            break;
        }
    }

    percentComplete = atEnd ? 100 : parseInt(percentComplete);

    increment;
</g:evaluate>


<j:set var="jvar_t" value="$[jvar_ref]" />

<table id="workflow.progress" border="1" cellpadding="0" cellspacing="0"
       style="width:100%; margin-top: 2px; background-color: transparent;" >

<j:if test="$[showValue]">
  <tr>
      <td colspan="${choices.getSize()}" style="width:100%; font-size:10px; border:none; text-align:center; background: #000066 url('progress_pctnotdone.gifx') repeat-x;">
          ${showValue==='true' ? percentComplete+'%' : ' '}
      </td>
  </tr>
</j:if>

  <tr id="progress">
   
  <j:forEach var="jvar_choice" items="$[jvar_choices]">
    <g:evaluate var="jvar_choice_visible" jelly="true">
        var isVisible = true;
        if (!api.getOption('showSkipped'))
            if (jelly.jvar_choice.getParameter('state')+'' == 'skipped')
                isVisible = false;

        if (jelly.jvar_choice.value == '')
            isVisible = false;

        isVisible;
    </g:evaluate>

    <g:evaluate var="jvar_image" jelly="true">
        var imgsrc = 'progress_pctnotdone.gifx';
        if (jelly.jvar_choice.getParameter('state')+'' != 'pending')
              imgsrc = 'progress_pctdone.gifx';
        imgsrc;
    </g:evaluate>
     
    <j:if test="$[jvar_choice_visible]">
      <td nowrap="true" style="width:${jvar_increment}%; border-left:none; border-top:none; border-bottom:none; border-right: 1px solid white;  background: #000066 url('${imgsrc}') repeat-x;">
          $[SP]
      </td>
    </j:if>
  </j:forEach>

</tr>
</table>


</j:jelly>

Mark users as VIP based on their Group


var vip_grm = new GlideRecord('sys_user_grmember');
vip_grm.addQuery('group', 'SNVIP');
vip_grm.query();
while (vip_grm.next()) {
    var vip_rec = new GlideRecord('sys_user');
    vip_rec.addQuery('sys_id', vip_grm.user);
    vip_rec.query();
    while (vip_rec.next()) {
        vip_rec.vip = true;
        vip_rec.update();
    }
} 

Tuesday, May 2, 2017

Code to make document upload mandatory on a record producer

Execute this as a catalog client script on the record producer, onSubmit method

function onSubmit() {
        var cat_id = gel('sysparm_item_guid').value;
        var gr = new GlideRecord("sys_attachment");
        gr.addQuery("table_name", "u_ar_package");
        gr.addQuery("table_sys_id", cat_id);
        gr.query();
        if (!gr.next()) {
                alert("You must upload a package prior to submitting.");
                return false;
        }else if(gr.next()){
                return true;
        }
}