- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 02:15 AM
Hi, i have made a UI action button in SCTASK that ask user for assignment group + assignee and when clicked, SCTask is created.
When ok is clicked, it will create another SCTask with assigned group and assessor if any.
Problem:
However, this is working fine if a user has 'admin' role.
If a user does not have 'admin' role, no SCTask will be created.
This is really pulling my hair out 😞
Below are my config and script. Appreciate if anyone can help me out please.
Thank you so much in advance!
ui action:
function confirmAndProcess() {
var assignment_group = g_form.getReference("assignment_group");
var agroup = g_form.getValue("assignment_group");
var confirm = new GlideDialogWindow('add_assignment_group_page_modify'); //UI Page Name
confirm.setTitle('Select Assignment Group');
//Check Size
confirm.setSize(400,300);
confirm.setPreference("assignment_group", assignment_group);
confirm.setPreference("agroup", agroup);
confirm.render();
}
UI Page:
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">
<script>
addLoadEvent (function(){
onLoadFunction();
});
</script>
Assignment Group: <g:ui_reference name="group" id="group" table="sys_user_group" completer="AJAXTableCompleter" query="active=true" onchange="setUserFilter()" style="width:100px" />
<br />
Assign to Assessor (Optional): <g:ui_reference name="userRecords" id="userRecords" table="sys_user" completer="AJAXTableCompleter" style="width:100px" />
<br />
Additional Notes for Cross Team:
<div class="row">
<div class="form-horizontal">
<div class="form-group" style="margin-left:16px !important;margin-right:16px !important">
<textarea id="comments" name="comments" class="form-control" spellcheck="true" style="overflow: hidden; word-wrap: break-word; resize: none;" ></textarea>
</div>
</div>
</div>
<br />
<g:dialog_buttons_ok_cancel ok="saveGroups()" cancel_type="button" />
</j:jelly>
client script:
function onLoadFunction() {
var a = document.getElementById('sys_display.userRecords');
a.setAttribute('disabled', 'true');
var b = document.getElementById('lookup.userRecords');
b.setAttribute('disabled', 'true');
var c = document.getElementById('comments');
c.setAttribute('disabled', 'true');
}
function setUserFilter() {
var groupSysId = gel('group').value;
var UserLookUp = gel('lookup.userRecords');
var userArray = [];
var gr = new GlideRecord("u_assessor");
gr.addQuery("u_group", groupSysId);
gr.query();
while (gr.next()) {
userArray.push(gr.u_user.toString());
}
UserLookUp.setAttribute('onclick', "mousePositionSave(event); reflistOpen( 'userRecords', 'not', 'sys_user', '', 'false','QUERY:active=true', 'sys_idIN" + userArray + "', '')");
var a = document.getElementById('sys_display.userRecords');
a.removeAttribute("disabled"); // removing the disabled attribute
var b = document.getElementById('lookup.userRecords');
b.removeAttribute("disabled"); // removing the disabled attribute
var c = document.getElementById('comments');
c.removeAttribute("disabled"); // removing the disabled attribute
}
function saveGroups() {
//get the groups that are selected in the UI page.
var groups = $('group').value; //your value
var user = $('userRecords').value; //your value
var comments = $('comments').value; //your value
if (groups == "") {
//If groups are empty stop submission
alert("Please provide assignment group name.");
return false;
}
var newCTask = new GlideRecord('sc_task');
newCTask.state = '1';
newCTask.request = g_form.getValue('request');
newCTask.request_item = g_form.getValue('request_item');
newCTask.assignment_group = groups;
newCTask.assigned_to = user;
newCTask.u_assign_to_assessor = user;
var rf = g_form.getReference('request', myFunc);
function myFunc(rf) {
newCTask.requested_for = rf.requested_for;
}
var currentid = g_form.getValue('number');
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', groups);
gr.query();
if (gr.next()) {
gr = gr.getValue('name');
}
newCTask.parent = g_form.getValue('request_item');
newCTask.short_description = 'Assessor for ' + gr + ' to Assess - Cross Team Requested By: ' + currentid;
newCTask.description = 'Cross Team created by previous Assessor ' + currentid + '. \nAdditional Comments from previous assessor: ' + comments + '\nIf any comments, please contact previous Assessor. You can delete this SCTASK if cross team not required.';
var id = newCTask.insert();
//self.location = "sc_task.do?sys_id=" + id;
alert("New Cross Team SCTask has been created for " + gr + "\nYou can see it later in the RITM. \n\nYou may now continue to assess this task.");
GlideDialogWindow.get().destroy();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 04:15 AM
Just check whether you have applied admin role in the UI action. This section is at below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 02:20 AM
Hi,
so what debugging have you done so far?
UI page is not getting called?
GlideRecord is not working?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 02:58 AM
Hi Ankur, you're always the first to reply. ????
I am doing debuging, and i relise it's only the below part, when:
user has admin role: alert(id); is able to get a new SCTask ID
user does not have admin role: alert(id); is getting "undefined".
Any idea which part in this UI Page, Client script require admin to run?
Or am i missing something somewhere?
function saveGroups() {
//get the groups that are selected in the UI page.
var groups = $('group').value; //your value
var user = $('userRecords').value; //your value
var comments = $('comments').value; //your value
var newCTask = new GlideRecord('sc_task');
newCTask.state = '1';
newCTask.request = g_form.getValue('request');
newCTask.request_item = g_form.getValue('request_item');
newCTask.assignment_group = groups;
newCTask.assigned_to = user;
newCTask.u_assign_to_assessor = user;
var id = newCTask.insert();
alert(id);
alert("New Cross Team SCTask has been created for " + gr + "\nYou can see it later in the RITM. \n\nYou may now continue to assess this task.");
GlideDialogWindow.get().destroy();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 04:08 AM
Hi,
strange
Since it's GlideRecord ACLs won't be evaluated and hence no issue during insertion
Did you check any before insert BR on that table is stopping the inserting for non-admins?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 04:30 AM
Did you check all worked fine till newCTask.insert()? i.e. you got the values of the groups, comments etc?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader