@@ -248,6 +248,48 @@ function addMySource() {
248248}
249249```
250250
251+ ### Sample 4: Set a specific library version in the script
252+ ``` javascript
253+ function updateLibraryVersion (libraryId = ' ' , libraryName = ' ' , version ) {
254+ const script_id = ScriptApp .getScriptId ();
255+ const current_script_json = ScriptSync .getScriptContent (script_id);
256+ var appsscript_json = current_script_json .files .find (file => {
257+ return file .name === " appsscript"
258+ });
259+
260+ if (appsscript_json) {
261+ appsscript_json = JSON .parse (appsscript_json .source );
262+ var library = appsscript_json .dependencies ? .libraries ? .find (lib => {
263+ return (
264+ lib .libraryId === libraryId
265+ || lib .userSymbol === libraryName
266+ );
267+ });
268+
269+ if (library) {
270+ let new_version = version || Number (library .version ) + 1 ;
271+ library .version = (new_version).toString ();
272+ appsscript_json .source = JSON .stringify (appsscript_json, null , 2 );
273+ const updater = ScriptSync .assignTemplate ();
274+ updater .addFileToUserJson (" appsscript" , appsscript_json);
275+ updater .viewChanges (370 );
276+ Utilities .sleep (20000 ); // waiting for interruption by user (if needed)
277+ return updater .commit (); // after, apply the changes
278+ }
279+ }
280+ return false ;
281+ }
282+
283+ function do (e ) {
284+ // ....
285+ const libraryId = " library_script_id" ;
286+ const libraryName = " LibraryNameUsersDefined" ;
287+ const updateResult = updateLibraryVersion (libraryId, libraryName);
288+ console .log (updateResult);
289+ // ...
290+ }
291+ ` ` `
292+
251293# Restrictions
252294
253295PLEASE EXERCISE CAUTION WHEN RENAMING AND DELETING FILES!
0 commit comments