Link to home
Start Free TrialLog in
Avatar of apollo7
apollo7Flag for United States of America

asked on

CRM 2011 MultiLine Problem

Hi

A developer created custom Ship To addresses and Bill To address and coded the words "Ship To" and "Bill To"
as the first line of the address.

I want to modify the code below to remove this function or add code that strips out the first line of each address.

I have added comments to each line that contains the hard-coded Ship To and Bill To labels ( e.g. ////166: ).


1:[code]// JScript source code
2:/**********************************************************************
3:Procedure Name : [QuoteAddressFunctions.js]
4:*********************************************************************/
5:if (typeof (Crm2011) == "undefined") {
6:    Crm2011 = { __namespace: true };
7:}
8:Crm2011.QuoteAddressFunctions = {
9:    OUID: null,
10:
11:    //--------------------------------------------------------------------------------------------------------------------------
12:    // Crm2011.QuoteAddressFunctions.process();
13:    //--------------------------------------------------------------------------------------------------------------------------
14:    process: function () {
15:
16:        Crm2011.QuoteAddressFunctions.concatBillToAddress();
17:        Crm2011.QuoteAddressFunctions.concatShipToAddress();
18:        Crm2011.QuoteAddressFunctions.getDefaultOUQuoteResponseAddress();
19:        Crm2011.QuoteAddressFunctions.concatResponseAddress();
20:        Crm2011.QuoteAddressFunctions.concatEndUserAddress();
21:        Crm2011.QuoteAddressFunctions.concatRecipientDetails();
22:        Crm2011.QuoteAddressFunctions.getAndSetOperatingUnit();
23:    },
24:
25:    //--------------------------------------------------------------------------------------------------------------------------
26:    // Crm2011.QuoteAddressFunctions.getAndSetOperatingUnit();
27:    //--------------------------------------------------------------------------------------------------------------------------
28:    getAndSetOperatingUnit: function () {
29:        if (Crm2011.QuoteAddressFunctions.OUID != null) {
30:            return Crm2011.QuoteAddressFunctions.OUID;
31:        }
32:        var ou = Crm2011.UtilFunctions.getAndSetOperatingUnit();
33:        if (ou == null) {
34:            return null;
35:        }
36:        Crm2011.QuoteAddressFunctions.OUID = ou[0];
37:    },
38:
39:    //--------------------------------------------------------------------------------------------------------------------------
40:    // Crm2011.QuoteAddressFunctions.getAndSetOperatingUnitInfo();
41:    //--------------------------------------------------------------------------------------------------------------------------
42:    getAndSetOperatingUnitInfo: function () {
43:        if (Crm2011.QuoteAddressFunctions.OUID == null) {
44:            return null;
45:        }
46:        var sw = false, buffer = "", UK = false, USA = false, FRANCE = false;
47:        /*Xrm.Page.getAttribute("csc_legalcompanyname").setValue(null);
48:        Xrm.Page.getAttribute("csc_companytradingname").setValue(null);
49:        Xrm.Page.getAttribute("csc_ou_quotetemplateaddress").setValue(null);
50:        Xrm.Page.getAttribute("csc_registrationnumberlable").setValue(null);
51:        Xrm.Page.getAttribute("csc_companyquotetemplatelable").setValue(null);
52:        Xrm.Page.getAttribute("csc_companyregisteredaddress").setValue(null);
53:        Xrm.Page.getAttribute("csc_ou_website").setValue(null);*/
54:
55:        var OperatingUnitAddress = Crm2011.OUFunctions.getOperatingUnitAddress(Crm2011.QuoteAddressFunctions.OUID);
56:        if (OperatingUnitAddress == null) {
57:            return null;
58:        }
59:
60:        if (OperatingUnitAddress.website != null) {
61:            Crm2011.UtilFunctions.fillField("csc_ou_website", OperatingUnitAddress.website);
62:        }
63:
64:        if (OperatingUnitAddress.registeredincountry.name != null) {
65:            if (OperatingUnitAddress.registeredincountry.name == "United Kingdom") {
66:                UK = true;
67:            }
68:            else if (OperatingUnitAddress.registeredincountry.name == "United States") {
69:                USA = true;
70:            }
71:            else if (OperatingUnitAddress.registeredincountry.name == "France") {
72:                alert("France is not yet implemented!");
73:                FRANCE = true;
74:            }
75:        }
76:
77:        var legalcompanyname = "";
78:        if (OperatingUnitAddress.legalcompanyname != null) {
79:            legalcompanyname = OperatingUnitAddress.legalcompanyname;
80:        }
81:        Crm2011.UtilFunctions.fillField("csc_legalcompanyname", legalcompanyname);
82:
83:        var companytradingname = "";
84:        if (OperatingUnitAddress.companytradingname != null) {
85:            companytradingname = OperatingUnitAddress.companytradingname;
86:        }
87:        Crm2011.UtilFunctions.fillField("csc_companytradingname", companytradingname);
88:
89:        var website = "";
90:        if (OperatingUnitAddress.website != null) {
91:            website = OperatingUnitAddress.website;
92:        }
93:        Crm2011.UtilFunctions.fillField("csc_ou_website", website);
94:
95:        //----------------------------------------------------------------------------------------------//
96:        // <Legal Company Name> [trading as(UK)][doing business as(USA)] <Company Trading Name>
97:        var companyquotetemplatelable;
98:        if (UK) {
99:            companyquotetemplatelable = legalcompanyname + " trading as " + companytradingname;
100:        }
101:        else if (USA) {
102:            companyquotetemplatelable = legalcompanyname + " doing business as " + companytradingname;
103:        }
104:        else if (FRANCE) {
105:            // TODO: France
106:            alert("France is not yet implemented!");
107:        }
108:        Crm2011.UtilFunctions.fillField("csc_companyquotetemplatelable", companyquotetemplatelable);
109:
110:        //----------------------------------------------------------------------------------------------//
111:        // [Registration Number(UK)][Incorporated Number(USA)]: Company Registration Number
112:        var registrationnumberlable, registrationnumber;
113:        if (OperatingUnitAddress.registrationnumber != null) {
114:            registrationnumber = OperatingUnitAddress.registrationnumber;
115:        }
116:        if (UK) {
117:            registrationnumberlable = "Registration Number: " + registrationnumber;
118:        }
119:        else if (USA) {
120:            registrationnumberlable = "Incorporated Number: " + registrationnumber;
121:        }
122:        else if (FRANCE) {
123:            // TODO: France
124:            alert("France is not yet implemented!");
125:        }
126:        Crm2011.UtilFunctions.fillField("csc_registrationnumberlable", registrationnumberlable);
127:
128:        //----------------------------------------------------------------------------------------------//
129:        // [Registered Office(UK)][Incorporated State(USA): Company Registered Address
130:        var companyregisteredaddressBuffer, companyregisteredaddress;
131:        if (OperatingUnitAddress.companyregisteredaddress != null) {
132:            companyregisteredaddress = OperatingUnitAddress.companyregisteredaddress;
133:        }
134:        if (UK) {
135:            companyregisteredaddressBuffer = "Registered Office: " + companyregisteredaddress;
136:        }
137:        else if (USA) {
138:            companyregisteredaddressBuffer = "Incorporated State: " + companyregisteredaddress;
139:        }
140:        else if (FRANCE) {
141:            // TODO: France
142:            alert("France is not yet implemented!");
143:        }
144:        Crm2011.UtilFunctions.fillField("csc_companyregisteredaddress", companyregisteredaddressBuffer);
145:
146:        //----------------------------------------------------------------------------------------------//
147:
148:        if (OperatingUnitAddress.quotetemplateaddress != null) {
149:            Crm2011.UtilFunctions.fillField("csc_ou_quotetemplateaddress", OperatingUnitAddress.quotetemplateaddress);
150:        }
151:    },
152:
153:    //--------------------------------------------------------------------------------------------------------------------------
154:    // Crm2011.QuoteAddressFunctions.concatBillToAddress();
155:    // Customer Address + Bill To Address
156:    //--------------------------------------------------------------------------------------------------------------------------
157:    concatBillToAddress: function () {
158:
159:        var sw = Crm2011.UtilFunctions.doesFieldExistNoAlert("csc_billto_quotetemplateaddress");
160:        if (sw == false) {
161:            return;
162:        }
163:
164:        Crm2011.UtilFunctions.setFieldNull("csc_billto_quotetemplateaddress");
165:
////166:        var buffer = "Bill To:" + "\n";
167:
168:        var contactname = Xrm.Page.getAttribute("billto_contactname").getValue();
169:        if (contactname != null) {
170:            buffer = buffer + contactname;
171:        }
172:
173:        var line1 = Xrm.Page.getAttribute("billto_line1").getValue();
174:        if (line1 != null) {
175:            if (contactname != null) {
176:                buffer = buffer + "," + "\n" + line1;
177:            }
178:            else {
179:                buffer = buffer + line1;
180:            }
181:
182:        }
183:
184:        var line2 = Xrm.Page.getAttribute("billto_line2").getValue();
185:        if (line2 != null) {
186:            if ((line1 != null) || (contactname != null)) {
187:                buffer = buffer + "," + "\n" + line2;
188:            }
189:            else {
190:                buffer = buffer + line2;
191:            }
192:        }
193:
194:        var line3 = Xrm.Page.getAttribute("billto_line3").getValue();
195:        if (line3 != null) {
196:            if ((line2 != null) || (line1 != null) || (contactname != null)) {
197:                buffer = buffer + "," + "\n" + line3;
198:            }
199:            else {
200:                buffer = buffer + line3;
201:            }
202:        }
203:
204:        var city = Xrm.Page.getAttribute("billto_city").getValue();
205:        var stateorprovince = Xrm.Page.getAttribute("billto_stateorprovince").getValue();
206:        buffer = Crm2011.QuoteAddressFunctions.concatCityStateOrProvince(buffer, city, stateorprovince);
207:
208:        var postalcode = Xrm.Page.getAttribute("billto_postalcode").getValue();
209:        var country = Xrm.Page.getAttribute("billto_country").getValue();
210:        buffer = Crm2011.QuoteAddressFunctions.concatPostalCodeAndCountry(buffer, postalcode, country);
211:        buffer = Crm2011.UtilFunctions.trim(buffer);
212:
////213:        if (buffer == "Bill To:\n") {
214:            buffer = null;
215:        }
216:
217:        Crm2011.UtilFunctions.fillField("csc_billto_quotetemplateaddress", buffer);
218:    },
219:
220:    //--------------------------------------------------------------------------------------------------------------------------
221:    // Crm2011.QuoteAddressFunctions.concatShipToAddress();
222:    // Address must be on Quote/Order
223:    //--------------------------------------------------------------------------------------------------------------------------
224:    concatShipToAddress: function () {
225:
226:        var sw = Crm2011.UtilFunctions.doesFieldExistNoAlert("csc_shipto_quotetemplateaddress");
227:        if (sw == false) {
228:            return;
229:        }
230:
231:        Crm2011.UtilFunctions.setFieldNull("csc_shipto_quotetemplateaddress");
232:
////233:        var buffer = "ship to:" + "\n";
234:
235:        var contactname = Xrm.Page.getAttribute("shipto_contactname").getValue();
236:        if (contactname != null) {
237:            buffer = buffer + contactname;
238:        }
239:
240:        var line1 = Xrm.Page.getAttribute("shipto_line1").getValue();
241:        if (line1 != null) {
242:            if (contactname != null) {
243:                buffer = buffer + "," + "\n" + line1;
244:            }
245:            else {
246:                buffer = buffer + line1;
247:            }
248:
249:        }
250:
251:        var line2 = Xrm.Page.getAttribute("shipto_line2").getValue();
252:        if (line2 != null) {
253:            if ((line1 != null) || (contactname != null)) {
254:                buffer = buffer + "," + "\n" + line2;
255:            }
256:            else {
257:                buffer = buffer + line2;
258:            }
259:        }
260:
261:        var line3 = Xrm.Page.getAttribute("shipto_line3").getValue();
262:        if (line3 != null) {
263:            if ((line2 != null) || (line1 != null) || (contactname != null)) {
264:                buffer = buffer + "," + "\n" + line3;
265:            }
266:            else {
267:                buffer = buffer + line3;
268:            }
269:        }
270:
271:        var city = Xrm.Page.getAttribute("shipto_city").getValue();
272:        var stateorprovince = Xrm.Page.getAttribute("shipto_stateorprovince").getValue();
273:        buffer = Crm2011.QuoteAddressFunctions.concatCityStateOrProvince(buffer, city, stateorprovince);
274:
275:        var postalcode = Xrm.Page.getAttribute("shipto_postalcode").getValue();
276:        var country = Xrm.Page.getAttribute("shipto_country").getValue();
277:        buffer = Crm2011.QuoteAddressFunctions.concatPostalCodeAndCountry(buffer, postalcode, country);
278:
279:        buffer = Crm2011.UtilFunctions.trim(buffer);
280:
////281:        if (buffer == "Ship To:\n") {
282:            buffer = null;
283:        }
284:
285:        Crm2011.UtilFunctions.fillField("csc_shipto_quotetemplateaddress", buffer);
286:    },
287:
288:    //--------------------------------------------------------------------------------------------------------------------------
289:    // Crm2011.QuoteAddressFunctions.concatResponseAddress();
290:    //--------------------------------------------------------------------------------------------------------------------------
291:    concatResponseAddress: function () {
292:
293:        var entityName = Xrm.Page.data.entity.getEntityName();
294:        if (entityName != "quote") {
295:            return;
296:        }
297:
298:        var responseAddressCols = ["csc_response_quotetemplateaddress", "csc_response_name", "csc_response_contactname", "",
299:"csc_response_line1", "csc_response_line2", "csc_response_line3", "csc_response_city",
300:"csc_response_stateorprovince", "csc_response_postalcode", "csc_response_country", "csc_response_telephone",
301:"csc_response_fax", "csc_response_email"]
302:
303:        var sw = Crm2011.UtilFunctions.doesFieldExistNoAlert("csc_response_quotetemplateaddress");
304:        if (sw == false) {
305:            return;
306:        }
307:        // Set the Address Name
308:        var name = Xrm.Page.getAttribute("csc_response_name").getValue();
309:        if (name == null) {
310:            name = "Response Address";
311:            Crm2011.UtilFunctions.fillField("csc_response_name", name);
312:        }
313:
314:        var buffer = "Response Address:" + "\n";
315:
316:        var contactname = Xrm.Page.getAttribute("csc_response_contactname").getValue();
317:        if (contactname != null) {
318:            buffer = buffer + contactname;
319:        }
320:
321:        var line1 = Xrm.Page.getAttribute("csc_response_line1").getValue();
322:        if (line1 != null) {
323:            if (contactname != null) {
324:                buffer = buffer + "," + "\n" + line1;
325:            }
326:            else {
327:                buffer = buffer + line1;
328:            }
329:        }
330:
331:        var line2 = Xrm.Page.getAttribute("csc_response_line2").getValue();
332:        if (line2 != null) {
333:            if ((line1 != null) || (contactname != null)) {
334:                buffer = buffer + "," + "\n" + line2;
335:            }
336:            else {
337:                buffer = buffer + line2;
338:            }
339:        }
340:
341:        var line3 = Xrm.Page.getAttribute("csc_response_line3").getValue();
342:        if (line3 != null) {
343:            if ((line2 != null) || (line1 != null) || (contactname != null)) {
344:                buffer = buffer + "," + "\n" + line3;
345:            }
346:            else {
347:                buffer = buffer + line3;
348:            }
349:        }
350:
351:        var city = Xrm.Page.getAttribute("csc_response_city").getValue();
352:        var stateorprovince = Xrm.Page.getAttribute("csc_response_stateorprovince").getValue();
353:        buffer = Crm2011.QuoteAddressFunctions.concatCityStateOrProvince(buffer, city, stateorprovince);
354:
355:        var postalcode = Xrm.Page.getAttribute("csc_response_postalcode").getValue();
356:        var country = Xrm.Page.getAttribute("csc_response_country").getValue();
357:        buffer = Crm2011.QuoteAddressFunctions.concatPostalCodeAndCountry(buffer, postalcode, country);
358:
359:        var telephone = Xrm.Page.getAttribute("csc_response_telephone").getValue();
360:        if (telephone != null) {
361:            if (buffer != "Response Address:\n") {
362:                buffer = buffer + "\n" + "Phone: " + telephone;
363:            }
364:            else {
365:                buffer = buffer + "Phone: " + fax;
366:            }
367:        }
368:
369:        var fax = Xrm.Page.getAttribute("csc_response_fax").getValue();
370:        if (fax != null) {
371:            if (buffer != "Response Address:\n") {
372:                buffer = buffer + "\n" + "Fax: " + fax;
373:            }
374:            else {
375:                buffer = buffer + "Fax: " + fax;
376:            }
377:        }
378:
379:        // response_email
380:        var email = Xrm.Page.getAttribute("csc_response_email").getValue();
381:        if (email != null) {
382:            if (buffer != "Response Address:\n") {
383:                buffer = buffer + "\n" + "Email: " + email;
384:            }
385:            else {
386:                buffer = buffer + "Email: " + email;
387:            }
388:        }
389:
390:        buffer = Crm2011.UtilFunctions.trim(buffer);
391:        if (buffer == "Response Address:\n") {
392:            buffer = null;
393:        }
394:
395:        var existingResponseQuoteTemplateAddress = Xrm.Page.getAttribute("csc_response_quotetemplateaddress").getValue();
396:
397:        if (buffer != existingResponseQuoteTemplateAddress) {
398:            Crm2011.UtilFunctions.setFieldNull("csc_response_quotetemplateaddress");
399:            Crm2011.UtilFunctions.fillField("csc_response_quotetemplateaddress", buffer);
400:        }
401:    },
402:
403:    //--------------------------------------------------------------------------------------------------------------------------
404:    // Crm2011.QuoteAddressFunctions.concatEndUserAddress();
405:    //--------------------------------------------------------------------------------------------------------------------------
406:    concatEndUserAddress: function () {
407:
408:        var sw = Crm2011.UtilFunctions.doesFieldExistNoAlert("csc_enduser_quotetemplateaddress");
409:        if (sw == false) {
410:            return;
411:        }
412:
413:        var existingEndUserQuoteTemplateAddress = Xrm.Page.getAttribute("csc_enduser_quotetemplateaddress").getValue();
414:
415:        var sw = Crm2011.UtilFunctions.lookupIsNull("csc_endusercustomer");
416:        if (sw) {
417:            if (existingEndUserQuoteTemplateAddress != null) {
418:                Crm2011.UtilFunctions.setFieldNull("csc_enduser_quotetemplateaddress");
419:            }
420:            return;
421:        }
422:
423:        var usercustomererid = Crm2011.UtilFunctions.getLookupId("csc_endusercustomer");
424:        var accountBillToAddressData = Crm2011.QuoteAddressFunctions.getAccountBillToAddress(usercustomererid);
425:        if (accountBillToAddressData == null) {
426:            Crm2011.UtilFunctions.setFieldNull("csc_enduser_quotetemplateaddress");
427:            return;
428:        }
429:
430:        var buffer = "End User:" + "\n";
431:
432:        // <End User>
433:        var customername = Crm2011.UtilFunctions.getLookupName("csc_endusercustomer");
434:        if (customername != null) {
435:            buffer = buffer + customername;
436:        }
437:
438:        var contactname = accountBillToAddressData.primarycontactname;
439:        if (contactname != null) {
440:            if (customername != null) {
441:                buffer = buffer + "," + "\n" + contactname;
442:            }
443:            else {
444:                buffer = buffer + contactname;
445:            }
446:        }
447:
448:        var line1 = accountBillToAddressData.line1;
449:        if (line1 != null) {
450:            if ((contactname != null) || (customername != null)) {
451:                buffer = buffer + "," + "\n" + line1;
452:            }
453:            else {
454:                buffer = buffer + line1;
455:            }
456:        }
457:
458:        var line2 = accountBillToAddressData.line2;
459:        if (line2 != null) {
460:            if ((contactname != null) || (customername != null) || (line1 != null)) {
461:                buffer = buffer + "," + "\n" + line2;
462:            }
463:            else {
464:                buffer = buffer + line2;
465:            }
466:        }
467:
468:        var line3 = accountBillToAddressData.line3;
469:        if (line3 != null) {
470:            if ((contactname != null) || (customername != null) || (line1 != null) || (line2 != null)) {
471:                buffer = buffer + "," + "\n" + line3;
472:            }
473:            else {
474:                buffer = buffer + line3;
475:            }
476:        }
477:
478:        var city = accountBillToAddressData.city;
479:        var stateorprovince = accountBillToAddressData.stateorprovince;
480:        buffer = Crm2011.QuoteAddressFunctions.concatCityStateOrProvince(buffer, city, stateorprovince);
481:
482:        var postalcode = accountBillToAddressData.postalcode;
483:        var country = accountBillToAddressData.country;
484:        buffer = Crm2011.QuoteAddressFunctions.concatPostalCodeAndCountry(buffer, postalcode, country);
485:
486:        var telephone = accountBillToAddressData.telephone1;
487:        if (telephone != null) {
488:            if (buffer != "End User:\n") {
489:                buffer = buffer + "\n" + "Phone: " + telephone;
490:            }
491:            else {
492:                buffer = buffer + "Phone: " + telephone;
493:            }
494:        }
495:
496:        var fax = accountBillToAddressData.fax;
497:        if (fax != null) {
498:            if (buffer != "End User:\n") {
499:                buffer = buffer + "\n" + "Fax: " + fax;
500:            }
501:            else {
502:                buffer = buffer + "Fax: " + fax;
503:            }
504:        }
505:
506:        buffer = Crm2011.UtilFunctions.trim(buffer);
507:
508:        if (buffer == "End User:\n") {
509:            buffer = null;
510:        }
511:        if (buffer != existingEndUserQuoteTemplateAddress) {
512:            Crm2011.UtilFunctions.setFieldNull("csc_enduser_quotetemplateaddress");
513:            Crm2011.UtilFunctions.fillField("csc_enduser_quotetemplateaddress", buffer);
514:        }
515:    },
516:
517:    //--------------------------------------------------------------------------------------------------------------------------
518:    // Crm2011.QuoteAddressFunctions.concatRecipientDetails();
519:    //--------------------------------------------------------------------------------------------------------------------------
520:    concatRecipientDetails: function () {
521:
522:        var entityName = Xrm.Page.data.entity.getEntityName();
523:        if (entityName != "quote") {
524:            return;
525:        }
526:
527:        var sw = Crm2011.UtilFunctions.doesFieldExistNoAlert("csc_recipient_quotetemplate");
528:        if (sw == false) {
529:            return;
530:        }
531:        var buffer = "Recipient:" + "\n";
532:
533:        var existingRecipientQuoteTemplate = Xrm.Page.getAttribute("csc_recipient_quotetemplate").getValue();
534:
535:        var sw = Crm2011.UtilFunctions.lookupIsNull("csc_recipientname");
536:        if (sw) {
537:            if (existingRecipientQuoteTemplate != null) {
538:                Crm2011.UtilFunctions.setFieldNull("csc_recipient_quotetemplate");
539:            }
540:            return;
541:        }
542:
543:        var name = Crm2011.UtilFunctions.getLookupName("csc_recipientname");
544:        if (name != null) {
545:            buffer = buffer + name + "\n";
546:        }
547:
548:        var telephone = Xrm.Page.getAttribute("csc_recipienttelephone").getValue();
549:        if (telephone != null) {
550:            buffer = buffer + "Phone: " + telephone + "\n";
551:        }
552:
553:        var fax = Xrm.Page.getAttribute("csc_recipientfax").getValue();
554:        if (fax != null) {
555:            buffer = buffer + "Fax: " + fax + "\n";
556:        }
557:
558:        var email = Xrm.Page.getAttribute("csc_recipientemail").getValue();
559:        if (email != null) {
560:            buffer = buffer + "Email: " + email + "\n";
561:        }
562:
563:        buffer = Crm2011.UtilFunctions.trim(buffer);
564:
565:        if (buffer == "Recipient:\n") {
566:            buffer = null;
567:        }
568:
569:        if (buffer != existingRecipientQuoteTemplate) {
570:            Crm2011.UtilFunctions.fillField("csc_recipient_quotetemplate", buffer);
571:        }
572:    },
573:
574:
575:    //--------------------------------------------------------------------------------------------------------------------------
576:    // buffer = Crm2011.QuoteAddressFunctions.concatCityStateOrProvince(buffer, city, stateorprovince);
577:    //--------------------------------------------------------------------------------------------------------------------------
578:    concatCityStateOrProvince: function (buffer, city, stateorprovince) {
579:
580:        if (city == "undefined") {
581:            city = null;
582:        }
583:
584:        if (stateorprovince == "undefined") {
585:            stateorprovince = null;
586:        }
587:
588:        if (city == undefined) {
589:            city = null;
590:        }
591:
592:        if (stateorprovince == undefined) {
593:            stateorprovince = null;
594:        }
595:
////596:        if ((buffer != "Bill To:\n") && (buffer != "Ship To:\n") && (buffer != "Response Address:\n") && (buffer != "End User:\n")) {
597:            buffer = buffer + "," + "\n";
598:        }
599:
600:        if ((city != null) && (stateorprovince != null)) {
601:            buffer = buffer + city + ", " + stateorprovince;
602:        }
603:        else if ((city != null) && (stateorprovince == null)) {
604:            buffer = buffer + city;
605:        }
606:        else if ((city == null) && (stateorprovince != null)) {
607:            buffer = buffer + stateorprovince;
608:        }
609:
610:        return buffer;
611:    },
612:
613:
614:    //--------------------------------------------------------------------------------------------------------------------------
615:    // buffer = Crm2011.QuoteAddressFunctions.concatPostalCodeAndCountry(buffer, postalcode, country);
616:    //--------------------------------------------------------------------------------------------------------------------------
617:    concatPostalCodeAndCountry: function (buffer, postalcode, country) {
618:
619:        if ((postalcode == "undefined") || (postalcode == undefined)) {
620:            postalcode = null;
621:        }
622:        if ((country == "undefined") || (country == undefined)) {
623:            country = null;
624:        }
625:
////626:        if ((buffer != "Bill To:\n") && (buffer != "Ship To:\n") && (buffer != "Response Address:\n") && (buffer != "End User:\n")) {
627:            buffer = buffer + "," + "\n";
628:        }
629:
630:        if ((postalcode != null) && (country != null)) {
631:            buffer = buffer + postalcode + ", " + country;
632:        }
633:        else if ((postalcode != null) && (country == null)) {
634:            buffer = buffer + postalcode;
635:        }
636:        else if ((postalcode == null) && (country != null)) {
637:            buffer = buffer + country;
638:        }
639:
640:        return buffer;
641:    },
642:
643:
644:    //--------------------------------------------------------------------------------------------------------------------------
645:    // var populateOK = Crm2011.QuoteAddressFunctions.populateBillToAndShipToAddressesFromCustomer(customerid);
646:    //--------------------------------------------------------------------------------------------------------------------------
647:    populateBillToAndShipToAddressesFromCustomer: function (customerid) {
648:
649:        // var existingRecipientQuoteTemplate = Xrm.Page.getAttribute("csc_recipient_quotetemplate").getValue();
650:
651:        if (customerid == null) {
652:            return;
653:        }
654:
655:        if (Xrm.Page.ui.getFormType() == 4) {
656:            return;
657:        }
658:
659:        var entityName = Xrm.Page.data.entity.getEntityName();
660:        if (entityName != "quote") {
661:            if (entityName != "salesorder") {
662:                return;
663:            }
664:        }
665:
666:        var billToCols = ["billto_name", "billto_line1", "billto_line2", "billto_line3",
667:"billto_city", "billto_contactname", "billto_stateorprovince", "billto_postalcode",
668:"billto_country", "billto_telephone", "billto_fax"];
669:        // Crm2011.UtilFunctions.setFieldsNull(billToCols);
670:        // Set fields to READ ONLY
671:        Crm2011.UtilFunctions.disableFields(billToCols);
672:
673:        //*** BILL TO ADDRESS ***//
674:        var accountBillToAddressData = Crm2011.QuoteAddressFunctions.getAccountBillToAddress(customerid);
675:
676:        var existingValueBillToName = Xrm.Page.getAttribute("billto_name").getValue();
677:        var existingValueBillToLine1 = Xrm.Page.getAttribute("billto_line1").getValue();
678:        var existingValueBillToLine2 = Xrm.Page.getAttribute("billto_line2").getValue();
679:        var existingValueBillToLine3 = Xrm.Page.getAttribute("billto_line3").getValue();
680:
681:        var existingValueBillToCity = Xrm.Page.getAttribute("billto_city").getValue();
682:        var existingValueBillToContactName = Xrm.Page.getAttribute("billto_contactname").getValue();
683:        var existingValueBillToStateOrProvince = Xrm.Page.getAttribute("billto_stateorprovince").getValue();
684:        var existingValueBillToPostalCode = Xrm.Page.getAttribute("billto_postalcode").getValue();
685:
686:        var existingValueBillToCountry = Xrm.Page.getAttribute("billto_country").getValue();
687:        var existingValueBillToTelephone = Xrm.Page.getAttribute("billto_telephone").getValue();
688:        var existingValueBillToFax = Xrm.Page.getAttribute("billto_fax").getValue();
689:
690:        if (accountBillToAddressData != null) {
691:            if (accountBillToAddressData.name != existingValueBillToName) {
692:                Crm2011.UtilFunctions.fillField("billto_name", accountBillToAddressData.name);
693:            }
694:
695:            if (accountBillToAddressData.line1 != existingValueBillToLine1) {
696:                if (accountBillToAddressData.line1 == null) {
697:                    Crm2011.UtilFunctions.setFieldNull("billto_line1");
698:                }
699:                else {
700:                    Crm2011.UtilFunctions.fillField("billto_line1", accountBillToAddressData.line1);
701:                }
702:            }
703:
704:            if (accountBillToAddressData.line2 != existingValueBillToLine2) {
705:                if (accountBillToAddressData.line2 == null) {
706:                    Crm2011.UtilFunctions.setFieldNull("billto_line2");
707:                }
708:                else {
709:                    Crm2011.UtilFunctions.fillField("billto_line2", accountBillToAddressData.line2);
710:                }
711:            }
712:
713:            if (accountBillToAddressData.line3 != existingValueBillToLine3) {
714:                if (accountBillToAddressData.line3 == null) {
715:                    Crm2011.UtilFunctions.setFieldNull("billto_line3");
716:                }
717:                else {
718:                    Crm2011.UtilFunctions.fillField("billto_line3", accountBillToAddressData.line3);
719:                }
720:            }
721:
722:            if (accountBillToAddressData.city != existingValueBillToCity) {
723:                if (accountBillToAddressData.city == null) {
724:                    Crm2011.UtilFunctions.setFieldNull("billto_city");
725:                }
726:                else {
727:                    Crm2011.UtilFunctions.fillField("billto_city", accountBillToAddressData.city);
728:                }
729:            }
730:
731:            if (accountBillToAddressData.primarycontactname != existingValueBillToContactName) {
732:                if (accountBillToAddressData.primarycontactname == null) {
733:                    Crm2011.UtilFunctions.setFieldNull("billto_contactname");
734:                }
735:                else {
736:                    Crm2011.UtilFunctions.fillField("billto_contactname", accountBillToAddressData.primarycontactname);
737:                }
738:            }
739:
740:            if (accountBillToAddressData.stateorprovince != existingValueBillToStateOrProvince) {
741:                if (accountBillToAddressData.stateorprovince == null) {
742:                    Crm2011.UtilFunctions.setFieldNull("billto_stateorprovince");
743:                }
744:                else {
745:                    Crm2011.UtilFunctions.fillField("billto_stateorprovince", accountBillToAddressData.stateorprovince);
746:                }
747:            }
748:
749:            if (accountBillToAddressData.postalcode != existingValueBillToPostalCode) {
750:                if (accountBillToAddressData.postalcode == null) {
751:                    Crm2011.UtilFunctions.setFieldNull("billto_postalcode");
752:                }
753:                else {
754:                    Crm2011.UtilFunctions.fillField("billto_postalcode", accountBillToAddressData.postalcode);
755:                }
756:            }
757:
758:            if (accountBillToAddressData.country != existingValueBillToCountry) {
759:                if (accountBillToAddressData.country == null) {
760:                    Crm2011.UtilFunctions.setFieldNull("billto_country");
761:                }
762:                else {
763:                    Crm2011.UtilFunctions.fillField("billto_country", accountBillToAddressData.country);
764:                }
765:            }
766:
767:            if (accountBillToAddressData.telephone1 != existingValueBillToTelephone) {
768:                if (accountBillToAddressData.telephone1 == null) {
769:                    Crm2011.UtilFunctions.setFieldNull("billto_telephone");
770:                }
771:                else {
772:                    Crm2011.UtilFunctions.fillField("billto_telephone", accountBillToAddressData.telephone1);
773:                }
774:            }
775:
776:            if (accountBillToAddressData.fax != existingValueBillToFax) {
777:                if (accountBillToAddressData.fax == null) {
778:                    Crm2011.UtilFunctions.setFieldNull("billto_fax");
779:                }
780:                else {
781:                    Crm2011.UtilFunctions.fillField("billto_fax", accountBillToAddressData.fax);
782:                }
783:            }
784:        }
785:
786:        //*** SHIP TO ADDRESS ***//
787:
788:        // "shipto_telephone", "shipto_fax" is NOT on the Account Entity
789:        var shipToCols = ["shipto_name", "shipto_line1", "shipto_line2", "shipto_line3",
790:"shipto_city", "shipto_contactname", "shipto_stateorprovince", "shipto_postalcode",
791:"shipto_country", "shipto_telephone", "shipto_fax"];
792:        //Crm2011.UtilFunctions.setFieldsNull(shipToCols); SET NULL BELOW
793:        // Set fields to READ ONLY
794:        Crm2011.UtilFunctions.disableFields(shipToCols);
795:
796:        var existingValueShipToName = Xrm.Page.getAttribute("shipto_name").getValue();
797:        var existingValueShipToLine1 = Xrm.Page.getAttribute("shipto_line1").getValue();
798:        var existingValueShipToLine2 = Xrm.Page.getAttribute("shipto_line2").getValue();
799:        var existingValueShipToLine3 = Xrm.Page.getAttribute("shipto_line3").getValue();
800:
801:        var existingValueShipToCity = Xrm.Page.getAttribute("shipto_city").getValue();
802:        var existingValueShipToContactName = Xrm.Page.getAttribute("shipto_contactname").getValue();
803:        var existingValueShipToStateOrProvince = Xrm.Page.getAttribute("shipto_stateorprovince").getValue();
804:        var existingValueShipToPostalCode = Xrm.Page.getAttribute("shipto_postalcode").getValue();
805:
806:        var existingValueShipToCountry = Xrm.Page.getAttribute("shipto_country").getValue();
807:
808:        var accountShipToAddressData = Crm2011.QuoteAddressFunctions.getAccountShipToAddress(customerid);
809:        if (accountShipToAddressData != null) {
810:
811:            if (accountShipToAddressData.name != existingValueShipToName) {
812:                Crm2011.UtilFunctions.fillField("shipto_name", accountShipToAddressData.name);
813:            }
814:
815:            if (accountShipToAddressData.line1 != existingValueShipToLine1) {
816:                if (accountShipToAddressData.line1 == null) {
817:                    Crm2011.UtilFunctions.setFieldNull("shipto_line1");
818:                }
819:                else {
820:                    Crm2011.UtilFunctions.fillField("shipto_line1", accountShipToAddressData.line1);
821:                }
822:            }
823:
824:            if (accountShipToAddressData.line2 != existingValueShipToLine2) {
825:                if (accountShipToAddressData.line2 == null) {
826:                    Crm2011.UtilFunctions.setFieldNull("shipto_line2");
827:                }
828:                else {
829:                    Crm2011.UtilFunctions.fillField("shipto_line2", accountShipToAddressData.line2);
830:                }
831:            }
832:
833:            if (accountShipToAddressData.line3 != existingValueShipToLine3) {
834:                if (accountShipToAddressData.line3 == null) {
835:                    Crm2011.UtilFunctions.setFieldNull("shipto_line3");
836:                }
837:                else {
838:                    Crm2011.UtilFunctions.fillField("shipto_line3", accountShipToAddressData.line3);
839:                }
840:            }
841:
842:            if (accountShipToAddressData.city != existingValueShipToCity) {
843:                if (accountShipToAddressData.city == null) {
844:                    Crm2011.UtilFunctions.setFieldNull("shipto_city");
845:                }
846:                else {
847:                    Crm2011.UtilFunctions.fillField("shipto_city", accountShipToAddressData.city);
848:                }
849:            }
850:
851:            if (accountShipToAddressData.primarycontactname != existingValueShipToContactName) {
852:                if (accountShipToAddressData.primarycontactname == null) {
853:                    Crm2011.UtilFunctions.setFieldNull("shipto_contactname");
854:                }
855:                else {
856:                    Crm2011.UtilFunctions.fillField("shipto_contactname", accountShipToAddressData.primarycontactname);
857:                }
858:            }
859:
860:            if (accountShipToAddressData.stateorprovince != existingValueShipToStateOrProvince) {
861:                if (accountShipToAddressData.stateorprovince == null) {
862:                    Crm2011.UtilFunctions.setFieldNull("shipto_stateorprovince");
863:                }
864:                else {
865:                    Crm2011.UtilFunctions.fillField("shipto_stateorprovince", accountShipToAddressData.stateorprovince);
866:                }
867:            }
868:
869:            if (accountShipToAddressData.postalcode != existingValueShipToPostalCode) {
870:                if (accountShipToAddressData.postalcode == null) {
871:                    Crm2011.UtilFunctions.setFieldNull("shipto_postalcode");
872:                }
873:                else {
874:                    Crm2011.UtilFunctions.fillField("shipto_postalcode", accountShipToAddressData.postalcode);
875:                }
876:            }
877:
878:            if (accountShipToAddressData.country != existingValueShipToCountry) {
879:                if (accountShipToAddressData.country == null) {
880:                    Crm2011.UtilFunctions.setFieldNull("shipto_country");
881:                }
882:                else {
883:                    Crm2011.UtilFunctions.fillField("shipto_country", accountShipToAddressData.country);
884:                }
885:            }
886:        }
887:    },
888:
889:
890:    //--------------------------------------------------------------------------------------------------------------------------
891:    // Crm2011.QuoteAddressFunctions.getDefaultOUQuoteResponseAddress();
892:    //--------------------------------------------------------------------------------------------------------------------------
893:    getDefaultOUQuoteResponseAddress: function () {
894:
895:        var entityName = Xrm.Page.data.entity.getEntityName();
896:        if (entityName != "quote") {
897:            return;
898:        }
899:        sw = Crm2011.UtilFunctions.doesFieldExistNoAlert("csc_response_quotetemplateaddress");
900:        if (sw == false) {
901:            return;
902:        }
903:
904:        sw = Crm2011.UtilFunctions.doesFieldExistNoAlert("csc_operatingunit");
905:        if (sw == false) {
906:            return;
907:        }
908:        sw = Crm2011.UtilFunctions.lookupIsNull("csc_operatingunit");
909:        if (sw) {
910:            return;
911:        }
912:        var ouid = Crm2011.UtilFunctions.getLookupId("csc_operatingunit");
913:
914:        var responseAddressCols = ["csc_response_quotetemplateaddress", "csc_response_name", "csc_response_contactname",
915:"csc_response_line1", "csc_response_line2", "csc_response_line3", "csc_response_city",
916:"csc_response_stateorprovince", "csc_response_postalcode", "csc_response_country", "csc_response_telephone",
917:"csc_response_fax", "csc_response_email"];
918:
919:        //If Default Response Address Required, then clear & populate all the above fields... ???
920:        // Crm2011.UtilFunctions.setFieldsNull(responseAddressCols);
921:        // Set fields to READ ONLY
922:        Crm2011.UtilFunctions.disableFields(responseAddressCols);
923:
924:        // Only override address if Selected User Option == OU Default Response Address...
925:        var responseAddressUserOverrideSW = Crm2011.UtilFunctions.getYesNoValue("csc_responseaddressoptions");
926:        // User choose to override...
927:        if (responseAddressUserOverrideSW) {
928:            Crm2011.QuoteAddressFunctions.checkResponseAddressOptions();
929:            //return;
930:        }
931:        else {
932:            //ERP336CRM - Have moved code to setReponseAddress to allow the ability to be called form other functions
933:            Crm2011.QuoteAddressFunctions.setResponseAddress(ouid);
934:        }
935:    },
936:
937:    //--------------------------------------------------------------------------------------------------------------------------
938:    // Crm2011.QuoteAddressFunctions.setResponseAddress();
939:    //--------------------------------------------------------------------------------------------------------------------------
940:    setResponseAddress: function (ouid) {
941:        var existingValueResponseName = Xrm.Page.getAttribute("csc_response_name").getValue();
942:        var existingValueResponseLine1 = Xrm.Page.getAttribute("csc_response_line1").getValue();
943:        var existingValueResponseLine2 = Xrm.Page.getAttribute("csc_response_line2").getValue();
944:        var existingValueResponseLine3 = Xrm.Page.getAttribute("csc_response_line3").getValue();
945:
946:        var existingValueResponseCity = Xrm.Page.getAttribute("csc_response_city").getValue();
947:        var existingValueResponseContactName = Xrm.Page.getAttribute("csc_response_contactname").getValue();
948:        var existingValueResponseStateOrProvince = Xrm.Page.getAttribute("csc_response_stateorprovince").getValue();
949:        var existingValueResponsePostalCode = Xrm.Page.getAttribute("csc_response_postalcode").getValue();
950:
951:        var existingValueResponseCountry = Xrm.Page.getAttribute("csc_response_country").getValue();
952:        var existingValueResponseTelephone = Xrm.Page.getAttribute("csc_response_telephone").getValue();
953:        var existingValueResponseFax = Xrm.Page.getAttribute("csc_response_fax").getValue();
954:        var existingValueResponseEmail = Xrm.Page.getAttribute("csc_response_email").getValue();
955:
956:        var OperatingUnitAddress = Crm2011.OUFunctions.getOperatingUnitAddressRecord(ouid, Crm2011.UtilFunctions.ADDRESS_QUOTE_RESPONSE);
957:        if (OperatingUnitAddress == null) {
958:            return null;
959:        }
960:
961:        // TODO: Do all the rest in the same format... as csc_response_name
962:        if (OperatingUnitAddress.name == null) {
963:            Crm2011.UtilFunctions.setFieldNull("csc_response_name");
964:        }
965:        else {
966:            if (OperatingUnitAddress.name != existingValueResponseName) {
967:                Crm2011.UtilFunctions.fillField("csc_response_name", OperatingUnitAddress.name);
968:            }
969:        }
970:
971:        if ((OperatingUnitAddress.addresscontact.id != null) && (OperatingUnitAddress.addresscontact.name != null)) {
972:            if (OperatingUnitAddress.addresscontact.name != existingValueResponseContactName) {
973:                Crm2011.UtilFunctions.fillField("csc_response_contactname", OperatingUnitAddress.addresscontact.name);
974:            }
975:        }
976:
977:        if ((OperatingUnitAddress.street1 != null) && (OperatingUnitAddress.street1 != existingValueResponseLine1)) {
978:            Crm2011.UtilFunctions.fillField("csc_response_line1", OperatingUnitAddress.street1);
979:        }
980:
981:        if ((OperatingUnitAddress.street2 != null) && (OperatingUnitAddress.street2 != existingValueResponseLine2)) {
982:            Crm2011.UtilFunctions.fillField("csc_response_line2", OperatingUnitAddress.street2);
983:        }
984:
985:        if ((OperatingUnitAddress.street3 != null) && (OperatingUnitAddress.street3 != existingValueResponseLine3)) {
986:            Crm2011.UtilFunctions.fillField("csc_response_line3", OperatingUnitAddress.street3);
987:        }
988:
989:        if ((OperatingUnitAddress.city != null) && (OperatingUnitAddress.city != existingValueResponseCity)) {
990:            Crm2011.UtilFunctions.fillField("csc_response_city", OperatingUnitAddress.city);
991:        }
992:
993:        if ((OperatingUnitAddress.stateorprovince != null) && (OperatingUnitAddress.stateorprovince != existingValueResponseStateOrProvince)) {
994:            Crm2011.UtilFunctions.fillField("csc_response_stateorprovince", OperatingUnitAddress.stateorprovince);
995:        }
996:
997:        if ((OperatingUnitAddress.postalcode != null) && (OperatingUnitAddress.postalcode != existingValueResponsePostalCode)) {
998:            Crm2011.UtilFunctions.fillField("csc_response_postalcode", OperatingUnitAddress.postalcode);
999:        }
1000:
1001:        if ((OperatingUnitAddress.country.id != null) && (OperatingUnitAddress.country.name != null)) {
1002:            if (OperatingUnitAddress.country.name != existingValueResponseCountry) {
1003:                Crm2011.UtilFunctions.fillField("csc_response_country", OperatingUnitAddress.country.name);
1004:            }
1005:        }
1006:
1007:        if ((OperatingUnitAddress.telephone1 != null) || (OperatingUnitAddress.telephone1 != existingValueResponseTelephone)) {
1008:            Crm2011.UtilFunctions.fillField("csc_response_telephone", OperatingUnitAddress.telephone1);
1009:        }
1010:
1011:        if ((OperatingUnitAddress.fax != null) && (OperatingUnitAddress.fax != existingValueResponseFax)) {
1012:            Crm2011.UtilFunctions.fillField("csc_response_fax", OperatingUnitAddress.fax);
1013:        }
1014:
1015:        if ((OperatingUnitAddress.email != null) && (OperatingUnitAddress.email != existingValueResponseEmail)) {
1016:            Crm2011.UtilFunctions.fillField("csc_response_email", OperatingUnitAddress.email);
1017:        }
1018:
1019:        Crm2011.QuoteAddressFunctions.concatResponseAddress();
1020:    },
1021:
1022:    //--------------------------------------------------------------------------------------------------------------------------
1023:    // Crm2011.QuoteAddressFunctions.resetOUDefaulRepsonseAddress();
1024:    //--------------------------------------------------------------------------------------------------------------------------
1025:    resetOUDefaulRepsonseAddress: function (ouid) {
1026:        var OperatingUnitAddress = Crm2011.OUFunctions.getOperatingUnitAddressRecord(ouid, Crm2011.UtilFunctions.ADDRESS_QUOTE_RESPONSE);
1027:        if (OperatingUnitAddress == null) {
1028:            return null;
1029:        }
1030:
1031:        if (OperatingUnitAddress.name == null) {
1032:            Crm2011.UtilFunctions.setFieldNull("csc_response_name");
1033:        }
1034:        else {
1035:            if (OperatingUnitAddress.name != null) {
1036:                Crm2011.UtilFunctions.fillField("csc_response_name", OperatingUnitAddress.name);
1037:            }
1038:        }
1039:
1040:        if (OperatingUnitAddress.addresscontact.id == null) {
1041:            Crm2011.UtilFunctions.setFieldNull("csc_response_contactname");
1042:        }
1043:        else {
1044:            if ((OperatingUnitAddress.addresscontact.id != null) && (OperatingUnitAddress.addresscontact.name != null)) {
1045:                Crm2011.UtilFunctions.fillField("csc_response_contactname", OperatingUnitAddress.addresscontact.name);
1046:            }
1047:        }
1048:
1049:        if (OperatingUnitAddress.street1 == null) {
1050:            Crm2011.UtilFunctions.setFieldNull("csc_response_line1");
1051:        }
1052:        else {
1053:            if (OperatingUnitAddress.street1 != null) {
1054:                Crm2011.UtilFunctions.fillField("csc_response_line1", OperatingUnitAddress.street1);
1055:            }
1056:        }
1057:
1058:        if (OperatingUnitAddress.street2 == null) {
1059:            Crm2011.UtilFunctions.setFieldNull("csc_response_line2");
1060:        }
1061:        else {
1062:            if (OperatingUnitAddress.street2 != null) {
1063:                Crm2011.UtilFunctions.fillField("csc_response_line2", OperatingUnitAddress.street2);
1064:            }
1065:        }
1066:
1067:        if (OperatingUnitAddress.street3 == null) {
1068:            Crm2011.UtilFunctions.setFieldNull("csc_response_line3");
1069:        }
1070:        else {
1071:            if (OperatingUnitAddress.street3 != null) {
1072:                Crm2011.UtilFunctions.fillField("csc_response_line3", OperatingUnitAddress.street3);
1073:            }
1074:        }
1075:
1076:        if (OperatingUnitAddress.city == null) {
1077:            Crm2011.UtilFunctions.setFieldNull("csc_response_city");
1078:        }
1079:        else {
1080:            if (OperatingUnitAddress.city != null) {
1081:                Crm2011.UtilFunctions.fillField("csc_response_city", OperatingUnitAddress.city);
1082:            }
1083:        }
1084:
1085:        if (OperatingUnitAddress.stateorprovince == null) {
1086:            Crm2011.UtilFunctions.setFieldNull("csc_response_stateorprovince");
1087:        }
1088:        else {
1089:            if (OperatingUnitAddress.stateorprovince != null) {
1090:                Crm2011.UtilFunctions.fillField("csc_response_stateorprovince", OperatingUnitAddress.stateorprovince);
1091:            }
1092:        }
1093:
1094:        if (OperatingUnitAddress.postalcode == null) {
1095:            Crm2011.UtilFunctions.setFieldNull("csc_response_postalcode");
1096:        }
1097:        else {
1098:            if (OperatingUnitAddress.postalcode != null) {
1099:                Crm2011.UtilFunctions.fillField("csc_response_postalcode", OperatingUnitAddress.postalcode);
1100:            }
1101:        }
1102:
1103:        if (OperatingUnitAddress.country.id == null) {
1104:            Crm2011.UtilFunctions.setFieldNull("csc_response_country");
1105:        }
1106:        else {
1107:            if ((OperatingUnitAddress.country.id != null) && (OperatingUnitAddress.country.name != null)) {
1108:                Crm2011.UtilFunctions.fillField("csc_response_country", OperatingUnitAddress.country.name);
1109:            }
1110:        }
1111:
1112:        if (OperatingUnitAddress.telephone1 == null) {
1113:            Crm2011.UtilFunctions.setFieldNull("csc_response_telephone");
1114:        }
1115:        else {
1116:            if (OperatingUnitAddress.telephone1 != null) {
1117:                Crm2011.UtilFunctions.fillField("csc_response_telephone", OperatingUnitAddress.telephone1);
1118:            }
1119:        }
1120:
1121:        if (OperatingUnitAddress.fax == null) {
1122:            Crm2011.UtilFunctions.setFieldNull("csc_response_fax");
1123:        }
1124:        else {
1125:            if (OperatingUnitAddress.fax != null) {
1126:                Crm2011.UtilFunctions.fillField("csc_response_fax", OperatingUnitAddress.fax);
1127:            }
1128:        }
1129:
1130:        if (OperatingUnitAddress.email == null) {
1131:            Crm2011.UtilFunctions.setFieldNull("csc_response_email");
1132:        }
1133:        else {
1134:            if (OperatingUnitAddress.email != null) {
1135:                Crm2011.UtilFunctions.fillField("csc_response_email", OperatingUnitAddress.email);
1136:            }
1137:        }
1138:
1139:        Crm2011.QuoteAddressFunctions.concatResponseAddress();
1140:    },
1141:
1142:    //--------------------------------------------------------------------------------------------------------------------------
1143:    // Crm2011.QuoteAddressFunctions.checkResponseAddressOptions();
1144:    //--------------------------------------------------------------------------------------------------------------------------
1145:    checkResponseAddressOptions: function () {
1146:        var responseAddressUserOverrideSW = Crm2011.UtilFunctions.getYesNoValue("csc_responseaddressoptions");
1147:        var responseAddressCols = ["csc_response_quotetemplateaddress", "csc_response_name", "csc_response_contactname",
1148:"csc_response_line1", "csc_response_line2", "csc_response_line3", "csc_response_city",
1149:"csc_response_stateorprovince", "csc_response_postalcode", "csc_response_country", "csc_response_telephone",
1150:"csc_response_fax", "csc_response_email"];
1151:
1152:        if (responseAddressUserOverrideSW) {
1153:            Crm2011.UtilFunctions.enableFields(responseAddressCols);
1154:            return;
1155:        }
1156:        else {
1157:            var ouid = Crm2011.UtilFunctions.getLookupId("csc_operatingunit");
1158:            Crm2011.QuoteAddressFunctions.resetOUDefaulRepsonseAddress(ouid);
1159:            Crm2011.UtilFunctions.disableFields(responseAddressCols);
1160:        }
1161:    },
1162:
1163:
1164:    //--------------------------------------------------------------------------------------------------------------------------
1165:    // Function: var accountBillToAddressData = Crm2011.QuoteAddressFunctions.getAccountBillToAddress(accountid);
1166:    // address1_country == The Prefix, link to csc_country to get the Name...
1167:    // JAL - Only called from the quote address so move to that .js
1168:    //--------------------------------------------------------------------------------------------------------------------------
1169:    getAccountBillToAddress: function (accountid) {
1170:
1171:        if (accountid == null) {
1172:            return null;
1173:        }
1174:        else {
1175:            var cols = ["accountid", "address1_name", "address1_addressid", "address1_addresstypecode",
1176:"address1_line1", "address1_line2", "address1_line3", "address1_postalcode",
1177:"address1_city", "address1_country", "address1_stateorprovince", "address1_county",
1178:"address1_primarycontactname", "address1_telephone1", "address1_telephone2", "address1_telephone3",
1179:"address1_fax"];
1180:            var retrievedRec = Crm2011.UtilFunctions.crmServiceToolkitRetrieveAction("account", accountid, cols);
1181:            if ((retrievedRec == null) || (retrievedRec == false)) {
1182:                return null;
1183:            }
1184:            else {
1185:                var countryid = null, countryname = null;
1186:                var countryPrefix = retrievedRec.getValue("address1_country");
1187:                if (countryPrefix != null) {
1188:                    var CountryRecord = Crm2011.CountryFunctions.getCountryByPrefix(countryPrefix);
1189:                    if (CountryRecord != null) {
1190:                        countryid = CountryRecord.id;
1191:                        countryname = CountryRecord.name;
1192:                    }
1193:                }
1194:
1195:                // accountBillToAddressData(accountid, name, addressid, addresstypecode, line1, line2, line3, postalcode, city
1196:                // country, stateorprovince, county, primarycontactname, telephone1, telephone21, telephone3,
1197:                // fax, customercountry.id, customercountry.name )
1198:                var accountBillToAddressData = {
1199:
1200:                    accountid: retrievedRec.getValue("accountid"),
1201:                    name: retrievedRec.getValue("address1_name"),
1202:                    addressid: retrievedRec.getValue("address1_addressid"),
1203:                    addresstypecode: retrievedRec.getValue("address1_addresstypecode"),
1204:
1205:                    line1: retrievedRec.getValue("address1_line1"),
1206:                    line2: retrievedRec.getValue("address1_line2"),
1207:                    line3: retrievedRec.getValue("address1_line3"),
1208:                    postalcode: retrievedRec.getValue("address1_postalcode"),
1209:
1210:                    city: retrievedRec.getValue("address1_city"),
1211:                    country: retrievedRec.getValue("address1_country"),
1212:                    stateorprovince: retrievedRec.getValue("address1_stateorprovince"),
1213:                    county: retrievedRec.getValue("address1_county"),
1214:
1215:                    primarycontactname: retrievedRec.getValue("address1_primarycontactname"),
1216:                    telephone1: retrievedRec.getValue("address1_telephone1"),
1217:                    telephone2: retrievedRec.getValue("address1_telephone2"),
1218:                    telephone3: retrievedRec.getValue("address1_telephone3"),
1219:
1220:                    fax: retrievedRec.getValue("address1_fax"),
1221:
1222:                    customercountry: {
1223:                        id: countryid,
1224:                        name: countryname
1225:                    }
1226:
1227:                }
1228:                return accountBillToAddressData;
1229:            }
1230:        }
1231:    },
1232:
1233:    //--------------------------------------------------------------------------------------------------------------------------
1234:    // var accountShipToAddressData = Crm2011.QuoteAddressFunctions.getAccountShipToAddress(accountid);
1235:    // address2_country == The Prefix, link to csc_country to get the Name...
1236:    // JAL - Only called from the quote address so move to that .js
1237:    //--------------------------------------------------------------------------------------------------------------------------
1238:    getAccountShipToAddress: function (accountid) {
1239:
1240:        if (accountid == null) {
1241:            return null;
1242:        }
1243:        else {
1244:            var cols = ["accountid", "address2_addresstypecode", "address2_name", "address2_primarycontactname",
1245:"address2_line1", "address2_line2", "address2_line3", "address2_city",
1246:"address2_county", "address2_stateorprovince", "address2_country", "address2_postalcode"];
1247:
1248:            var retrievedRec = Crm2011.UtilFunctions.crmServiceToolkitRetrieveAction("account", accountid, cols);
1249:            if ((retrievedRec == null) || (retrievedRec == false)) {
1250:                return null;
1251:            }
1252:            else {
1253:                var countryid = null, countryname = null;
1254:                var countryPrefix = retrievedRec.getValue("address2_country");
1255:                if (countryPrefix != null) {
1256:                    var CountryRecord = Crm2011.CountryFunctions.getCountryByPrefix(countryPrefix);
1257:                    if (CountryRecord != null) {
1258:                        countryid = CountryRecord.id;
1259:                        countryname = CountryRecord.name;
1260:                    }
1261:                }
1262:                var accountShipToAddressData = {
1263:
1264:                    accountid: retrievedRec.getValue("accountid"),
1265:                    name: retrievedRec.getValue("address2_name"),
1266:                    addresstypecode: retrievedRec.getValue("address2_addresstypecode"),
1267:
1268:                    line1: retrievedRec.getValue("address2_line1"),
1269:                    line2: retrievedRec.getValue("address2_line2"),
1270:                    line3: retrievedRec.getValue("address2_line3"),
1271:                    postalcode: retrievedRec.getValue("address2_postalcode"),
1272:
1273:                    city: retrievedRec.getValue("address2_city"),
1274:                    country: retrievedRec.getValue("address2_country"),
1275:                    stateorprovince: retrievedRec.getValue("address2_stateorprovince"),
1276:                    county: retrievedRec.getValue("address2_county"),
1277:
1278:                    primarycontactname: retrievedRec.getValue("address2_primarycontactname"),
1279:
1280:                    customercountry: {
1281:                        id: countryid,
1282:                        name: countryname
1283:                    }
1284:
1285:                }
1286:                return accountShipToAddressData;
1287:            }
1288:        }
1289:
1290:    },
1291:
1292:    __namespace: true
1293:};
1294:
1295://--------------------------------------------------------------------------------------------------------------------------
1296:// **** QUOTEADDRESS.JS ****
1297://--------------------------------------------------------------------------------------------------------------------------

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Feridun Kadir
Feridun Kadir
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of apollo7

ASKER

That seems to work for new Quotes, is there a way to strip out the first line of draft quotes that already have Bill To or Ship To already written as part of the address text?
Avatar of apollo7

ASKER

Feridun, this works very well, appreciate your help
You are welcome. Did you sort out how to remove the first line for existing records?