diff --git a/Specialized Areas/Fix scripts/Copy favourite to other users/README.md b/Specialized Areas/Fix scripts/Copy favourite to other users/README.md index acbe6b7361..4067de50fc 100644 --- a/Specialized Areas/Fix scripts/Copy favourite to other users/README.md +++ b/Specialized Areas/Fix scripts/Copy favourite to other users/README.md @@ -1,3 +1,7 @@ +**Enhancement** +1. This code will create the sp favorites of the selected users along with the sys_ui_bookmarks. +2. The entry will be made in "sp_favorite" through new **createPortalFav** function. + You can use this script to take an existing favaourite from the sys_ui_bookmark table and create a copy of it for any number of users. Can be useful when onboarding new staff, doing testing, etc. diff --git a/Specialized Areas/Fix scripts/Copy favourite to other users/favCopy.js b/Specialized Areas/Fix scripts/Copy favourite to other users/favCopy.js index a6cb18a644..867b1f993d 100644 --- a/Specialized Areas/Fix scripts/Copy favourite to other users/favCopy.js +++ b/Specialized Areas/Fix scripts/Copy favourite to other users/favCopy.js @@ -1,9 +1,12 @@ var srcFav = ""; // Add the sys_id of the favourite to copy, from sys_ui_bookmark table +var portalFav = ""; // Add the sys_id of the favourite to copy, from sp_favorite table. var userCriteria = ""; // Add an encoded query of users from sys_user table - var fav = new GlideRecord("sys_ui_bookmark"); fav.get(srcFav); +var portalFavRec = new GlideRecord("sp_favorite"); +portalFavRec.get(portalFav); // glide record of favorite record. + var users = new GlideRecord("sys_user"); users.addEncodedQuery(userCriteria); users.query(); @@ -18,4 +21,18 @@ while(users.next()) { newFav.setValue("url",fav.url); newFav.setValue("user",users.sys_id); newFav.insert(); + + createPortalFav(users); // function to create portal favorites +} +function createPortalFav(userRec){ + var newPortalFav = new GlideRecord("sp_favorite"); + newPortalFav.initialize(); + newPortalFav.setValue('user',userRec.user); + newPortalFav.setValue('reference_table',portalFavRec.reference_table); + newPortalFav.setValue('reference_document',portalFavRec.reference_document); + newPortalFav.setWorkflow(false); // OOB Sscript include take the logged-in user to check the duplicate records so workflow false restricts the SI to run. + newPortalFav.insert(); } + + +