- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 07:44 AM
Hi,
When an user sets the state to closed rejected on first catalog task, an alert will be triggered asking them to click on save button instead of close task button(it sets the state to closed complete). Still some users are clicking on close task button after setting the state to closed rejected and the state is getting closed complete instead of closed rejected.
So, we have decided to hide 'close task' UI action on first catalog task. I have created a UI policy with the below condition and selected isolate script to false.
function onCondition() {
$$('#close_sc_task')[0].hide();
}It's working as per the requirement, but previewing the reference records from SC task form (like request item, requested for, item) is not working.
I have tried inserting the condition within UI action condition field, but it works only during onLoad. I need this functionality to work during onChange. Please assist.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 10:10 AM
Hi @sath ,
I am not sure what logic you are applying to check whether that's a first task or not. I applied my own logic to determine it, if it is the first one to be closed and all the remaining SC Tasks of that Requested Item are in the open state then I am considering it as an open Task.
In order to achieve this I am using a Display Business Rule and declared a scratchpad variable. Please find the code below.
Display BR Code:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 12:13 PM
I have the similar code and looking to avoid DOM manipulation as its not allowing to preview reference records on SC task once its set to closed rejected (used DOM in UI policy)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 12:35 PM - edited ‎05-16-2023 12:38 PM
You can avoid to use DOM manipulation (if the scTask is already on state 'closed rejected') you can add that to script include.
something like this if((gr.sys_id == scTask && gr.state != closed rejected)
so the DOM manipulation will not run if the state is already closed rejected
and with that the ui action close task will not show up because the task is already closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2023 06:45 AM
State will not be set to closed rejected on load. User will change it to closed rejected and then close task UI action should be hidden.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2023 01:05 PM - edited ‎05-16-2023 01:15 PM
You can try this :
Script include :
var checkiffirst = Class.create();
checkiffirst.prototype = Object.extendsObject(AbstractAjaxProcessor, {
process: function() {
var scReqItem = this.getParameter("sysparm_scReqItem");
var scTask = this.getParameter("sysparm_scTask");
var gr = new GlideRecord("sc_task");
gr.addQuery("requested_item", scReqItem);
gr.orderByDesc('sys_created_on');
gr.query();
if (gr.next()) {
if (gr.sys_id == scTask)
return JSON.stringify( {
'isTheFirst': 'true',
'state': gr.getValue('state')
});
else
return JSON.stringify({
'isTheFirst': 'false',
'state': gr.getValue('state')
});
}
},
type: 'checkiffirst'
});
UI POLICY :
condition : state is closed rejected
Execute if true
function onCondition() {
var ga = new GlideAjax('checkiffirst');
ga.addParam('sysparm_scReqItem', g_form.getValue('request_item'));
ga.addParam('sysparm_scTask', g_form.getUniqueValue());
ga.getXML(resp);
function resp(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
if(answer.isTheFirst == 'true' && answer.state != 'closed rejected')
$$('#close_sc_task')[0].hide();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2023 06:46 AM
I have used $$('#close_sc_task')[0].hide(); in UI policy and its working.
But not able to preview reference records after state is set to closed rejected.
If I disable the UI policy, then I can preview reference records after state is set to closed rejected.
