Javascript in SC 6.x is a great improvement and will make it easier to code reusable.
Lets start posting usefull javascripts and tips & tricks.
I'll start with a script I wrote. This script will move attachments from a call, incident, change etc to an activity record. This way it is possible to keep a history of changes in the attachments.
Code:// This script moves attachment from the normal attachment container to an activity record. // Will create the activity record and update the attachments. // // The unique key on the activity dbdict must have "thenumber" as the first field // Also add new trigger to run this script. Script is called like this: // // system.library.ActivityAttachments.moveAttachment( record, oldrecord ); // function moveAttachment(record, oldrecord) { var strFileName = system.functions.filename( record ); var strRecordID; var strActivityFilename; strRecordID = record.number ; switch (strFileName) { case "probsummary": strRecordID = record.number ; strActivityFilename = "activity" ; break; case "cm3r": strRecordID = record.number ; strActivityFilename = "activitychanges" ; break; case "incidents": strRecordID = record.incident_id ; strActivityFilename = "activityservicemgt" ; break; case "rootcause": strRecordID = record.id ; strActivityFilename = "activityproblem" ; break; case "knownerror": strRecordID = record.id ; strActivityFilename = "activityknownerror" ; break; default: break; } var activityFile = new SCFile(strActivityFilename); var sysattachmentsFile = new SCFile("SYSATTACHMENTS"); var strSqlActivity; var strSqlSysattachments; var strActivityID = new String; var arrDescription = new Array(); var today = new Date(); var future = new Date(); var negdatestamp = new Date(); var intCount = 2; future.setDate(1); future.setMonth(1); future.setFullYear(2200); future.setHours(1); future.setMinutes(0); future.setSeconds(0); negdatestamp.setTime(future - today); // Prepare activity record activityFile.number = strRecordID; activityFile.type = "Attachment Added"; activityFile.operator = system.functions.operator(); activityFile.datestamp = today; activityFile.negdatestamp = negdatestamp; activityFile.doInsert(); strActivityID = activityFile.thenumber; arrDescription[0] = "Attachment(s) Added"; // Modify attachments records in SYSATTACHMENTS to move them to the activity record strSqlSysattachments = "topic = \""+strRecordID+"\" and application = \""+strFileName+"\""; if (sysattachmentsFile.doSelect( strSqlSysattachments ) == RC_SUCCESS ) { do { sysattachmentsFile.application = strActivityFilename; sysattachmentsFile.topic = strActivityID; sysattachmentsFile.doUpdate(); arrDescription[intCount] = sysattachmentsFile.filename; intCount = intCount + 1; } while (sysattachmentsFile.getNext() == RC_SUCCESS); } activityFile.description = arrDescription; activityFile.doUpdate(); }



Reply With Quote

so as long as there's no mix up, you're OK.

Bookmarks