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

Hi Koji, your UI action need to be a client one. If that's the case, then you just need to call the function:



getCurrentAttachmentNumber('here_goes_the_sys_id_of_your_record');



Thanks,


Berny


You could also access the field directly on the following way:



var sys_id = 'here_goes_the_sys_id_of_your_record';


gel('attachmentNumber_' + sys_id).innerHTML;



Thanks,


Berny


Hi Berny, Thank you for your advice.


Should I make the function as a script include or UI script?


Thanks,


Koji


Hi Koji, the function getCurrentAttachmentNumber is already defined as part of the internal client functions of ServiceNow



Thanks,


Berny


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