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.

Latest attachment not visible on the request after removing ZZ_YY from attachment name

Sampathr382
Tera Contributor

Hi Everyone,

I have a requirement of making attachment mandatory based on the value(Select-box) in one of the catalog item. So, instead of generic attachment(paper clip icon) I have used attachment variable in catalog item. Please refer below image for the variable

Sampathr382_0-1739890146194.png

 


Whenever I upload the attachment and submit the form and the attachment would be named with prefix "ZZ_YY".
So, to avoid this I have used After insert BR and wrote a script like this

Script:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

    var gr = new GlideRecord("sys_attachment");

    gr.addQuery("table_name""ZZ_YY" + current.getTableName());

    gr.addQuery("table_sys_id", current.sys_id);

    gr.query();

    if (gr.next()) {

        gr.table_name = current.getTableName();

        gr.update();

       

    }

})(current, previous);


There will be no issue if I attach/upload a proper file for the first attempt in the variable but incase If I want to update the file in attachment variable using upload option and submit the form.

Sampathr382_1-1739890146195.png

 

I am able to see the previously attached file not the latest one in request form.

Can anyone please help on this issue?

2 REPLIES 2

Swapna Abburi
Mega Sage
Mega Sage

Hi @Sampathr382 

What is the reason to rename the table name in attachment record in the first place?

Sampathr382
Tera Contributor

Hi @Swapna Abburi 

I need to rename the attachment table name since the attachment table name is prefixed with "ZZ_YYsc_req_item", since the attachment is not visible on the form.

So, I have added the gr.orderByDesc('sys_created_on'); query and it worked. 
Anyway thanks for the response!!