1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
6 Purpose
: Import a file of contacts exported from Schedule
+
7 Author
(s
) : Andrew McMillan
8 Notes
: Run from import.p
9 ------------------------------------------------------------------------*/
10 DEF INPUT PARAMETER file_name
AS CHAR NO-UNDO.
11 DEF VAR messages
AS CHAR FORMAT '
X(60)'
LABEL 'Messages'
NO-UNDO.
13 DEFINE FRAME default-frame
15 WITH DOWN FONT 8 SCROLL 16 SIZE 107 BY 200 SCROLLABLE
18 /* DEFINE VAR last_note_code_found
LIKE Note.NoteCode
INITIAL 0 NO-UNDO.
*/
19 DEFINE VAR bad_eol
AS CHARACTER NO-UNDO.
20 bad_eol
= "\" + CHR(10) + "\" + CHR(10).
22 DEF VAR f
AS CHAR FORMAT "X(512)" EXTENT 3 NO-UNDO.
23 DEF VAR new_person_code
LIKE Person.PersonCode
NO-UNDO.
24 DEF VAR last_modified_date
AS DATE NO-UNDO.
25 DEF VAR note_code
LIKE Note.NoteCode
NO-UNDO.
27 DEF VAR vlastmodified
AS CHARACTER NO-UNDO.
28 DEF VAR vcreatorname
AS CHARACTER NO-UNDO.
30 DEF VAR vfirstname
AS CHARACTER NO-UNDO.
31 DEF VAR vlastname
AS CHARACTER NO-UNDO.
33 DEF VAR vcompany
AS CHARACTER NO-UNDO.
34 DEF VAR vjobtitle
AS CHARACTER NO-UNDO.
35 DEF VAR vdepartment
AS CHARACTER NO-UNDO.
36 DEF VAR voffice
AS CHARACTER NO-UNDO.
38 DEF VAR vphonebusiness
AS CHARACTER NO-UNDO.
39 DEF VAR vphonebusiness2
AS CHARACTER NO-UNDO.
40 DEF VAR vphonefax
AS CHARACTER NO-UNDO.
41 DEF VAR vphonehome
AS CHARACTER NO-UNDO.
42 DEF VAR vphonehome2
AS CHARACTER NO-UNDO.
43 DEF VAR vphonemobile
AS CHARACTER NO-UNDO.
45 DEF VAR vaddresshome
AS CHARACTER NO-UNDO.
46 DEF VAR vcityhome
AS CHARACTER NO-UNDO.
47 DEF VAR vstatehome
AS CHARACTER NO-UNDO.
48 DEF VAR vcountryhome
AS CHARACTER NO-UNDO.
49 DEF VAR vzipcodehome
AS CHARACTER NO-UNDO.
51 DEF VAR vaddressbusiness
AS CHARACTER NO-UNDO.
52 DEF VAR vcitybusiness
AS CHARACTER NO-UNDO.
53 DEF VAR vstatebusiness
AS CHARACTER NO-UNDO.
54 DEF VAR vcountrybusiness
AS CHARACTER NO-UNDO.
55 DEF VAR vzipcodebusiness
AS CHARACTER NO-UNDO.
57 DEF VAR vcontacttype
AS CHARACTER EXTENT 5 NO-UNDO.
58 DEF VAR vnotes
AS CHARACTER NO-UNDO.
59 DEF VAR vspouse
AS CHARACTER NO-UNDO.
61 DEF VAR vscheduleplusid
AS CHARACTER NO-UNDO.
63 DEF VAR import-results
AS WIDGET-HANDLE NO-UNDO.
64 CREATE WINDOW import-results
65 ASSIGN WIDTH-CHARS = 81
69 /* _UIB-CODE-BLOCK-END
*/
73 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
75 /* ******************** Preprocessor Definitions
******************** */
77 &Scoped-define PROCEDURE-TYPE Procedure
81 /* _UIB-PREPROCESSOR-BLOCK-END
*/
86 /* *********************** Procedure Settings
************************ */
88 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
89 /* Settings for
THIS-PROCEDURE
93 Add Fields to
: Neither
94 Other Settings
: CODE-ONLY
COMPILE
96 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
98 /* ************************* Create Window
************************** */
100 &ANALYZE-SUSPEND _CREATE-WINDOW
101 /* DESIGN Window definition
(used by the UIB
)
102 CREATE WINDOW Procedure
ASSIGN
105 /* END WINDOW DEFINITION
*/
112 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
115 /* *************************** Main Block
*************************** */
116 ON CREATE OF Person
OVERRIDE DO:
119 ON CREATE OF Contact
OVERRIDE DO:
122 VIEW FRAME default-frame
IN WINDOW import-results.
123 DISPLAY file_name
WITH FRAME default-frame.
125 INPUT FROM VALUE(file_name
).
127 DISPLAY "Importing Master Contact List..." @ messages
WITH FRAME default-frame.
128 DOWN WITH FRAME default-frame.
132 DO WHILE f
[1] <> "Contacts:":
137 DO WHILE f
[1] <> "~{" :
142 vlastmodified
= ? vcreatorname
= ?
143 vfirstname
= ? vlastname
= ?
144 vcompany
= ? vjobtitle
= ? vdepartment
= ? voffice
= ?
145 vphonebusiness
= ? vphonebusiness2
= ? vphonefax
= ?
146 vphonehome
= ? vphonehome2
= ? vphonemobile
= ?
147 vaddresshome
= ? vcityhome
= ? vstatehome
= ?
148 vcountryhome
= ? vzipcodehome
= ?
149 vaddressbusiness
= ? vcitybusiness
= ? vstatebusiness
= ?
150 vcountrybusiness
= ? vzipcodebusiness
= ?
151 vnotes
= ? vspouse
= ?
152 vcontacttype
[1] = ? vcontacttype
[2] = ? vcontacttype
[3] = ?
153 vcontacttype
[4] = ? vcontacttype
[5] = ?
158 DO WHILE f
[1] <> "~}":
161 WHEN "FirstName:" THEN vfirstname
= f
[2].
162 WHEN "LastName:" THEN vlastname
= f
[2].
164 WHEN "Company:" THEN vcompany
= f
[2].
165 WHEN "JobTitle:" THEN vjobtitle
= f
[2].
166 WHEN "Office:" THEN voffice
= f
[2].
167 WHEN "Department:" THEN vdepartment
= f
[2].
169 WHEN "LastModified:" THEN vlastmodified
= f
[2].
170 WHEN "CreatorName:" THEN vcreatorname
= f
[2].
172 WHEN "PhoneBusiness:" THEN vphonebusiness
= f
[2].
173 WHEN "PhoneBusiness2:" THEN vphonebusiness2
= f
[2].
174 WHEN "PhoneFax:" THEN vphonefax
= f
[2].
175 WHEN "PhoneMobile:" THEN vphonemobile
= f
[2].
176 WHEN "PhoneHome:" THEN vphonehome
= f
[2].
177 WHEN "PhoneHome2:" THEN vphonehome2
= f
[2].
179 WHEN "AddressBusiness:" THEN vaddressbusiness
= f
[2].
180 WHEN "CityBusiness:" THEN vcitybusiness
= f
[2].
181 WHEN "StateBusiness:" THEN vstatebusiness
= f
[2].
182 WHEN "CountryBusiness:" THEN vcountrybusiness
= f
[2].
183 WHEN "ZipCodeBusiness:" THEN vzipcodebusiness
= f
[2].
185 WHEN "AddressHome:" THEN vaddresshome
= f
[2].
186 WHEN "CityHome:" THEN vcityhome
= f
[2].
187 WHEN "StateHome:" THEN vstatehome
= f
[2].
188 WHEN "CountryHome:" THEN vcountryhome
= f
[2].
189 WHEN "ZipCodeHome:" THEN vzipcodehome
= f
[2].
191 WHEN "Spouse:" THEN vspouse
= f
[2].
192 WHEN "Notes:" THEN vnotes
= f
[2].
194 WHEN "User1:" THEN vcontacttype
[1] = f
[2].
195 WHEN "User2:" THEN vcontacttype
[2] = f
[2].
196 WHEN "User3:" THEN vcontacttype
[3] = f
[2].
197 WHEN "User4:" THEN vcontacttype
[4] = f
[2].
198 WHEN "User5:" THEN vcontacttype
[5] = f
[2].
200 WHEN "ItemID:" THEN vscheduleplusid
= f
[2].
202 /* Do nothing in these cases
*/
203 WHEN "Created:" THEN .
204 WHEN "CurrentCardViewHomePhone1:" THEN .
205 WHEN "CurrentCardViewBusinessPhone1:" THEN .
206 WHEN "CurrentCardViewHomeAddress:" THEN .
207 WHEN "CurrentBusinessPhone1:" THEN .
208 WHEN "CurrentPhone1:" THEN .
209 WHEN "ExportToWatchPhones:" THEN .
210 WHEN "CreatorEntryID:" THEN .
211 WHEN "CreatorSearchKey:" THEN .
214 DISPLAY (f
[1] + " ignored") @ messages
WITH FRAME default-frame.
215 DOWN WITH FRAME default-frame.
221 FIND Person
WHERE Person.SchedulePlusID
= vscheduleplusid
EXCLUSIVE-LOCK NO-ERROR.
222 IF NOT AVAILABLE(Person
) THEN DO:
223 FIND Person
WHERE Person.LastName
= vlastname
224 AND Person.FirstName
= vfirstname
225 AND Person.Company
= vcompany
226 EXCLUSIVE-LOCK NO-ERROR.
227 IF NOT AVAILABLE(Person
) THEN DO:
228 FIND LAST Person
NO-LOCK NO-ERROR.
229 new_person_code
= IF AVAILABLE(Person
) THEN Person.PersonCode
+ 1 ELSE 1.
232 Person.PersonCode
= new_person_code
233 Person.LastName
= vlastname
234 Person.FirstName
= vfirstname
235 Person.Company
= vcompany
236 Person.SchedulePlusID
= vscheduleplusid
241 RUN convert-date
IN THIS-PROCEDURE ( vlastmodified
, OUTPUT last_modified_date
).
245 RUN set-notes
IN THIS-PROCEDURE ( vnotes
, Person.Notes
, OUTPUT note_code
).
248 Person.CreatorID
= vcreatorname
249 Person.Department
= vdepartment
250 Person.JobTitle
= vjobtitle
251 Person.LastModified
= last_modified_date
252 Person.Office
= voffice
253 Person.Spouse
= vspouse
254 Person.Notes
= note_code
255 Person.SystemContact
= no
256 Person.LastName
= vlastname
257 Person.FirstName
= vfirstname
258 Person.Company
= vcompany
259 Person.SchedulePlusID
= vscheduleplusid
262 IF vphonebusiness
<> ?
THEN
263 RUN set-phone-number
IN THIS-PROCEDURE ( Person.PersonCode
, "BUS", vphonebusiness
).
264 IF vphonebusiness2
<> ?
THEN
265 RUN set-phone-number
IN THIS-PROCEDURE ( Person.PersonCode
, "BUS2", vphonebusiness2
).
266 IF vphonefax
<> ?
THEN
267 RUN set-phone-number
IN THIS-PROCEDURE ( Person.PersonCode
, "FAX", vphonefax
).
268 IF vphonehome
<> ?
THEN
269 RUN set-phone-number
IN THIS-PROCEDURE ( Person.PersonCode
, "HOME", vphonehome
).
270 IF vphonehome2
<> ?
THEN
271 RUN set-phone-number
IN THIS-PROCEDURE ( Person.PersonCode
, "HMFX", vphonehome2
).
272 IF vphonemobile
<> ?
THEN
273 RUN set-phone-number
IN THIS-PROCEDURE ( Person.PersonCode
, "MOB", vphonemobile
).
274 IF vaddresshome
<> ?
THEN
275 IF SUBSTRING(vaddresshome
,1,5) = "Home\" THEN
276 RUN set-address
IN THIS-PROCEDURE ( Person.PersonCode
, "HOME", SUBSTRING(vaddresshome
,9), vcityhome
, vstatehome
, vcountryhome
, vzipcodehome
).
278 RUN set-address
IN THIS-PROCEDURE ( Person.PersonCode
, "COUR", vaddresshome
, vcityhome
, vstatehome
, vcountryhome
, vzipcodehome
).
280 IF vaddressbusiness
<> ?
THEN
281 RUN set-address
IN THIS-PROCEDURE ( Person.PersonCode
, "POST", vaddressbusiness
, vcitybusiness
, vstatebusiness
, vcountrybusiness
, vzipcodebusiness
).
283 IF vcontacttype
[1] <> ?
THEN
284 RUN make-contact
IN THIS-PROCEDURE ( Person.PersonCode
, vcontacttype
[1] ).
285 IF vcontacttype
[2] <> ?
THEN
286 RUN make-contact
IN THIS-PROCEDURE ( Person.PersonCode
, vcontacttype
[2] ).
287 IF vcontacttype
[3] <> ?
THEN
288 RUN make-contact
IN THIS-PROCEDURE ( Person.PersonCode
, vcontacttype
[3] ).
289 IF vcontacttype
[4] <> ?
THEN
290 RUN make-contact
IN THIS-PROCEDURE ( Person.PersonCode
, vcontacttype
[4] ).
291 IF vcontacttype
[5] <> ?
THEN
292 RUN make-contact
IN THIS-PROCEDURE ( Person.PersonCode
, vcontacttype
[5] ).
295 DISPLAY "Import complete." @ messages
WITH FRAME default-frame.
296 DOWN WITH FRAME default-frame.
301 DELETE WIDGET import-results.
303 /* _UIB-CODE-BLOCK-END
*/
307 /* ********************** Internal Procedures
*********************** */
309 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE convert-date Procedure
310 PROCEDURE convert-date
:
311 /*------------------------------------------------------------------------------
313 Parameters
: date-string
(in
), date-value
(out
)
315 ------------------------------------------------------------------------------*/
316 DEFINE INPUT PARAMETER date-string
AS CHARACTER NO-UNDO.
317 DEFINE OUTPUT PARAMETER date-value
AS DATE NO-UNDO.
319 DEF VAR p1
AS INTEGER NO-UNDO INITIAL 0.
320 DEF VAR p2
AS INTEGER NO-UNDO INITIAL 0.
321 DEF VAR mm
AS INTEGER NO-UNDO.
322 DEF VAR dd
AS INTEGER NO-UNDO.
323 DEF VAR yyyy
AS INTEGER NO-UNDO.
325 p1
= INDEX( date-string
, "-").
326 p2
= INDEX( date-string
, "-", p1
+ 1).
328 mm
= INTEGER( SUBSTRING( date-string
, 1, p1
- 1) ).
329 dd
= INTEGER( SUBSTRING( date-string
, p1
+ 1, p2
- p1
- 1) ).
330 yyyy
=INTEGER( SUBSTRING( date-string
, p2
+ 1, 4) ).
332 date-value
= DATE( mm
, dd
, yyyy
).
335 /* _UIB-CODE-BLOCK-END
*/
339 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE make-contact Procedure
340 PROCEDURE make-contact
:
341 /*------------------------------------------------------------------------------
343 Parameters
: person_code
, contact_type
345 ------------------------------------------------------------------------------*/
346 DEFINE INPUT PARAMETER person_code
LIKE Person.PersonCode
NO-UNDO.
347 DEFINE INPUT PARAMETER in_contact_type
LIKE Contact.ContactType
NO-UNDO.
349 DEF VAR contact_type
AS CHARACTER NO-UNDO.
350 DEF VAR temp
AS CHARACTER NO-UNDO.
351 DEF VAR pos
AS INTEGER INITIAL 1 NO-UNDO.
353 /* Handle data-entry problems
*/
354 CASE SUBSTRING( in_contact_type
, 1, 5):
355 WHEN "Trade" THEN temp
= "TR".
356 WHEN "Devel" THEN temp
= "DV".
357 OTHERWISE temp
= in_contact_type.
360 /* Handle multiple codes all entered in one string
*/
361 contact_type
= SUBSTRING( temp
, pos
, 2).
363 /* Note
, < rather than
<= to ensure we only get
2-character codes
*/
364 DO WHILE pos
< LENGTH(temp
) :
366 IF NOT CAN-FIND( Contact
WHERE Contact.ContactType
= contact_type
367 AND Contact.PersonCode
= person_code
) THEN DO:
370 Contact.ContactType
= contact_type
371 Contact.PersonCode
= person_code
375 IF NOT CAN-FIND( ContactType
WHERE ContactType.ContactType
= contact_type
) THEN DO:
378 ContactType.ContactType
= contact_type
379 ContactType.SystemCode
= no
384 contact_type
= SUBSTRING( temp
, pos
, 2).
389 /* _UIB-CODE-BLOCK-END
*/
393 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE set-address Procedure
394 PROCEDURE set-address
:
395 /*------------------------------------------------------------------------------
397 Parameters
: person_code
, address_type
, address
, city
, state
, country
, zipcode
399 ------------------------------------------------------------------------------*/
400 DEFINE INPUT PARAMETER person_code
LIKE Person.PersonCode
NO-UNDO.
401 DEFINE INPUT PARAMETER address_type
LIKE PostalDetail.PostalType
NO-UNDO.
402 DEFINE INPUT PARAMETER address
LIKE PostalDetail.Address
NO-UNDO.
403 DEFINE INPUT PARAMETER city
LIKE PostalDetail.City
NO-UNDO.
404 DEFINE INPUT PARAMETER state
LIKE PostalDetail.State
NO-UNDO.
405 DEFINE INPUT PARAMETER country
LIKE PostalDetail.Country
NO-UNDO.
406 DEFINE INPUT PARAMETER zipcode
LIKE PostalDetail.Zip
NO-UNDO.
408 DEF VAR pos
AS INTEGER NO-UNDO.
410 pos
= INDEX( address
, bad_eol
).
412 address
= SUBSTRING( address
, 1, pos
- 1) + CHR(13) + SUBSTRING( address
, pos
+ 4).
413 pos
= INDEX( address
, bad_eol
).
416 FIND PostalDetail
WHERE PostalDetail.PersonCode
= person_code
417 AND PostalDetail.PostalType
= address_type
418 EXCLUSIVE-LOCK NO-ERROR.
419 IF NOT AVAILABLE(PostalDetail
) THEN CREATE PostalDetail.
421 PostalDetail.PostalType
= address_type
422 PostalDetail.PersonCode
= person_code
423 PostalDetail.Address
= address
424 PostalDetail.City
= city
425 PostalDetail.State
= state
426 PostalDetail.Country
= country
427 PostalDetail.Zip
= zipcode
432 /* _UIB-CODE-BLOCK-END
*/
436 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE set-notes Procedure
437 PROCEDURE set-notes
:
438 /*------------------------------------------------------------------------------
440 Parameters
: notes
, OUTPUT note_code
442 ------------------------------------------------------------------------------*/
443 DEF INPUT PARAMETER note_text
AS CHARACTER NO-UNDO.
444 DEF INPUT PARAMETER old-notecode
AS INTEGER NO-UNDO.
445 DEF OUTPUT PARAMETER note_code
LIKE Note.NoteCode
NO-UNDO.
447 FIND FIRST Note
WHERE Note.NoteCode
= old-notecode
NO-ERROR.
448 IF AVAILABLE(Note
) THEN ASSIGN
449 Note.Detail
= note_text
450 note_code
= Note.NoteCode
453 FIND LAST Note
NO-LOCK NO-ERROR.
454 note_code
= IF AVAILABLE(Note
) THEN Note.NoteCode
+ 1 ELSE 1.
457 Note.NoteCode
= note_code
458 Note.Detail
= note_text
464 /* _UIB-CODE-BLOCK-END
*/
468 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE set-phone-number Procedure
469 PROCEDURE set-phone-number
:
470 /*------------------------------------------------------------------------------
472 Parameters
: person_code
, phone_type
, phone_no
474 ------------------------------------------------------------------------------*/
475 DEFINE INPUT PARAMETER person_code
LIKE Person.PersonCode
NO-UNDO.
476 DEFINE INPUT PARAMETER phone_type
AS CHARACTER FORMAT "X(20)" NO-UNDO.
477 DEFINE INPUT PARAMETER phone_no
LIKE PhoneDetail.Number
NO-UNDO.
479 DEF VAR country
AS INTEGER NO-UNDO.
480 DEF VAR std
AS INTEGER NO-UNDO.
482 ASSIGN country
= ? std
= ?.
483 IF SUBSTRING(phone_no
,1,2) = "DD" THEN DO:
485 phone_no
= TRIM(SUBSTRING(phone_no
,4)).
488 IF phone_type
= "MOB" AND SUBSTRING(phone_no
, 1, 2) = "02" THEN DO:
489 std
= INTEGER( SUBSTRING(phone_no
, 1, 3) ).
490 phone_no
= TRIM( SUBSTRING(phone_no
, 4) ).
493 IF INDEX(phone_no
, " ") = 3 THEN DO:
494 IF SUBSTRING(phone_no
, 1, 1) = "0" THEN
495 std
= INTEGER( SUBSTRING(phone_no
, 1, 2) ).
497 country
= INTEGER( SUBSTRING(phone_no
, 1, 2) ).
499 phone_no
= SUBSTRING(phone_no
, 4).
502 IF INDEX(phone_no
, " ") = 3 THEN DO:
503 std
= INTEGER( SUBSTRING(phone_no
, 1, 2) ).
504 phone_no
= SUBSTRING(phone_no
, 4).
507 IF INDEX(phone_no
, " ") = 2 THEN DO:
508 std
= INTEGER( SUBSTRING(phone_no
, 1, 1) ).
509 phone_no
= SUBSTRING(phone_no
, 3).
513 FIND PhoneDetail
WHERE PhoneDetail.PersonCode
= person_code
514 AND PhoneDetail.PhoneType
= phone_type
515 EXCLUSIVE-LOCK NO-ERROR.
516 IF NOT AVAILABLE(PhoneDetail
) THEN CREATE PhoneDetail.
518 PhoneDetail.PhoneType
= phone_type
519 PhoneDetail.PersonCode
= person_code
520 PhoneDetail.Number
= phone_no
521 PhoneDetail.STDCode
= std
522 PhoneDetail.CountryCode
= country
527 /* _UIB-CODE-BLOCK-END
*/