Layout > Update Table of Contents.
I'm confused as to why this is a scripting question. When you set up a TOC correctly, updating the page numbers without losing formatting is automatic. You have control over everything in the Table of Contents dialog box—it's really powerful. For details, see https://helpx.adobe.com/indesign/using/creating-table-contents.html.
Workflow in my company is not 100% and after creating toc workers make formating by hand...yea, stupid i know..this is reason why i need way to update only page numbers in toc. We use scripts for some tasks and this will be good update for some of this sripts.
"Workflow in my company is not 100% and after creating toc workers make formating by hand...yea, stupid i know."
You do have the option of creating proper TOC styles using selections from the manually formatted TOC, then regenerating. Might take about 3 minutes. That way you accomplish the update, and facilitate clean ones going forward.
This is a situation where you just need to educate your co-workers on how to work with a TOC correctly in InDesign. Specifically, let them know that edits are made to the source files and then the TOC is updated to reflect those edits with the current page numbers.
What you are asking for is part of InDesign's out-of-the-box feature set. I'm sure you can hire someone to write a custom script for you, but why pay a programmer to write a script for a feature that is already included with the software?
Alternatively, generate your ToC once and then replace all page numbers with crossreferences. See https://helpx.adobe.com/indesign/using/cross-references.html
Edits in the text won't update the ToC anymore but text reflows will update the page numbers totally automatic.
Could you please explain step by step?
As I'm not managing to find it in the guide.