Marking a field as True if Attachment is added to the form

Alon Grod
Tera Expert

Hi,


I have the field 'Attachment Added' of type True/False. I need to mark this field as True, if attachment is added to the incident form.

How can I achieve that?

1 ACCEPTED SOLUTION

Michael Ward
Kilo Guru

Hi Alon,

 

You could have a before insert business rule on the attachment table.

 

1. GlideRecord the incident table to query the incident number

2. While loop through the records to check if the worknotes contains "Attachment: " + current.file_name + " has been attached.";

3. set gr.attachment_added = true;

4. gr.update;

 

Let me know if this helps! 

View solution in original post

5 REPLIES 5

Michael Ward
Kilo Guru

Hi Alon,

 

You could have a before insert business rule on the attachment table.

 

1. GlideRecord the incident table to query the incident number

2. While loop through the records to check if the worknotes contains "Attachment: " + current.file_name + " has been attached.";

3. set gr.attachment_added = true;

4. gr.update;

 

Let me know if this helps! 

Anurag Tripathi
Mega Patron
Mega Patron

Hi Alon,

 

Check the solution on this thread.

Solved: Update field based on attachment - ServiceNow Community

-Anurag

Community Alums
Not applicable

Hi @Alon Grod ,

I checked your problem in my PDI and it works for me 

I created onLoad Client script and aaded below code 

function onLoad() {
    //Type appropriate comment here, and begin script below
	alert("getUniqueValue" + g_form.getUniqueValue());
    var gr = new GlideRecord("sys_attachment");

    gr.addQuery("table_name", "incident");
    gr.addQuery("table_sys_id", g_form.getUniqueValue());
    gr.query();
	if(gr.next()){
		g_form.setValue('u_isattachmentadded', true);
		g_form.update()
	}
}

SarthakKashyap_0-1714553387067.png

 

Result 

SarthakKashyap_1-1714553407825.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

I wouldn't recommend GlideRecord in a client script.

-Anurag