bsm033
Contributor
Contributor

Create Java script function

Jump to solution

Hi,

I try to create the following java script function to pull out some string:

String.prototype.left = function( findWhat )

{

try

{

var position = this.search( findWhat );

if ( position > -1 )

return this.substr( 0, position );

}

catch( e )

{

//alert(e.message);

}

return "";

};

var text = "myText-description";

var delimiter = "-";

In this example i try to pull out the word from left before the "-" delimiter (mtText)

But i get the following error message: Cannot add a property to a sealed object: left

My question is how can i create a simple js function in the Orchestrator using the following example

Thanks

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal

Hi,

You can try the below code to pull out a string from the left of the delimiter.


searchstr();

function searchstr() {
   try{
   var str = "angela.soni"
   var pos = str.indexOf("."); // Currently this is hard coded, you can pass delimiter as an input parameter.
   if(pos>-1) {
      var substr = str.substring( 0, pos );
      System.log(substr);
   }
   else { 
      System.error("Delimiter not found");
   }  
  } 
  catch (e) {
   System.error("Search failed: " + e);
  }
}

I hope this would help you.

Thanks!

Angela

View solution in original post

0 Kudos
2 Replies
admin
Immortal
Immortal

Hi,

You can try the below code to pull out a string from the left of the delimiter.


searchstr();

function searchstr() {
   try{
   var str = "angela.soni"
   var pos = str.indexOf("."); // Currently this is hard coded, you can pass delimiter as an input parameter.
   if(pos>-1) {
      var substr = str.substring( 0, pos );
      System.log(substr);
   }
   else { 
      System.error("Delimiter not found");
   }  
  } 
  catch (e) {
   System.error("Search failed: " + e);
  }
}

I hope this would help you.

Thanks!

Angela

View solution in original post

0 Kudos
bsm033
Contributor
Contributor

Thanks

0 Kudos