- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 01:24 AM
hi
ihave a requirement that, we need to hide the close task button and close complete option in state field on change task when rfc record is created on change request and change task short description contains System Test & Validation.
below are the code i wrote but here close task button some times is not hiding please give me your suggestion or can we take sysyid of the close task
Solved! Go to Solution.
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 05:35 AM
Hi
Please find the steps you need to follow to achieve your requirement:
1) Create a Script Include and use the script as below:
var uiActionVisibility = Class.create();
uiActionVisibility.prototype = {
initialize: function() {
},
buttonDisplay : function(changeID){
var gr = new GlideRecord('u_charm_rfcs');
gr.addQuery('FieldName',changeID); // Replace 'FieldName' witht he field which is present on your Charm Rfcs table which will be a Reference field and connecting to Change record
gr.query();
if(gr.next()){
return false;
}else{
return true;
}
},
type: 'uiActionVisibility'
};
Now Close task button present on Change Task you need to add the below line to your existing Script with an AND condition and pass the Change Request ID as shown below:
current.state < 3 && current.approval != 'requested' && !current.change_request.on_hold && new uiActionVisibility().buttonDisplay(current.change_request)
Let me know how you go with this:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 01:28 AM
Hi,
I will suggest to avoid DOM manipulation for showing/hiding the UI action
UI Actions are meant to be shown/hidden based on condition and only once when form loads
Please use appropriate condition to hide
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
02-24-2022 01:31 AM
hi Ankur
could you please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 01:43 AM
Hi,
please share existing UI action condition and script include script here and the client script
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
02-24-2022 01:46 AM
Ui action condition : current.state < 3&& current.approval != 'requested' && current.state != -5
script include :
var checkcharmrfc = Class.create();
checkcharmrfc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
charmexists: function()
{
var answer = '';
var cursysid = this.getParameter('sysparm_currentsysid');
var rfc = new GlideRecord('u_charm_rfcs');
rfc.addQuery('u_cr_number', cursysid);
//rfc.addQuery('u_create_rfc','=','true');
//rfc.addJoinQuery('u_charm_rfcs', 'u_cr_number', 'number');
rfc.query();
if(rfc.next() && (!gs.hasRole("admin")))
{
answer = 'Yes';
}
else
{
answer = 'No';
}
return answer;
},
type: 'checkcharmrfc'
});
clientscript :
function onLoad() {
//Type appropriate comment here, and begin script below
// g_form.getValue('short_description').indexOf('System Test & Validation') > -1;
var ga = new GlideAjax('checkcharmrfc');
var st = g_form.getValue('state');
ga.addParam('sysparm_name','charmexists');
ga.addParam('sysparm_currentsysid', g_form.getValue('change_request'));
ga.getXMLWait();
var answer = ga.getAnswer();
if((answer == 'Yes') && (st != '3') && (g_form.getValue('short_description').indexOf('System Test & Validation')>-1))
{
g_form.removeOption('state', 3);
//return false;
var items = $$('BUTTON').each(function(item){
if(item.innerHTML.indexOf('Close Task') > -1){
item.hide();
}
});
}
}