- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2016 03:18 AM
We have a ui Action "Close Task" , which we need to make visible to the assignee or his delegate.
For this we are trying to call a script include which checks if the current logged in user is the assignee's delegate.
But the problem is that we are not able to call the script include from the "conditions" section of the ui action.
------------------------------------------------
Ui Action Condition:
javascript:delegateclosetasks()
------------------------------------------
Script Include Name - delegateclosetasks
Active - true
Client Callable - true
var delegateclosetasks = Class.create();
delegateclosetasks.prototype = {
initialize: function() {
gs.log("Entered Script Include","Apoorv");
//Check visibility conditions
if(current.state !=3 && current.state !=4 && current.approval != 'requested' && (gs.getUser().isMemberOf(current.assignment_group.name)|| gs.getUser().isMemberOf('Change Analyst')) && current.change_request.state != 35)
{
gs.log("Entered if","Apoorv");
return true;
}
},
type: 'delegateclosetasks'
}
Somehow, I am not able to trigger the SI itself, before I can add the logic for checking delegate.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2016 06:55 AM
Conditions: new delegateclosetasks().allowdelegate();
1. You don't need the 'javascript' declaration in a condition field. It's already evaluated as JavaScript.
2. You forgot the () on your constructor call.
3. I don't think you need to check the 'client callable' box on your script include. It doesn't extend GlideAjax, and the condition field is evaluated on the server side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2016 03:27 AM
Try -
javascript:new delegateclosetasks();
Usually in the prototype initialization, its not advisable to put a customized code, the initialize function is used to initialize variables which are going to be used in the entire script include.
Please define a new function in the script include and the call can be made
javascript: new DelegateUtil.delegateCloseTask();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2016 05:18 AM
Hi ghsrikanth,
I made the following changes, but the UI action is still not behaving as expected, whats more strage is that the UI Action is now visible for all users on all tasks:
Ui Action:
Name: Close as Delegate
Action name: close_change_task_delegate
Onclick: closetask();
Conditions: javascript:new delegateclosetasks.allowdelegate();
--------------------------------------------------------------------------------------
function closetask()
{
if (g_form.getValue('assigned_to')== "" && g_form.getValue('state')==1)
{
g_form.setMandatory('assigned_to', true);
g_form.showFieldMsg('assigned_to','Assigned to is mandatory when closing the task.','error');
return false;
}gsftSubmit(null, g_form.getFormElement(), 'close_change_task_delegate');
}
if(typeof window == 'undefined')
{
serverClosetask();
}
function serverClosetask()
{
current.state = 3;
current.update();
}
--------------------------------------------------------------
In the script include, active=true, client callable = true
var delegateclosetasks = Class.create();
delegateclosetasks.prototype = {
initialize: function() {
},
allowdelegate : function (){
gs.log("Entered SI allow function","Apoorv");
var grDelegate = new GlideRecord("sys_user_delegate");
grDelegate.addQuery("delegate", gs.getUserID());
grDelegate.addQuery("assignments", "true");
grDelegate.addQuery("starts", "<=", gs.daysAgo(0));
grDelegate.addQuery("ends", ">=", gs.daysAgo(0));
grDelegate.query();
if(grDelegate.getRowCount()>0 ||current.state !=3 && current.state !=4 && current.approval != 'requested' && (gs.getUser().isMemberOf(current.assignment_group.name)|| gs.getUser().isMemberOf('Change Analyst')) && current.change_request.state != 35)
{
gs.log("Entered if","Apoorv");
return true;
}
},
type: 'delegateclosetasks'
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2016 06:55 AM
Conditions: new delegateclosetasks().allowdelegate();
1. You don't need the 'javascript' declaration in a condition field. It's already evaluated as JavaScript.
2. You forgot the () on your constructor call.
3. I don't think you need to check the 'client callable' box on your script include. It doesn't extend GlideAjax, and the condition field is evaluated on the server side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2016 04:42 AM
Hi andrew.lawlor,
This worked, my script include is being called now, will just need to refine the logic to control the visibility. Thanks a ton!