2017年9月20日 星期三

[ServiceNow] Delete additional comments or work notes of Incident

First, copy the sys_id of an incident.

Then search the comments in sys_audit and sys_journal_field respectively.

Delete the records carefully.


function confirmDelete(){
   if(confirm('Are you sure you want to permanently delete this history line and all corresponding audit history?\n\nTHIS ACTION CANNOT BE UNDONE!')){
      //Call the UI Action and skip the 'onclick' function
      gsftSubmit(null, g_form.getFormElement(), 'delete_history_line'); //MUST call the 'Action name' set in this UI Action
   }
   else{
      return false;
   }
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
   deleteHistoryLine();

function deleteHistoryLine(){
   var fieldVal = current["new"];
   var fieldName = current.field;
 
   //Query for and delete the 'sys_audit' record
   var aud = new GlideRecord('sys_audit');
   aud.addQuery('documentkey', current.set.id);
   aud.addQuery('fieldname', fieldName);
   aud.addQuery('newvalue', fieldVal);
   aud.query();
   if(aud.next()){
      aud.deleteRecord();
   }
 
   //Query for and delete the 'sys_journal_field' record (if applicable)
   var je = new GlideRecord('sys_journal_field');
   je.addQuery('element_id', current.set.id);
   je.addQuery('element', fieldName);
   je.addQuery('value', fieldVal);
   je.query();
   if(je.next()){
      je.deleteRecord();
   }
 
   //Set redirect and info message for the parent record
   gs.addInfoMessage(current.label + " entry '" + fieldVal + "' deleted.");
   action.setRedirectURL(current.set.getRefRecord());
 
   //Delete the 'sys_history_line' record
   current.deleteRecord();
}

2017年9月19日 星期二

[ServiceNow] UI Page > Check All Links target blank

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g2:evaluate var="jvar_gr_sc_cat_item" jelly="true" object="true">
var gr = new GlideRecordSecure('sc_cat_item');
gr.addEncodedQuery('descriptionLIKEhref=^active=true');
gr.addJoinQuery('sys_user', 'sys_created_by', 'user_name');
gr.orderByDesc('sys_created_on');
gr.query();
gr;
</g2:evaluate>
<j2:set var="jvar_count" value="1"/>
<head>
<script language="javascript">
function checkBlankLink( id, tid) {

var s = document.getElementById(tid).value;
var finda = s.match(/href=/g);
var findb = s.match(/target="_blank"/g);
var a=0;
var b=0;
if(finda) {
a = finda.length;
}
if(findb) {
b = findb.length;
}
if(a==b)
{
//alert(a+', '+b);
document.getElementById(id).innerHTML='OK';
}

}


</script>
</head>
<body >
<h2>Category Item Target Blank</h2>
<table id="headerTable" border="1" width="100%" cellpadding="10pt">
<tr>
<td>#</td>
<td>OK = All Blank</td>
<td>name</td>
<td>short_description</td>
<td>sys_created_by</td>
<td>sys_created_on</td>
<td>sys_id</td>
</tr>
<j2:while test="$[ jvar_gr_sc_cat_item.next() ]">
<tr>
<td>
$[jvar_count]
<j2:set var="jvar_count" value="$[jvar_count+1]"/>
</td>
<td align="center">
<div id="lbl_$[jvar_gr_sc_cat_item.getValue('sys_id')]" style="color:red"></div>
<textarea id="t_$[jvar_gr_sc_cat_item.getValue('sys_id')]" style="display:none">$[jvar_gr_sc_cat_item.getValue('description')]</textarea>
<script language="javascript">
checkBlankLink("lbl_$[jvar_gr_sc_cat_item.getValue('sys_id')]", "t_$[jvar_gr_sc_cat_item.getValue('sys_id')]");

</script>
</td>
<td>
<a href="sc_cat_item.do?sys_id=$[jvar_gr_sc_cat_item.getValue('sys_id')]" target="_blank">$[jvar_gr_sc_cat_item.getValue('name')]</a>
</td>
<td>
$[jvar_gr_sc_cat_item.getValue('short_description')]
</td>
<!--
<td style="padding:10px;white-space: pre;">
$[jvar_gr_sc_cat_item.getValue('description')]
</td>
-->
<td>
$[jvar_gr_sc_cat_item.getValue('sys_created_by')]
</td>
<td>
$[jvar_gr_sc_cat_item.getValue('sys_created_on')]
</td>
<td>
$[jvar_gr_sc_cat_item.getValue('sys_id')]
</td>

</tr>
</j2:while>
</table>
</body>

</j:jelly>

2017年9月11日 星期一

[ServiceNow] Jelly script in UI Page

Just tried building a simple ui page in my developer instance (Istanbul).

I find that:

<g:...> and <j:...> tag do not work;
if the variable name in <g2:evaluate> does not start with "jvar_", the <j2:if > and <j2:while > cannot work properly;
<g2:breakpoint> prints nothing;


Ref: http://wiki.servicenow.com/index.php?title=Jelly_Tags#gsc.tab=0


<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g2:evaluate var="jvar_gr_incident" jelly="true" object="true">
var gr = new GlideRecord('incident');
gr.orderByDesc('number');
gr.query();
gr;
</g2:evaluate>

<g2:evaluate var="jvar_a">
var a = 21;
a;
</g2:evaluate>

<g2:evaluate var="jvar_b">
var b = 21;
b;
</g2:evaluate>

<j2:set var="jvar_a" value="$[22]"/>
<j2:set var="jvar_b" value="$[2111]"/>

<div>

$[jvar_a] aa<br/>
<j2:if test="$[jvar_a!=21]">
   We did not find any active incidents. $[jvar_a]<br/>
</j2:if>
<j2:if test="$[jvar_a==21]">
   We found $[jvar_a] active incidents.<br/>
</j2:if>


abc $[jvar_a] vv</div>

<br/>
b= $[jvar_b]
<br/>

<table id="headerTable" >
<j2:while test="$[ jvar_gr_incident.next() ]">
<tr>
<td>
<a href="incident.do?sys_id=$[jvar_gr_incident.getValue('sys_id')]">$[jvar_gr_incident.getValue('number')] - $[jvar_gr_incident.getValue('short_description')]</a>
</td>
</tr>
</j2:while>
</table>

</j:jelly>