home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / omnidemo.zip / RXGMIN.CMD < prev   
OS/2 REXX Batch file  |  1997-07-01  |  14KB  |  372 lines

  1. /* REXX PROGRAM */
  2. /* This file is for importing GoldMine data into OmniFile */
  3. /* This REXX program expects OMNIFILE or CCV2 to be the host environment */
  4. /* If you are attempting to change this file, you will normally only need to change the commands in the CHANGE_REC subroutine and the user variables. */
  5.  
  6. /********* USER VARIABLES ***********************/
  7. /* If useCreateOwner is set to 1 the created by and owner fields will be stored as a note */
  8. /* By default, we set this variable to 0 to indicate that these fields will not be converted */
  9. /* If useLastInfo is set to 1, the fields regarding the last time the record was changed will be added as a note*/
  10. /* By default, we set this variable to 0 to indicate that these fields will not be converted */
  11. /* If separateBusinesses is set to 1, then Goldmine records with a business name but no contact name will be */
  12. /* added to the Business database, as opposed to the Individual database.  Set it to 0 if you want all */
  13. /* records added to the Individuals database  */
  14. /* If useAccountNum is set to 1, the account number assigned by GoldMine will be used as an ID for the record */
  15. /* By default, we set this variable to 0 to indicate that this field will not be converted; only pertains to GoldMine 95*/
  16. /* If useStatus is set to 1, the status field is added as a note */
  17. /* By default, we set this variable to 0 to indicate that this field will not be converted */
  18. useCreateOwner = 0
  19. useLastInfo=0
  20. separateBusinesses=1
  21. useAccountNum = 0
  22. useStatus = 0
  23. Delimiter = '|'
  24. /****************************************************/
  25.  
  26. /*  Define field numbers */
  27. fileType=GetTypeGivenName("File")
  28. fileTypeType=GetTypeGivenName("File Type")
  29. actionType=GetTypeGivenName("Action")
  30. actionTypeType=GetTypeGivenName("Action Type")
  31. codeTypeType=GetTypeGivenName("Code Type")
  32.  
  33. /* these are field numbers for individuals */
  34. prefixFieldNum = 2
  35. firstFieldNum= 3
  36. middleFieldNum= 4
  37. lastFieldNum=5
  38. suffixFieldNum = 6
  39. jobTitleFieldNum = 10
  40. IidFieldNum = 1
  41. IaddressFieldNum = 12
  42. IphoneFieldNum = 13
  43. IcodeFieldNum = 14
  44. InotesFieldNum = 15
  45.  
  46. /* these are field numbers for businesses */
  47. BidFieldNum = 1
  48. BaddressFieldNum = 4
  49. BphoneFieldNum = 5
  50. BcodeFieldNum = 6
  51. BnotesFieldNum = 7
  52.  
  53. addressTypeFieldNum = 1
  54. addressAddressFieldNum = 3
  55. addressCityFieldNum = 4
  56. addressStateFieldNum = 5
  57. addressZipFieldNum = 6
  58. addressCountryFieldNum = 7
  59. addressNoteFieldNum = 8
  60. phoneTypeFieldNum = 1
  61. phonePhoneFieldNum = 2
  62. phoneNoteFieldNum = 3
  63. fileTypeFieldNum = 1
  64. fileNameFieldNum = 2
  65. codeTypeField = 1
  66. actionTypeField = 1
  67. actionCompletedField = 2
  68. actionDateField = 3
  69. actionTimeField = 4
  70. actionFreqField = 5
  71. actionSummaryField = 7
  72.  
  73. /* MAIN SUBROUTINE */
  74. szEnvironment = address()
  75. IF ((szEnvironment <> "Omnifile") & (szEnvironment <> "Contacts")) THEN DO
  76.     SAY "This rexx file can only be run by Omnifile or Contact Connection, not directly."
  77.     RETURN 1
  78.     END
  79.  
  80. /* FileIn1 is the file with all the GoldMine exported data; provided by user */
  81. FileIn1 = ARG(1)
  82.  
  83. /* Make sure the required arguments were given. */
  84. IF FileIn1 = "" THEN DO
  85.     SAY "FILEIN1 is required."
  86.     RETURN 1
  87.     END
  88.  
  89. /* Set the delimiters and separators; GoldMine uses different terminology */
  90. SetDefaultQuoteChar(Delimiter)
  91. Separator = ','
  92. SetDefaultDelimiter(Separator)
  93.  
  94. /* Set the Header Line and pass it to OmniFile in order to initialize the import. */
  95. /* Literals in REXX have a limit of 250 chars; but can concatenate to make a bigger one */
  96. headerLine1 = 'Business Name, FullName, Last Name, Job Title, Address1, Address2, City, State, Zip, Country, Phone1, Phone1Ext, Phone2, Phone2Ext, Phone3, Phone3Ext, Fax, Phone4Ext, Informal Name,'
  97.  
  98. headerLine2='Department, Email, Asst, Source, Status, Comments, CreateBy, Key1, Key2, Key3, Key4, Key5, AccountNum, Owner, u1,u2,u3,u4,u5,u6,u7,u8,u9,u10, PrevResult, LastDate, LastTime, LastUser,'
  99.  
  100. headerLine3='LastContAt, LastContOn, LastAttAt, LastAttOn, NextMeetOn, NextMeetAt, NextAction, SaleDate, CallBackAt, CallBackOn, CallBackFreq, NextActionOn, NoteString'
  101.  
  102. headerLine=headerLine1||headerLine2||headerLine3
  103.  
  104. /* For each line in the input file, load the line, load the Rexx variables, modify the Rexx variables, and add the record. */
  105. DO while LINES(FileIn1)
  106.     line = LINEIN(FileIn1)
  107.     multiline = 0
  108.     /* if there's a multiline note field, then need to append a delimiter at end of line */
  109.     lineLength=LENGTH(line)
  110.     PARSE VAR line a =(lineLength) lastChar
  111.     IF lastChar \= Delimiter THEN DO
  112.         line = line || Delimiter
  113.         multiline = 1
  114.         END
  115.     RecType = GetTypeGivenName("Individual")
  116.     SetDefaultType(RecType)
  117.     SetHeaderLine(headerLine)
  118.     SetRexxVariables(line)
  119.     IF separateBusinesses=1 & FullName= "" & BusinessName \= "" THEN DO
  120.         RecType = GetTypeGivenName("Business")
  121.         SetDefaultType(RecType)
  122.         SetHeaderLine(headerLine)
  123.         SetRexxVariables(line)
  124.         inBusiness = 1
  125.         idFieldNum = BidFieldNum
  126.         addressFieldNum = BaddressFieldNum
  127.         phoneFieldNum = BphoneFieldNum
  128.         codeFieldNum = BcodeFieldNum
  129.         notesFieldNum = BnotesFieldNum
  130.         END
  131.     ELSE DO
  132.         inBusiness = 0
  133.         idFieldNum = IidFieldNum
  134.         addressFieldNum = IaddressFieldNum
  135.         phoneFieldNum = IphoneFieldNum
  136.         codeFieldNum = IcodeFieldNum
  137.         notesFieldNum = InotesFieldNum
  138.         END
  139.     Rec = GetRec(0, RecType)
  140.     SetRecFromRexxVariables()
  141.     /* get rest of note if a multiline note */
  142.     IF multiline=1 THEN
  143.         DO while LINES(FileIn1)
  144.             line = LINEIN(FileIn1)
  145.             IF line=="" THEN line = " "
  146.             lineLength=LENGTH(line)
  147.             PARSE VAR line a =(lineLength) lastChar
  148.             IF lastChar == Delimiter THEN DO
  149.                 IF lineLength > 1 THEN DO
  150.                     PARSE VAR line line =(lineLength) .
  151.                     NoteString = NoteString || 'A'x || line
  152.                     END
  153.                 LEAVE
  154.                 END
  155.             NoteString = NoteString || 'A'x || line
  156.             END
  157.     CALL CHANGE_REC
  158.     AddRec()
  159.     END
  160. /* Close the file. */
  161. result=stream(FileIn1, 'c', 'close')
  162. RETURN 0
  163.  
  164.  
  165. /* SUBROUTINE */
  166. CHANGE_REC:
  167. /* Need to break FullName into first, middle, last etc.  */
  168. /* Goldmine only has explicit field for LastName, so we need to get the rest */
  169. IF inBusiness = 0 & FullName \= "" THEN DO
  170.     prefix=""
  171.     first=""
  172.     middle=""
  173.     suffix=""
  174.     firstPos=0
  175.     lastPos= 0
  176.     /* Parse the full name into words */
  177.     namestr=FullName
  178.     DO j=1 TO 50
  179.         IF namestr='' THEN LEAVE
  180.         PARSE VAR namestr name.j namestr
  181.         name.j=STRIP(name.j, 'B', ',')
  182.         IF name.j = LastName THEN lastPos=j
  183.         END
  184.     numnames=j-1
  185.     IF lastPos=0 THEN DO
  186.         lastPos=numnames
  187.         IF LastName="" THEN DO
  188.             LastName = name.lastPos
  189.             LastName=STRIP(LastName,'B')
  190.             Result=SetField(lastFieldNum, LastName, "String", "cur");
  191.             END
  192.         END
  193.     IF name.1='Mr.' | name.1='Mrs.' | name.1='Ms.' | name.1='Miss' | name.1='Dr.' | name.1='Prof.' THEN DO
  194.         prefix=name.1
  195.         firstPos=2
  196.         IF lastPos > 2 THEN first=name.2
  197.         END
  198.     ELSE DO
  199.         firstPos=1
  200.         IF lastPos > 1 THEN first=name.1
  201.         END
  202.     DO j=(firstPos+1) TO (lastPos-1)
  203.         middle = middle||name.j||' '
  204.         END
  205.     DO j=(lastPos+1) TO numnames
  206.         suffix = suffix||name.j||' '
  207.         END
  208.     prefix=STRIP(prefix, 'B')
  209.     first=STRIP(first,'B')
  210.     middle=STRIP(middle,'B')
  211.     suffix=STRIP(suffix,'B')
  212.     Result=SetField(prefixFieldNum, prefix, "String", "cur");
  213.     Result=SetField(firstFieldNum, first, "String", "cur");
  214.     Result=SetField(middleFieldNum, middle, "String", "cur");
  215.     Result=SetField(suffixFieldNum, suffix, "String", "cur");
  216.     END
  217.  
  218. /* Add in address if not blank */
  219. /* need to make one string out of the 2 Address strings */
  220. IF Address2 \= "" THEN Address1 = Address1||'A'x||Address2
  221. IF Address1 \= "" | City \= "" | State \= "" | Zip \= "" | Country \= "" THEN DO
  222.     subRec=GetSubRec(addressFieldNum, 0, "cur")
  223.     Result=SetField(addressTypeFieldNum, 2, "Int", "SubRec")
  224.     Result=SetField(addressAddressFieldNum, Address1, "String", "SubRec")
  225.     Result=SetField(addressCityFieldNum, City, "String", "SubRec")
  226.     Result=SetField(addressStateFieldNum, State, "String", "SubRec")
  227.     Result=SetField(addressZipFieldNum, Zip, "String", "SubRec")
  228.     Result=SetField(addressCountryFieldNum, Country, "String", "SubRec")
  229.     Result=AddRec(subRec, 0, "SubRec")
  230.     END
  231. /* GoldMine for Windows doesn't have an email field */
  232. IF Email \= "" & Email \= "WINDOWS" THEN DO
  233.     subRec=GetSubRec(addressFieldNum, 0, "cur")
  234.     Result=SetField(addressTypeFieldNum, 4, "Int", "SubRec")
  235.     Result=SetField(addressAddressFieldNum, Email, "String", "SubRec")
  236.     Result=AddRec(subRec, 0, "SubRec")
  237.     END
  238.  
  239. /* Add in phones; by default set type to WORK  */
  240. CALL ADD_PHONE Phone1, Phone1Ext, 2
  241. CALL ADD_PHONE Phone2, Phone2Ext, 2
  242. /* GoldMine appears to have a bug; phone4ext is switched with phone3ext when exporting */
  243. CALL ADD_PHONE Phone3, Phone4Ext, 2
  244. /* GoldMine has the 4th phone as a FAX */
  245. CALL ADD_PHONE Fax, Phone3Ext, 6
  246.  
  247. /* add in 5 codes */
  248. CALL ADD_CODE Key1
  249. CALL ADD_CODE Key2
  250. CALL ADD_CODE Key3
  251. CALL ADD_CODE Key4
  252. CALL ADD_CODE Key5
  253.  
  254. /*  Need to convert dates to OmniFile format */
  255. LastContOn=CONVERT_DATE(LastContOn)
  256. LastAttOn=CONVERT_DATE(LastAttOn)
  257. NextMeetOn=CONVERT_DATE(NextMeetOn)
  258. CallBackOn=CONVERT_DATE(CallBackOn)
  259. SaleDate=CONVERT_DATE(SaleDate)
  260. LastDate=CONVERT_DATE(LastDate)
  261.  
  262. /* Add in activities */
  263. CALL ADD_ACTIVITY LastContOn, LastContAt, "Contact", 1, ""
  264. CALL ADD_ACTIVITY LastAttOn, LastAttAt, "Call", 1, "Unsuccessful call attempt"
  265. CALL ADD_ACTIVITY NextMeetOn, NextMeetAt, "Meet", 0, NextAction
  266. CALL ADD_ACTIVITY CallBackOn, CallBackAt, "Call", 0, ""
  267. CALL ADD_ACTIVITY SaleDate, "", "Forecast Sale", 0, ""
  268.  
  269. /* GoldMine for Windows doesn't have an account number field */
  270. IF useAccountNum = 1 & AccountNum \= "" & AccountNum \= "WINDOWS" THEN
  271.     Result=SetField(idFieldNum, AccountNum, "String", "cur");
  272.  
  273. /* the Goldmine fields that have no correlation to fields in OmniFile are read into the Notes section so the data is not lost */
  274. notes = ""
  275. IF Asst \= "" THEN notes = notes || "Assistant: " || Asst || 'A'x
  276. IF Source \= "" THEN notes = notes || "Source: " || Source || 'A'x
  277. IF PrevResult \= "" THEN notes = notes || "Previous result: " || PrevResult || 'A'x
  278. IF useStatus = 1 & Status \= "" THEN notes = notes || "Status: " || Status || 'A'x
  279. IF useCreateOwner = 1 THEN DO
  280.     IF CreateBy \= "" THEN notes = notes || "Created by: " || CreateBy || 'A'x
  281.     IF Owner \= "" THEN notes = notes || "Owner: " || Owner || 'A'x
  282.     END
  283. IF useLastInfo = 1 THEN DO
  284.     notes = notes || "Last touched on " || LastDate || " "|| LastTime || "m by "|| LastUser || 'A'x
  285.     END
  286. IF Comments \= "" THEN notes = notes || Comments || 'A'x
  287. IF u1 \= "" THEN notes = notes || "User field1: " || u1 || 'A'x
  288. IF u2 \= "" THEN notes = notes || "User field2: " || u2 || 'A'x
  289. IF u3 \= "" THEN notes = notes || "User field3: " || u3 || 'A'x
  290. IF u4 \= "" THEN notes = notes || "User field4: " || u4 || 'A'x
  291. IF u5 \= "" THEN notes = notes || "User field5: " || u5 || 'A'x
  292. IF u6 \= "" THEN notes = notes || "User field6: " || u6 || 'A'x
  293. IF u7 \= "" THEN notes = notes || "User field7: " || u7 || 'A'x
  294. IF u8 \= "" THEN notes = notes || "User field8: " || u8 || 'A'x
  295. IF u9 \= "" THEN notes = notes || "User field9: " || u9 || 'A'x
  296. IF u10 \= "" THEN notes = notes || "User field10: " || u10 || 'A'x
  297. IF NoteString \= "" THEN notes = notes || NoteString
  298. notes=STRIP(notes, 'T', 'A'x)
  299. IF notes \= "" THEN Result=SetField(notesFieldNum, notes, "String", "cur");
  300. RETURN
  301.  
  302.  
  303. /* SUBROUTINE */
  304. CONVERT_DATE:
  305. dateString = ARG(1)
  306. IF dateString = "" THEN RETURN dateString
  307. /* if date already has slashes then leave it */
  308. PARSE VAR dateString a "/" .
  309. IF dateString = a THEN DO
  310.     PARSE VAR dateString unused 3 year +2 month +2 day
  311.     dateString=month || '/' || day || '/' || year
  312.     END
  313. RETURN dateString
  314.  
  315.  
  316. /* SUBROUTINE */
  317. ADD_PHONE:
  318. /* Add in phones if they're not blank; the EXT field of Goldmine can also be used for type */
  319. PhoneNumber=ARG(1)
  320. PhoneExt=ARG(2)
  321. PhoneType=ARG(3)
  322. IF PhoneExt \= "" THEN DO
  323.     IF PhoneExt="Car" | PhoneExt="CAR" THEN PhoneType = 4
  324.     ELSE IF PhoneExt="Fax" | PhoneExt="FAX" THEN PhoneType = 6
  325.     ELSE IF PhoneExt="Home" | PhoneExt="HOME" THEN PhoneType = 1
  326.     ELSE IF PhoneExt="Office" | PhoneExt="OFFICE" THEN PhoneType = 2
  327.     ELSE IF PhoneExt="Work" | PhoneExt="WORK" THEN PhoneType = 2
  328.     ELSE IF PhoneExt="Beeper" | PhoneExt="BEEPER" THEN PhoneType = 5
  329.     ELSE PhoneNumber = PhoneNumber||" Ext: "||PhoneExt
  330.     END
  331. IF PhoneNumber \= "" & PhoneNumber \= "(   )   -" THEN DO
  332.     subRec=GetSubRec(phoneFieldNum, 0, "cur")
  333.     Result=SetField(phoneTypeFieldNum, PhoneType, "Int", "SubRec")
  334.     Result=SetField(phonePhoneFieldNum, PhoneNumber, "String", "SubRec")
  335.     Result=AddRec(subRec, 0, "SubRec")
  336.     END
  337. RETURN
  338.  
  339.  
  340. /* SUBROUTINE */
  341. ADD_CODE:
  342. Key=ARG(1)
  343. IF Key \= "" & Key \= "N/A" THEN DO
  344.     subRec=GetSubRec(codeFieldNum, 0, "cur")
  345.     CodeRecNum=ConvertStringToDefineableComboBox(Key, codeTypeType, 1)
  346.     Result=SetField(codeTypeField, CodeRecNum, "Int", "SubRec")
  347.     Result=AddRec(subRec, 0, "SubRec")
  348.     END
  349. RETURN
  350.  
  351.  
  352. /* SUBROUTINE */
  353. ADD_ACTIVITY:
  354. actDate=ARG(1)
  355. actTime=ARG(2)
  356. actType=ARG(3)
  357. actCompleted=ARG(4)
  358. actSummary=ARG(5)
  359. IF actDate = "" & actTime = "" THEN RETURN
  360. ActionRec=GetRec(0, actionType, "Temp")
  361. ActionTypeRecNum=ConvertStringToDefineableComboBox(actType, actionTypeType, 1)
  362. Result=SetField(actionTypeField, ActionTypeRecNum, "Int", "Temp")
  363. Result=SetField(actionCompletedField, actCompleted, "Int", "Temp")
  364. Result=SetField(actionDateField, actDate, "Date", "Temp")
  365. Result=SetField(actionTimeField, actTime, "Time", "Temp")
  366. Result=SetField(actionSummaryField, actSummary, "String", "Temp")
  367. Result=SetField(actionFreqField, 1, "Int", "Temp")
  368. NewRecNum=AddRec(ActionRec, 0, "Temp")
  369. Result=AddLink(NewRecNum)
  370. RETURN
  371.  
  372.