how to delete a attachment present in task after close completing the task?

Ramya66
Tera Contributor

Hi,

I have a requirement when we attach any files in task after close completing the task the file should get deleted. If we use workflow the workflow contains so many items so the changes will be for all items but i need it particularly for 2 items alone. Is there any other way for this requirement?

1 ACCEPTED SOLUTION

Hi,

then you can use flow designer for this with no script required

Flow triggers when catalog task is closed

Searches for sys_attachment and deletes the record

Remember to save and activate the flow

find_real_file.png

find_real_file.png

find_real_file.png

Regards
Ankur

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

View solution in original post

13 REPLIES 13

SumanthDosapati
Mega Sage
Mega Sage

Hi Ramya,

Write an After business rule on your task table as below

Condition : State CHANGES TO closed complete

                 Request Item.Item IS <Item Name>

Script :

var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.getUniqueValue());
gr.query();
gr.deleteMultiple();

 

find_real_file.png

 

Mark as correct and helpful if it solved your query.

Regards,

Sumanth

Hi Sumanth,

I'll try this, thanks!

Feel free to ask if you have further questions or else you can mark an answer as correct and helpful to close the thread.

In general, You can also use below script in workflows or other scripts

var att = new GlideSysAttachment();

att.deleteAll('gliderRecordObject');

 

Regards,

Sumanth

Hi Sumanth,

Its working, can we keep this business rule for particular variables. To be more clear for my items there are few variables when you select that we get another variable from that variable we get this " we need this requirement for this variable alone. I don't need this when we select any other variable other than the mentioned, it has to run only with the specified variable. can we do it?