Reload a form right after attaching files

Koji Yanase
Tera Contributor

Can we reload a form automatically right after attaching files? I wrote a business rule which count up attachments and show the number in the form. But we need to refresh the form to display the new number. So it should be reloaded automatically right after attaching files.

Thanks.

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Koji, why don't you do this through a client script?



You can use the client function getCurrentAttachmentNumber(sys_id_of_your_record) to get the Attachment Number for your record.



This function just looks-up into the field which holds the attachmentNumber for that record. Here goes how internally ServiceNow has defined this function:



function getCurrentAttachmentNumber(sysid) {


if ($$('.attachmentNumber_' + sysid)[0] == undefined) {


if ($('header_attachment_list_label') == undefined)


return undefined;


else


return $('header_attachment_list_label').down().innerHTML;


}



Clarification: This function is already defined and available in your client code.



Thanks,


Berny


View solution in original post

12 REPLIES 12

Sharath Chandra
ServiceNow Employee
ServiceNow Employee

Hi Koji,



Can you provide more details on the requirement, trying to understand why you are reloading the form? If you are using OOTB attachment icon, it will get you the attachment count as soon as you attach documents to the form. Are you using your custom attachment icon?



You may not want to refresh the form, reason being it will generate a new record when you refresh.



Regards,


Sharath


Hi Sharath, Thank you for your quick reply.


I added the field that show the number of attachments. When the number is not zero, some button is displayed using UI action which copy the attachments to another related form. So I need to reflect the real number to the field immediately. Or can I use the attachment count directly?


Thanks,


Koji


Hi Koji,



You can use the attachment count directly as it gives you the total number of attachments for the current record. (Or) If you want to update the field on the form with the number of attachments, why not use an onLoad/onChange client script to do the same for you.



Regards,


Sharath


Hi Sharath,


I can't find the field which keeps the number of attachment originally. How could I refer the count in my UI action?


Thanks,


Koji