Client script (onLoad):
function onLoad() {
//check qual
var s_id = g_form.getUniqueValue().toString();
var rec1 = new GlideRecord('sc_task');
rec1.addQuery('request', s_id);
rec1.query();
var myarr=[];
var inwork = false;
while (rec1.next()) {
//console.log(rec1.request);
if(rec1.u_iss_active == 'false'){
myarr.push(rec1.description);
}
//check if one catlog task record still in work
if(rec1.u_iss_inwork=='true'){
inwork = true;
}
}
var rec2 = new GlideRecord('incident');
rec2.addQuery('parent', s_id);
rec2.query();
while (rec2.next()) {
if(rec2.u_iss_active == 'false'){
myarr.push(rec2.description);
}
//check if one catlog task record still in work
if(rec2.u_iss_inwork=='true'){
inwork = true;
}
}
if(myarr.length >= 1){
if(g_form.getValue('category') != '' && g_form.getValue('subcategory') != '' && g_form.getValue('u_symptom') != '' && g_form.getValue('u_reason') != '' && g_form.getValue('state') != 6 && !inwork){
//Initialize the GlideDialogWindow
var gdw = new GlideDialogWindow('iss_chose_task');
gdw.setTitle('Chose Task');
gdw.setSize(300,300);
gdw.setPreference("context_id", s_id);
gdw.render();
}
}
}
UI Page:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<g:evaluate var="jvar_context" expression="RP.getWindowProperties().get('context_id')" />
<g:evaluate var="jvar_sc_tasks" jelly="true">
var rec1 = new GlideRecord("sc_task");
rec1.addQuery("request", "${jvar_context}");
rec1.query();
var myStr="";
while (rec1.next()) {
if(!rec1.u_iss_active){
myStr += '<tr><td><input type="radio" class="iss_radio1" name="iss_radio1" value="'+rec1.sys_id+'">' + rec1.description.getDisplayValue() + '</input></td></tr>';
}
}
var rec2 = new GlideRecord("incident");
rec2.addQuery("parent", "${jvar_context}");
rec2.query();
while (rec2.next()) {
if(!rec2.u_iss_active){
myStr += '<tr><td><input type="radio" class="iss_radio1" name="iss_radio1" value="'+rec2.sys_id+'">' + rec2.description.getDisplayValue() + '</input></td></tr>';
}
}
myStr;
</g:evaluate>
<table width="100%" cellpadding="0" cellspacing="0">
<g:no_escape>
${jvar_sc_tasks}
</g:no_escape>
<tr><td align="left" nowrap="true"><br />
<input type="hidden" name="context_id" value="${jvar_context}" />
<g:dialog_buttons_ok_cancel ok="return onOk();" cancel="return onCancel();"/>
</td></tr>
</table>
</g:ui_form>
</j:jelly>
function onOk(){
var iss_radio = document.getElementsByClassName('iss_radio1');
var task = false;
var inc = false;
for(var i=0;i<iss_radio.length;i++){
if(iss_radio[i].checked){
//alert(iss_radio[i].value);
var sysid = iss_radio[i].value;
var rec1 = new GlideRecord("sc_task");
rec1.addQuery("sys_id", sysid);
rec1.query();
while (rec1.next()) {
//rec1.active = 'true';
task = true;
//rec1.u_iss_symptom = g_form.getOption('u_symptom', g_form.getValue('u_symptom')).text;
rec1.u_iss_symptom = g_form.getValue('u_symptom');
//rec1.u_iss_active = 'true';
rec1.u_iss_inwork = 'true';
rec1.update();
}
var rec2 = new GlideRecord("incident");
rec2.addQuery("sys_id", sysid);
rec2.query();
while (rec2.next()) {
inc = true;
rec2.u_iss_inwork = 'true';
rec2.update();
}
//var URL = "/sc_task.do";
if(task){
window.location.href = "sc_task.do?sys_id=" + sysid;
}else{
window.location.href = "incident.do?sys_id=" + sysid;
}
//setRedirectURL(rec1);
//response.sendRedirect("sc_task.do?sys_id=" + sysid);
//reloadWindow(window); //Refresh the form
}
}
GlideDialogWindow.get().destroy(); //Close the dialog window
return false;
}
function onCancel(){
GlideDialogWindow.get().destroy(); //Close the dialog window
//reloadWindow(window); //Refresh the form
return false;
}