cancel
Showing results for 
Search instead for 
Did you mean: 

Capture site name or current url from javascript run in (Repository > Data Dictionary > Scripts)

hernanisaurelio
Confirmed Champ
Confirmed Champ

image

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.

1 ACCEPTED ANSWER

@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.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View answer in original post

3 REPLIES 3

abhinavmishra14
World-Class Innovator
World-Class Innovator

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.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

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

@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.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)