I am getting an error in Webscript

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 01:01 PM
var catSearchPath = "PATH:\"/cm:categoryRoot/cm:generalclassifiable/cm:" + categories[j].replace(/\+/g,"_x0020_").replace(/&/g,"_x0026_").replace(/\//g, "/cm:");
However in another place I am using the JS function in the same web script.
function getSpaceXPath(disPath,rootsapce){ var spacePath="PATH:\""; var disPPath=disPath.split("/") for (k=1;k<disPPath.length;k++ ){ if (disPPath[k]=="Company Home"){ spacePath+="/app:company_home"; } else{ var value=disPPath[k]; spacePath+="/cm:"+value.(/ /g,"_x0020_").replace(/&/g,"_x0026_"); } }spacePath+="/cm:"+rootsapce+"//*\""return spacePath;}
In the first case the script replace the "+" with "_0020_"; in the second case the script is throwing error, It is not replaing the space to "_0020_"
ERROR is
Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/bg/portlet/links/links.get.js': Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/bg/portlet/links/links.get.js': The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are: class java.lang.String replace(java.lang.CharSequence,java.lang.CharSequence) class java.lang.String replace(char,char) (AlfrescoScript#76) Exception: org.mozilla.javascript.EvaluatorException - The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are: class java.lang.String replace(java.lang.CharSequence,java.lang.CharSequence) class java.lang.String replace(char,char) (AlfrescoScript#76)
Any help is appriciated. Thanks
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 05:24 AM
spacePath+="/cm:"+value.(/ /g,"_x0020_").replace(/&/g,"_x0026_");
should it be
spacePath+="/cm:"+value.replace(/ /g,"_x0020_").replace(/&/g,"_x0026_");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 09:13 AM
Thanks for your response. I am sorry i missed the replace while cut and copy in the posting,
In the actual code i have the code snippet what you have pointed out. Thanks you so much for poiting out.
spacePath+="/cm:"+value.replace(/ /g,"_x0020_").replace(/&/g,"_x0026_");
The above one gives error which i have mentioned.
I do not know why one place it works fine with javascript regex another place it is not working. I need to replace all the spaces and all the "&"
How ever the below one is not giving the error.
spacePath+="/cm:"+value.replace(" ","_x0020_").replace("&","_x0026_");
however it is not replacing all the spaces and "&"
Any help is appricited. Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 01:14 PM
This means that you need something like
spacePath+="/cm:"+value.replaceAll(" ","_x0020_").replaceAll("&","_x0026_");
rather than the standard javascript replace function. It seems you have a java string and not a javascript string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2007 06:10 PM
var trimmed = str.replace(/^\s+|\s+$/g, '') ;
thanks,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2007 06:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2008 11:22 AM
using the trim() function works sometimes versus others, this is the error that i get with the same code at different time.
: TypeError: Cannot find function trim. (AlfrescoScript#84
then if i use
args[arg].replace(/^\s+|\s+$/g, '') ;
it works sometimes but it also gives error on some other instances
candidate constructors are: class java.lang.String replace(java.lang.CharSequence,java.lang.CharSequence) class java.lang.String replace(char,char) (AlfrescoScript#40)
Can someone clear this up. what are the dependencies here. Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2008 08:49 AM
I had the same problem applying a regular expression to a string to trim it. I found an easy solution to this, instantiating a new String, so that the replace operates on a standard JavaScript String :
function trimString(str) { var s = new String(str); return s.replace(/^\s+|\s+$/g, '');}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2008 11:36 AM
var x = 'some string to replace in';
You can use the following code for the replaceAll to work…
x = new java.lang.String(x).replaceAll(" ", "_x0020_");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2014 05:52 AM
var x = "jbpm$132 ;";
while(x.indexOf(" ") >-1){
x=x.replace(' ','');
}
