Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 4 of 4

Thread: Javascript JS string function help needed

  1. #1
    Junior Member dukestanley's Avatar
    Join Date
    Jan 2008
    Posts
    23

    Default Javascript JS string function help needed

    I am actually looking for to pickup a number from the Description(action) of the incident record. Any help wud be appreciated.

    example an ovo alert message at HPSM:
    incident description--> sss.sss.com failed (REF#11335) to run the CRON job

    I need to pick up the "11335" using javascript at formatcontrol-->IM.template.open

  2. #2
    Senior Member glg's Avatar
    Join Date
    Aug 2004
    Location
    Chicago, IL, USA
    Posts
    715

    Default

    Will it always be contained in the (REF#XXXXX) and that's on the first line? Is it always going to be 5 characters? If so, this should work. Give it a try.

    var desc1 = incident.description[0]; // Gets first line of description (which is an SC array) into a JS string
    var refindex = desc1.indexOf("REF"); // Get location of REF, number returned is the R, so
    var refnumber = desc1.substr(refindex+4, 5); // number starts 4 characters after the R, and is 5 characters long

  3. #3
    Junior Member dukestanley's Avatar
    Join Date
    Jan 2008
    Posts
    23

    Default

    Thanks glg. I have completed this task and works fine..
    sDescription = aAction.toString();
    nStart = sDescription.indexOf("SPEDI_")+6;
    nEnd = sDescription.indexOf("_",nStart);
    sNumber = sDescription.substr(nStart,nEnd-nStart);
    spediNum = sNumber;
    print(spediNum);

  4. #4
    Senior Member glg's Avatar
    Join Date
    Aug 2004
    Location
    Chicago, IL, USA
    Posts
    715

    Default

    if you're finding an end character, use substring instead of substr:
    sNumber = sDescription.substring(nStart, nEnd);

    substr(start, length)
    substring(start, end)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts