The CreatorCon Call for Content is officially open! Get started here.

Need to show the Ritm Attachments in Sc task

Shweta Kasbe1
Tera Contributor

Need to show the Ritm Attachments in Sc task but Its showing two Attachments. When i am raising a request and adding attachments and when i open user attachments its showing me two attachments.

I have created a relationship for attachments which i have attachment to sc task.

find_real_file.png

Below is my script for attachments.

find_real_file.png

 

5 REPLIES 5

Bhaba
Tera Expert

Hi @Shweta Kasbe 

Use the following code:

(function refineQuery(current, parent) {
 current.addQuery('table_sys_id' , parent.request_item);
})(current, parent);

This should work absolutely fine for you. If not, try the below method.

Create a After insert BR on sys_attachment table:

addAttachments(current);

function addAttachments(attachment) {
	var grTask= new GlideRecord("sc_task");
	grTask.addActiveQuery();
	grTask.addQuery('request_item', current.table_sys_id);
	grTask.query();
	while(grTask.next()) {
		var attach= new GlideSysAttachment();
		attach.copy(current.table_name, current.table_sys_id, grTask.getTableName(), grTask.sys_id);
	}
}

Hope this helps you.

Thanks.

Fabian Kunzke
Kilo Sage
Kilo Sage

Hey,

I am going to put this up front:

tl:dr: That said, your related list shows 2 different attachment records. So it could also be - and is very likely as i can see no fault in your coding - that your solution does what it is designed for.

In the sys_attachment table there are always two records created for an attachment:

find_real_file.png

Now, i don't know 100% why this happens, but my guess is, that you have copied these attachments before (the thumb_ followed by a sys_id of sorts usually is the one generated by the system). Just to make sure, that your query works, i would tweak it a bit and also filter for the correct tables (sc_req_item and sc_request). For testing purposes, don't copy the attachment - if you did - but rather upload a new one. In your related list the ones named "thumb_" should not appear.

Regards

Fabian

ps.: Make sure that the user you are testing this with has the roles to see the attachments as well.

Sagar Pagar
Tera Patron

Hi,

Try this script - It will be helpful for you. Once you added this, make sure to add this Related list on Catalog task form.

(function refineQuery(current, parent) {

var queryString = "table_name=sc_req_item^table_sys_idIN" + parent.getValue("request_item");
	
	var gr = new GlideRecord("sc_task");
	gr.addQuery("sys_id", parent.getValue("request_item"));
	gr.query();
	while (gr.next()) {

		queryString += "," + gr.sys_id.toString();
	}
	current.addEncodedQuery(queryString);

})(current, parent);

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hello Everyone i have same issue in sys_attachment table the attachment is getting attached twice with same sys_id , how to resolve this issue ?