Topic Options
#56885 - 03/26/19 11:26 AM java scrip to search for the file name
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 320
Loc: Home
Hi OL Team,

I'm using a java script to capture file using the first 6 character, but my script is not correct, and need your help.

I want to use a case statement then Folder Capture, cause there could be 100s of files starts with ABC999......

ABC999xv1.pdf
ABC999yv2.pdf
ABC999dv3.pdf

I want to capture any files starts with ABC999

code is:

var FileName
FileName = Watch.getjobinfo(9)

switch (FileName)
{
case "ABC999" :
Script.returnvalue = 1;
break;
case "ABC888" :
Script.returnvalue = 1;
break;
default :
Script.returnvalue = 0;
break;
}

THANKS
_________________________
Peace

Top
#56887 - 03/26/19 11:43 AM Re: java scrip to search for the file name [Re: Sami786]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 459
Loc: Québec, Canada
Code:
var FileName
FileName = Watch.getjobinfo(9)

switch (FileName.substr(1,6))
{
case "ABC999" :
Script.returnvalue = 1;
break;
case "ABC888" :
Script.returnvalue = 1;
break;
default :
Script.returnvalue = 0;
break;
}

Top
#56889 - 03/26/19 12:32 PM Re: java scrip to search for the file name [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 320
Loc: Home
Great, thank you so much
_________________________
Peace

Top
#56891 - 03/28/19 09:52 AM Re: java scrip to search for the file name [Re: Sami786]
Philippe F. Offline
OL Expert

Registered: 09/06/00
Posts: 1926
Loc: Objectif Lune, Montreal, Qc
Using a Regular Expression, you can do this with a one-line script and the matching is case-insensitive:
Code:
Script.returnvalue = /^(ABC999|ABC888)/i.test(Watch.getjobinfo(9));


You can specify inside the parentheses all the patterns to be matched, separated with a pipe ( | ).

Read up on Regular Expressions, they are your friend... smile


Edited by Philippe F. (03/28/19 09:53 AM)
Edit Reason: typos
_________________________
Technical Product Manager
I don't want to achieve immortality through my work; I want to achieve immortality through not dying - Woody Allen

Top
#56893 - 03/28/19 11:03 AM Re: java scrip to search for the file name [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 320
Loc: Home
Great, thanks
_________________________
Peace

Top