Use case: JavaScript Developer

As a developer, I’d like to count the attachments related to interactions related to an incident.

  1. Log in as falcon,

  2. Navigate to Tailoring> Script Library

  3. Type getAttachments in the Name field.

  4. Click Add.

  5. Copy and paste the following code into the code window:

    var start=new Date();
    var file = new SCFile("probsummary");
    var sql = "SELECT pro.*, scr.*, att.* FROM probsummary pro, screlation scr inner join SYSATTACHMENTS att on (scr.source=att.topic ) where scr.depend=pro.number and scr.depend=\"IM10002\" and att.segment=0";
    var success=file.doSelect( sql ) ;
    
    
    var findNextRecord=RC_SUCCESS;
    var count=0;
    //iterate to print the related attachment names
    while ( success== RC_SUCCESS && findNextRecord == RC_SUCCESS && count<120)
    {
        print("find attachment No.: " + count + " " + file.filename + " in " + file.topic);
        //print(system.functions.descriptor(file));
        findNextRecord=file.getNext();
        count++;
     } 
    
    var end=new Date();
    var timespent = end-start;
    print ("select time is: " + timespent + "ms");
    start=new Date();
    
    //count how many attachments are related to this incidents
    count=file.doCount(sql);
    print ("There are " + count + " attachments");
    end=new Date();
    timespent = end-start;
    print ("count time is: " + timespent + "ms");
  6. Save and compile the JavaScript code.

  7. Execute the compiled code.