-
Notifications
You must be signed in to change notification settings - Fork 1
/
moveAttachments.crmscript
40 lines (35 loc) · 1.36 KB
/
moveAttachments.crmscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#setLanguageLevel 3;
// config section
Integer idBump = 1234;
String targetPath = "c:\\temp\\target\\attachments"; // No trailing \
String srcPath;
// srcPath = "c:/temp/source/attachments"; // Comment out if not needed
String getNumberPart(Integer id) {
String tmp = id.toString();
while (tmp.getLength() < 6)
tmp = "0" + tmp;
return tmp;
}
String getFolder(Integer id) {
return "folder." + getNumberPart(id / 10000);
}
Map targetFolders;
SearchEngine se;
se.bypassNetServer(true);
se.addField("attachment.id");
se.addField("attachment.attachment_location_id.path");
se.addOrder("attachment.id", true);
for (se.execute(); !se.eof(); se.next()) {
Integer attachmentId = se.getField("attachment.id").toInteger();
String targetFolder = getFolder(attachmentId + idBump);
if (targetFolders.exists(targetFolder) == false) {
printLine("mkdir \"" + targetPath + "\\" + targetFolder + "\"");
targetFolders.insert(targetFolder, "true");
}
String sourceAttachments = se.getField("attachment.attachment_location_id.path");
if (srcPath != "")
sourceAttachments = srcPath;
String source = sourceAttachments + "\\" + getFolder(attachmentId) + "\\attachment." + getNumberPart(attachmentId);
String target = targetPath + "\\" + targetFolder + "\\attachment." + getNumberPart(attachmentId + idBump);
printLine("copy \"" + source + "\" \"" + target + "\"");
}