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

cancel
Showing results for 
Search instead for 
Did you mean: 
hernanisaurelio
Active Member II

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

Jump to solution

Captura de ecrã 2022-04-19 151823.png

 

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 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: Capture site name or current url from javascript run in (Repository > Data Dictionary > Sc

Jump to solution

@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 solution in original post

3 Replies
abhinavmishra14
Advanced

Re: Capture site name or current url from javascript run in (Repository > Data Dictionary > Sc

Jump to solution

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)
hernanisaurelio
Active Member II

Re: Capture site name or current url from javascript run in (Repository > Data Dictionary > Sc

Jump to solution

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

abhinavmishra14
Advanced

Re: Capture site name or current url from javascript run in (Repository > Data Dictionary > Sc

Jump to solution

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