04-20-2022 05:25 AM
I'm having a hard time getting
the current url in the share.
I'm adding a script in Repository > Data Dictionary > Scripts
I need to capture the name of the site I'm on or the current url
but an error is coming.
" 254 KB (Failure: Failed to execute script 'workspace://SpacesStore/9c2b6207-ed5a-48f1-9fa9-350616033cc0': 03190438 ReferenceError: "window" is not defined. (workspace://SpacesStore/9c2b6207-ed5a-48f1-9fa9-350616033cc0#9))
"
Thank you very much in advance.
04-28-2022 03:25 PM
@hernanisaurelio You can use the root scoped object "document" and then get the site name.
Example: get-sitename-folder-rule.js (here 'document' is the folder node where you are creating the folder rule)
logger.log("FolderDisplayPath where rule is created: "+ document.displayPath);
var siteName = document.getSiteShortName(); logger.log("SiteName: "+ siteName);
//do whatever you want with the site name
Then you can use siteService.getSite() or siteService.getSiteInfo() to pull more info about site as needed, you will get Site or SiteInfo objects to play around.
example:
logger.log("FolderDisplayPath where rule is created: "+ document.displayPath); //get site short name from folder nodeRef var siteShortName = document.getSiteShortName(); logger.log("SiteShortName: "+ siteShortName); var siteInfo = siteService.getSiteInfo(siteShortName); logger.log("Site Display Title: "+siteInfo.getTitle()); //Or getSite var site = siteService.getSite(siteShortName); logger.log("Site Display Title: "+site.getTitle());
Hope this helps.
04-20-2022 09:43 AM
AFAIK, window object wont work in repository webscript/script. Not sure though.
If you can elobrate the use case and requirement as to what exactly you are trying to do then some potential solution can be thought of.
04-20-2022 10:48 AM
Mr. abhinav mishra
thank you very much for your time.
I intend to run this script in a specific folder on a site
How can I capture just the current site name in my script.
Thank you very much in advance
04-28-2022 03:25 PM
@hernanisaurelio You can use the root scoped object "document" and then get the site name.
Example: get-sitename-folder-rule.js (here 'document' is the folder node where you are creating the folder rule)
logger.log("FolderDisplayPath where rule is created: "+ document.displayPath);
var siteName = document.getSiteShortName(); logger.log("SiteName: "+ siteName);
//do whatever you want with the site name
Then you can use siteService.getSite() or siteService.getSiteInfo() to pull more info about site as needed, you will get Site or SiteInfo objects to play around.
example:
logger.log("FolderDisplayPath where rule is created: "+ document.displayPath); //get site short name from folder nodeRef var siteShortName = document.getSiteShortName(); logger.log("SiteShortName: "+ siteShortName); var siteInfo = siteService.getSiteInfo(siteShortName); logger.log("Site Display Title: "+siteInfo.getTitle()); //Or getSite var site = siteService.getSite(siteShortName); logger.log("Site Display Title: "+site.getTitle());
Hope this helps.
Explore our Alfresco products with the links below. Use labels to filter content by product module.