does slice and substring js functions not work on task scripts?

Jace Benson
Mega Sage

Does the slice or substring functions not work on catalog task advanced scripts?

I would think this would work. Mark.Stranger has directed people to use it in a script in another forum topic.

I need to get the get the first three characters of a variable from a requested item. I can return the who result, but I cannot modify the answer, it just gives me undefined.

I tried this on the demo site, I can reproduce it there.

Okay, the set up, a field that has at least three characters in it. I looked for an item with a small text field, iPhone 3g, it has a small text field for the original phone number but has no rules to make it numbers, great!
That's known as current.variable_pool.original.

I looked to see if the item had a workflow, it didn't. So I changed the item to have the workflow, Service Catalog Item Request.

I went into the workflow editor and checked this out, added a catalog task to the start that used the advanced script. Below it is;
task.description = "Test\n";
task.description += "current.variable_pool.original: " + current.variable_pool.original + "\n";
task.description += "current.variable_pool.original.substring(0,3): " + current.variable_pool.original.substring(0,3) + "\n";
task.description += "current.variable_pool.original.slice(0,3): " + current.variable_pool.original.slice(0,3) + "\n";

All of these should work however, my result when the number is "abcdef" is below;
Test
current.variable_pool.original: abcdef
current.variable_pool.original.substring(0,3): undefined
current.variable_pool.original.slice(0,3): undefined

I know it will be a new copy tomorrow, but now you know what I'm doing, any thoughts on another way to accomplish this. I don't want to change the values of the variables as they are in a dropdown and the full text of it looks better than an abbreviation.

Here's a link to task in demo

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

Try this. You need to force the variable value to be a string...



var orig = current.variable_pool.original.toString();
task.description = "Test\n";
task.description += "current.variable_pool.original: " + current.variable_pool.original + "\n";
task.description += "current.variable_pool.original.toString();substring(0,3): " + current.variable_pool.original.toString().substring(0,3) + "\n";
task.description += "orig.slice(0,3): " + orig.slice(0,3) + "\n";


View solution in original post

4 REPLIES 4

Mark Stanger
Giga Sage

Try this. You need to force the variable value to be a string...



var orig = current.variable_pool.original.toString();
task.description = "Test\n";
task.description += "current.variable_pool.original: " + current.variable_pool.original + "\n";
task.description += "current.variable_pool.original.toString();substring(0,3): " + current.variable_pool.original.toString().substring(0,3) + "\n";
task.description += "orig.slice(0,3): " + orig.slice(0,3) + "\n";


I knew it was something simply. Thanks!


It helped me, Thank you .


Thanks a lot 🙂