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.

hide attachment tab in standard ticket tab

Priyansh_98
Tera Guru

hello folks,

i have a requirement where I want to hide an attachment tab from the standard ticket tab , for a specific catalog item from the requester. but I am not able to do that can someone guide me how can i do this?

thanks in advance...

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Priyansh_98 

you need to clone the existing widget "Standard Ticket Tab" then make necessary changes

what did you start with?

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

hi @Ankur Bawiskar 

widget is already cloned, but i the stuck in a place where I have to hide the attachment tab because in html tag I am not able to identify which line of code is for the attachment tab see the image

prs1_0-1686656326017.png

here I want to hide the attachment tab and attachment icon also. so that the user won't be able to delete and update the attachment because in the attachment tab, there is a option to delete and add the attachment.

@Priyansh_98 

I was able to hide the html under that tab but the tab was still visible.

you can enhance the script further

here is the updated server side script and I have highlighted the changes in bold

(function() {
var tableName = $sp.getParameter('table');
var sysId = $sp.getParameter('sys_id');
var record = sn_std_tkt_api.TicketConfig.getTicketRecord(tableName, sysId);

var toShow = 'true';
if(tableName == 'sc_req_item'){
var rec = new GlideRecord('sc_req_item');
rec.addQuery('sys_id', sysId);
rec.addQuery('cat_item.name', 'Testing Item');
rec.query();
toShow = 'false';
}

data.canRead = (record != null && record.isValid() && record.canRead());
if (!data.canRead)
return;

if ($sp.getParameter('headless') == 'true')
data.headless = true;
else if ($sp.getParameter('headless') == 'false')
data.headless = false;
else if ($sp.getParameter('headless') == null)
data.headless = false;
else
return;

data.maxAttachmentSize = parseInt(gs.getProperty("com.glide.attachment.max_size", 1024));
if (isNaN(data.maxAttachmentSize))
data.maxAttachmentSize = 24;
data.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} MB - please try again", data.maxAttachmentSize);

var urClosedState;
if (tableName == 'universal_request') {
urClosedState = (record.state == '7');
if (record.primary_task) {
var primary_table = record.primary_task.getRefRecord().getTableName();
record = sn_std_tkt_api.TicketConfig.getTicketRecord(primary_table, record.primary_task);
data.canRead = record != null && record.isValid() && record.canRead();
if (!data.canRead)
return;
}
}
else if (record.isValidField('universal_request') && !record.universal_request.nil())
urClosedState = (record.universal_request.state == '7');

data.table = record.getTableName();
data.sys_id = record.getUniqueValue();

var tabs = [];
var config = sn_std_tkt_api.TicketConfig.getConfig(data.table, record.sys_domain);
var isNonPrimary = ((record.isValidField('universal_request') && !record.universal_request.nil()) && (record.universal_request.primary_task != record.sys_id));
if (!config.tabs) {
var tab_1 = {
name: gs.getMessage('Activity'),
order: 0,
widget: $sp.getWidget('std_ticket_conversations',
{sys_id: data.sys_id,
table:data.table,
btnLabel: gs.getMessage('Post'),
read_only: isNonPrimary || urClosedState,
rich_text_editor: options.rich_text_editor,
at_mentions: options.at_mentions
})
};
tabs.push(tab_1);
var tab_2 = {
name: gs.getMessage('Attachments'),
order: 1,
widget: $sp.getWidget('std_ticket_attachments', {record_id: data.sys_id,
record_table: data.table,
read_only: isNonPrimary || urClosedState
})
};
if(tableName == 'sc_req_item' && toShow == 'true'){
tabs.push(tab_2);
}
else if(tableName != 'sc_req_item'){
tabs.push(tab_2);
}

}
else {
config.tabs.forEach(function (tabConfig) {
var tab = {};
tab.name = tabConfig.name;
tab.type = tabConfig.type;
var condition = tabConfig.visible_condition;
var isAdvCondition = tabConfig.advanced;
var scriptCondition = tabConfig.visible_script;

if (isAdvCondition) {
if (scriptCondition) {
var evaluator = new GlideScopedEvaluator();
var tagGR = sn_std_tkt_api.TicketConfig.getTicketRecord('ticket_tab_configuration', tabConfig.sys_id);
evaluator.putVariable('current', record);
evaluator.putVariable('answer', null);
var response = evaluator.evaluateScript(tagGR, 'script');
if (typeof response !== 'undefined' && !(response == 'true' ||
response == true ||
response.answer ||
response.answer == 'true' ||
response.answer == true)) //either the script could return true, or set answer to true
return;

}
}
else {
if (condition) {
if (!GlideFilter.checkRecord(record, condition))
return;
}
}
if (tabConfig.type == 'activity') {
tab.widget = $sp.getWidget('std_ticket_conversations',
{sys_id: data.sys_id,
table: data.table,
btnLabel: gs.getMessage('Post'),
read_only: isNonPrimary || urClosedState,
rich_text_editor: options.rich_text_editor,
at_mentions: options.at_mentions
});
}
else if (tabConfig.type == 'attachments') {
if(tableName == 'sc_req_item' && toShow == 'true'){
tab.widget = $sp.getWidget('std_ticket_attachments', {record_id: data.sys_id,
record_table: data.table,
read_only: isNonPrimary || urClosedState
});
}
else if(tableName != 'sc_req_item'){
tabs.push(tab_2);
tab.widget = $sp.getWidget('std_ticket_attachments', {record_id: data.sys_id,
record_table: data.table,
read_only: isNonPrimary || urClosedState
});
}


}
else if (tabConfig.type == 'associated_requests') {
tab.widget = $sp.getWidget('my-requests-v2', {record_id: data.sys_id,
record_table: data.table,
is_associated_ticket_tab: true
});
}
else if (tabConfig.type == 'variable_editor' || tabConfig.type == 'variable_summary') {
if (record.variables.getElements(true).length == 0)
return;

var widgetParam = tabConfig.widget_param;
if (widgetParam)
widgetParam = JSON.parse(widgetParam)
else
widgetParam = {};
widgetParam.table = data.table;
widgetParam.sys_id = data.sys_id;
tab.widget = $sp.getWidget(tabConfig.widget, widgetParam);
}

else if (tabConfig.type == 'custom') {
var widgetParam = tabConfig.widget_param;
if (widgetParam)
widgetParam = JSON.parse(widgetParam)
else
widgetParam = {};
widgetParam.table = data.table;
widgetParam.sys_id = data.sys_id;
widgetParam.read_only = isNonPrimary || urClosedState;
tab.widget = $sp.getWidget(tabConfig.widget, widgetParam);
}
else if (tabConfig.type == 'iar_recommendations') {
tab.widget = $sp.getWidget('iar_recommendation', {record_id: data.sys_id, record_table: data.table });
}
tab.order = tabConfig.order;
tabs.push(tab);
});
}
data.tabs = tabs;
})();

Output:

AnkurBawiskar_0-1686657289131.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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