Service Catalog - Removal of Attachment icon on the portal after submitting the catalog item

Tek1
Kilo Contributor

Hello,

I've a requirement to remove the Attachment paper clip for the catalog items after submitting the item i.e, on the submit page of the Portal, for which we've opted 'Hide Attachment' as 'True' in the Portal Settings. I've tried multiple ways by modifying the 'Ticket Attachments' widget on the Service Portal. But nothing worked out.

 find_real_file.png

Please help me with the procedure.

Thanks in advance

1 ACCEPTED SOLUTION

Ok then modify to check the catalog item here, 

1. create a property with the sysid of the catalog items.

2. check if the ritm is from the catalog item.

3. block/allow the attachment

 

this should be added above the data.canAttach line. 

var currentRecord = $sp.getRecord(); // get the current record
var catitemrecord = currentRecord.cat_item; // check the catalog item


// the property should contain the sysid of the catalog item
var restricAttachment = (catitemrecord.indexOf(gs.getProperty('name of prop')) > -1)

// add the line "&& !restricAttachment" this will not allow attachment for the sysid mentioned in the property

data.canAttach = gs.hasRole(gs.getProperty("glide.attachment.role")) && GlideTableDescriptor.get(data.table).getED().getAttribute("no_attachment") != "true" && !restricAttachment;

View solution in original post

10 REPLIES 10

Okay, don't clone the widget. What you do instead is this: 

You create a new widget, and in that widget you in the server script define the attachments widget, so you can do it like this: 

Server script:

data.attachmentWidget = $sp.getWidget("widget-ticket-attachments"); //This is your ootb widget - no reason to clone it!!

data.hideAttachments = checkTicket(); //This is whether or not to show the attachment widget


//You then need a function to check the ticket and what item it belongs to.

//Example

function checkTicket(){

var id = $sp.getParameter("sys_id");
var table = $sp.getParameter("table");

if(table == 'sc_req_item'){
var reqitm = new GlideRecord('sc_req_item');
    reqitm.get(id);

var item = reqitm.getValue('cat_item');

if(item == 'sys_id_of_item1' || item == 'sys_id_of_item2') { //You could properly have something on the item it self to check this value, or have it in a property instead of hardcoding sys_ids. 
return true;
} else {
return false;
]

} else {
return false;
}
}

 

HTML: 

  <div ng-if="!data.hideAttachments">
  	<sp-widget widget="data.attachmentWidget"></sp-widget>
  </div>

Then you simply replace the ootb widget on the ticket page with your newly created widget, without changing functionalities and miss future upgrades. 


Best regards,
Sebastian Laursen

Muralidharan BS
Mega Sage
Mega Sage

can you try this, 

press control + right-click, open the widget editor, if OOB widget, clone it and amend this line and add this widget to the widget instance on that page.

from 

data.canAttach = gs.hasRole(gs.getProperty("glide.attachment.role")) && GlideTableDescriptor.get(data.table).getED().getAttribute("no_attachment") != "true";

to

data.canAttach = gs.hasRole(gs.getProperty("glide.attachment.role")) && GlideTableDescriptor.get(data.table).getED().getAttribute("no_attachment") != "true" && gs.hasRole('admin');

 

this will allow only the admin to attach it. Also this stop attachments from the pages where the widget is used. 

 

 

Hello Murali,

The requirement is not only for Enduser and also, it shouldn't be visible particularly for 2 catalog items for the rest of them all the functionality should be as is.

Ok then modify to check the catalog item here, 

1. create a property with the sysid of the catalog items.

2. check if the ritm is from the catalog item.

3. block/allow the attachment

 

this should be added above the data.canAttach line. 

var currentRecord = $sp.getRecord(); // get the current record
var catitemrecord = currentRecord.cat_item; // check the catalog item


// the property should contain the sysid of the catalog item
var restricAttachment = (catitemrecord.indexOf(gs.getProperty('name of prop')) > -1)

// add the line "&& !restricAttachment" this will not allow attachment for the sysid mentioned in the property

data.canAttach = gs.hasRole(gs.getProperty("glide.attachment.role")) && GlideTableDescriptor.get(data.table).getED().getAttribute("no_attachment") != "true" && !restricAttachment;

Hi Murali,

It worked. Thanks for the code.