Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

ui page processing script is not working

Roshani
Tera Expert

Hi All,

I have a ui page , its processing script is not working can somebody help me where i am doing wrong on code

 

HTML :

 

 

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

<body onload="hide()">
<g:ui_form>
<input type="hidden" id="type" value="" name="type"/>
<table style="width:600px">
<input type="hidden" id="document_id" name="document_id" value="${sysparm_document_id}" />
<input type="hidden" id="table_id" name="table_id" value="${sysparm_table}" />
<input type="hidden" id="table_name" name="table_name" value="dms_document" />
<input type="hidden" id="generated_by" name="generated_by" value="user" />
<input type="hidden" id="add_clicked" name="add_clicked" value="ok" />
<input type="hidden" id="user1" name="user1" />
<input type="hidden" id="generated_byy" name="generated_byy" value="group" />
<input type="hidden" id="group" name="group" />
<tr>
<td>
<label for="name">Please select the required approval</label>
</td>
<td>
<select id="quick_message_dropdown" onChange="showHide(this)">
<option value="">None</option>
<option value="user">User</option>
<option value="group">Group</option>
</select>
</td>
</tr><br/>
<tr id="userReference">
<td>
<label for="name">${gs.getMessage('User')}</label>
</td>
<td nowrap="true" align="left">
<g:ui_reference name="user_query" id="user_query" table="sys_user" query="active=true" />
</td>
</tr>

<tr id="groupReference">
<td>
<label for="name">${gs.getMessage('Group')}</label>
</td>
<td nowrap="true" align="left">
<g:ui_reference name="group_query" id="group_query" table="sys_user_group" query="active=true"/>
</td>
</tr>

<tr>
<td>
<label for="revision">${gs.getMessage('Comments')}</label>
</td>
<td>
<input id="sequence" name="sequence" />
</td>
</tr>

<tr>
<td colspan="2" height="20px"></td>
</tr>
<tr>
<td colspan="2">
<g:dialog_button onclick=" return validateApprover();"
name="" id="add">${gs.getMessage('Add')}</g:dialog_button>
</td>
</tr>
</table>
</g:ui_form>
</body>

</j:jelly>

 

CLIENT SCRIPT :

addLoadEvent(hide);

function hide() {
gel('userReference').style.display = 'none';
gel('groupReference').style.display = 'none';
}

function showHide(object) {

if (object.value == 'user') {
gel('userReference').style.display = '';
gel('groupReference').style.display = 'none';
gel("type").value = 'user';
} else if (object.value == 'group') {
gel('groupReference').style.display = '';
gel('userReference').style.display = 'none';
gel("type").value = 'group';
} else {
gel('userReference').style.display = 'none';
gel('groupReference').style.display = 'none';
gel("type").value = '';
}


$("user1").setValue($($('user_query').getValue()).getValue());
$("group").setValue($($('group_query').getValue()).getValue());

return true;

}


function validateApprover() {
gel("add_clicked").value = 'ok';
var userfield = gel('user_query').value;
var groupfield = gel('group_query').value;
var apprtype = gel('type').value;
var addButton = gel('add');
//alert(instanceName);
//document.getElementById('add').style.display='none';

//var invalidFields = new Array();
if (apprtype == 'user' && userfield == "" && $("sequence").getValue() == "") {

alert("${gs.getMessage('Enter a user')}");
alert("${gs.getMessage('Enter a comments')}");
//addButton.disabled = true;
return false;
}

if (apprtype == 'group' && groupfield == "" && $("sequence").getValue() == "") {

alert("${gs.getMessage('Enter a group')}");
alert("${gs.getMessage('Enter a comments')}");

return false;
}


if (apprtype == '') {
alert("${gs.getMessage('Select User or Group Approval')}");
return false;
}
if ($("sequence").getValue() == "") {
alert("${gs.getMessage('Enter a comments')}");
return false;
}
g_form.save();

 

document.getElementById('add').disabled = 'true';
return true;

 

}

 

PROCESSING SCRIPT:

 

(function(_this) {
var urlOnStack = gs.getSession().getUrlOnStack();

gs.addInfoMessage('loop');
if (add_clicked == 'ok') {

if(type == 'user'){
var gr = new GlideRecord('sysapproval_approver');
gr.initialize();
gr.source_table = table_id;
gr.document_id = document_id;
gr.state= 'requested';
gr.sysapproval = document_id;
gr.approver = request.getParameter("user_query"); //you had user, rather it should be id value
gr.comments = sequence;
gr.insert();
gs.addInfoMessage("User added in approver list " );

var gra = new GlideRecord('sn_hr_core_case_payroll');
gra.get(document_id);
gra.state = 11;
gra.approval = 'requested';
gra.update();
}

if(type == 'group'){
var group1 = new GlideRecord('sysapproval_group');
group1.initialize();
group1.assignment_group = request.getParameter("group_query"); //you had group, rather it should id value
group1.approval = 'requested';
group1.parent = document_id;
group1.comments = sequence;
group1.insert();
gs.addInfoMessage("Group added in approver list " );
var grpcase = new GlideRecord('sn_hr_core_case_payroll');
grpcase.get(document_id);
grpcase.state = 11;
grpcase.approval = 'requested';
grpcase.update();
action.setRedirectURL(current);
}
response.sendRedirect(urlOnStack);
}
response.sendRedirect( "/" + table_id + ".do?sys_id=" + document_id);
})(this);

 

6 REPLIES 6

Kieran Anson
Kilo Patron

Hi,

When posting on the community, please ensure to format your code into snippets to aid in readability. 

find_real_file.png

Hi Kieran,

Could you please take  a look now

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you are saving the form using g_form.save()

why to save it?

Can you try removing that?

Also please share from where this UI Page is getting called and the script?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur ,

I am calling ui page from ui action :