How to disable/hide the remove button in attachments in Agent Workspace

Lavanya R1
Tera Contributor

Hi everyone,

I have a requirement when the change is not in new state, the removal of the attachment should be restricted in Agent Workspace. But, the user should be able to add attachment in all the stages.

It would be helpful if anyone could answer.

Thanks in Advance

 

1 ACCEPTED SOLUTION

Subrahmanyam2
Giga Guru

Hi Lavanya,


Attachments are finally stored in sys_attachment (meta data), sys_attachment_doc (the actual data) tables.
You have to write before delete business rules on each of these to abort the deletion action, then the deletion will be stopped.
But with only this solution the problem is, users may see that attachment is removed when performing the removal action, but when they reload the form like (incident) it will show the attachment again.
Even if we keep the gs.addErrorMessage in business rules they will not show the error messages as these actions are done differently.

Please check the snapshots of Business rules below:
find_real_file.png

find_real_file.png

find_real_file.png

find_real_file.png

 

You may use still want to keep the UI page customizations as they will work in normal UI (If you remove UI page customizations in normal UI, then the error message while trying to remove attachments will not appear), but the maintenance overhead during upgrades will be there.

 

Thanks and regards,

Subrahmanyam Satti

View solution in original post

15 REPLIES 15

Thank you so much for your reply!

Regards,

Lavanya 

Hi,

I'm glad to see you found a correct answer, but I'm unsure how this solution solves your question for the Agent Workspace. The solution above would apply to the entire platform, no matter the view.

Again, it's great if it works for you, but your question may confuse and mislead others in the future due to you specifically asking for the Agent Workspace.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

I missed to mention that it works in agent workspace when I was posting the reply.


Since we are adding the restrictions in the before deletion business rule on the underlying attachment metadata and actual attachment data tables, this approach will work in both agent workspace and native UI.
In agent workspace this approach works perfectly. It even shows the error message when deletion failed.
In native UI, additional modifications to UI page are required if we need error messages to display. Looks like Lavanya already figured that out.

So the solution given exactly fits her need.

Thank you for the feedback!


Regards,

Subrahmanyam Satti

Hi,

What I'm saying is that their question was specifically about the Agent Workspace. Not involving the standard UI.

What you've proposed would affect both Agent Workspace and the standard UI and prevent deletion of attachments for both.

If that is what the author wants, then that's fine, but I'm unsure if they fully know that and may have only tested with the Agent Workspace.

I'm just calling it out because in the future, if a reader comes along and has the same request: I want to prevent deletion of attachments from Agent Workspace and they go to implement your solution, it will affect the standard UI as well.

Let's have the author confirm?

 

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Subrahmanyam2
Giga Guru

Hi Everyone,

There were some discussions on how can we achieve this if the requirement is only for agent workspace but not for any other UIs (Such as native platform UI or portal UI)

Sorry for the confusion here. I assumed that implementers want to provide uniform functionality or experience across all UIs. But if it not the case and if some one is really looking to restrict attachments only in agent workspace UI, please follow the same steps as mentioned in the answer marked correct but make below mentioned script modifications in the business rules.

The before delete sys_attachment business rule script (mentioned in 2nd screenshot of the answer marked as correct) should be modified as mentioned below:

(function executeRule(current, previous /*null when async*/ ) {
    var referer = GlideTransaction.get().getRequest().getHeader("referer");
    var workSpaceURL = gs.getProperty("glide.servlet.uri") + "now/workspace/agent";
    if (referer.indexOf(workSpaceURL) != 0) {
        return;
    }
    var grInc = new GlideRecord(current.getValue("table_name"));
    grInc.addQuery("sys_id", current.getValue("table_sys_id"));
    grInc.query();
    if (grInc.next()) {
        if (grInc.getValue("state") != 1 /*Incidents State is not New*/ ) {
            gs.addErrorMessage("Attachments cannot be deleted from incident not in new state!");
            current.setAbortAction(true);
        }
    }
})(current, previous);

 

The before delete sys_attachment_doc business rule script (mentioned in 4th screenshot of the answer marked as correct) should be modified as mentioned below.

(function executeRule(current, previous /*null when async*/ ) {
    var referer = GlideTransaction.get().getRequest().getHeader("referer");
    var workSpaceURL = gs.getProperty("glide.servlet.uri") + "now/workspace/agent";
    if (referer.indexOf(workSpaceURL) != 0) {
        return;
    }
    var grInc = new GlideRecord(current.sys_attachment.table_name.getValue());
    grInc.addQuery("sys_id", current.sys_attachment.table_sys_id.getValue());
    grInc.query();
    if (grInc.next()) {
        if (grInc.getValue("state") != 1 /*Incidents State is not New*/ ) {
            gs.addErrorMessage("Attachment deletion not allowed for incidents not in New state!");
            current.setAbortAction(true);
        }
    }
})(current, previous);

 

Hope this helps!

 

Thanks and regards,

Subrahmanyam Satti