Clone Customization

Our next customization is a toolbar button that enables a user to make copies of records with the click of a button. The purpose of this clone feature is to expedite the process of entering multiple records at once when the records are all very similar to one another. For example, if we are manually building our product list and have many similar items we can use this functionality to quickly copy records so we can then make changes to the copied record.

Let's take a closer look at this customization. As with any other customization, it is necessary to make sure that the ISV Integration key in the web.config file is turned on. Next, we need to add the following line in the Entities section in the isv.config file to add the clone button on the menu bar of the different entities we want to be able to clone:

<account>
    <ToolBar ValidForCreate="0" ValidForUpdate="1">
    <Button Title="Clone" ToolTip="Clone this account"
Icon="/_imgs/ico_18_debug.gif"
    Url="/Custom/c360/ToolPac/Clone.aspx" PassParams="1" WinParams="" WinMode="1" />
    </ToolBar>
</account>

NOTE

Our clone customization is capable of cloning accounts, contacts, opportunities, leads, cases, competitors, quotes, orders, and invoices.


When the user clicks the new clone button, a new window pops up and loads the Clone.aspx page. This page retrieves the original record, makes a copy of it, adds Clone of to the name or description of the new record, and displays a confirmation message. When the user dismisses the confirmation, the current window is closed, the new record is diplayed in a new pop-up window, and also the grid on the main screen is refreshed so that the new record is displayed if needed.

Looking at Clone.aspx, and more specifically at the Page_Init() method, you see that we first read the unique Id and the type of the original object we want to clone:

string strObjectId = Request.QueryString["oId"].ToString();
string strObjectType = Request.QueryString["oType"].ToString();

The reason those two values are passed to our custom ASPX page is that we turned on the PassParams option in ISV.config. The object type is an integer that represents the object. For example, 1 is an account, 2 is a contact, and 3 is an opportunity. Table 14.3 includes a complete list of all the Microsoft CRM object types.

Table 14.3. Microsoft CRM Object Type Codes
TypeDescription
1Account
2Contact
3Opportunity
4Lead
5Annotation
8SystemUser
9Team
10BusinessUnit
112Incident
121Workflow Process
122Workflow ProcessInstance
123Competitor
126DocumentIndex
127KbArticle
128FAQList
129Subject
130CompetitorContact
131LightweightContact
132BusinessUnitNewsArticle
134Activity
135ActivityParty
136FaxActivity
137PhoneCallActivity
138EmailActivity
139ChatActivity
140IncidentResolutionActivity
141LetterActivity
142AppointmentActivity
145OpportunityCloseActivity
146QueCloseActivity
147OrderCloseActivity
150UserSettings
1001ActivityMimeAttachment
1003InternalAddress
1004CompetitorAddress
1005CompetitorContactAddress
1007CompetitorRevenueReport
1010Contract
1011ContractDetail
1013Discount
1014ExactDocumentMatch
1016KbArticleTemplate
1017LeadAddress
1019Organization
1021OrganizationUI
1022PriceLevel
1023Privilege
1024Product
1026ProductPriceLevel
1036Role
1037RoleTemplate
1038SalesLiterature
1039SavedQuery
1040SearchCriterion
1041SearchLog
1044SuggestedExactMatch
1045SuggestedSearchCriterion
1054Unit
1055UoM
1056UoMSchedule
1061Workflow Action
1062WFActionLog
1064WFCondition
1065WFEventLog
1066WFParameter
1067WFRule
1068WFRuleLog
1069WFStep
1070SalesLiteratureItem
1071CustomerAddress
1080DiscountType
1081IncidentEntryActivity
1082KbArticleComment
1083OpportunityProduct
1084Que
1085QueDetail
1086UserFiscalCalendar
1088SalesOrder
1089SalesOrderDetail
1090Invoice
1091InvoiceDetail
2000AnnualFiscalCalendar
2001SemiAnnualFiscalCalendar
2002QuarterlyFiscalCalendar
2003MonthlyFiscalCalendar
2004FixedMonthlyFiscalCalendar
2010Template
2011ContractTemplate
2012LWContact
2013Territory
2014MailingList
2020Queue
2028TrackedItemHistory
2029QueueItem
3000IntegrationStatus

Some of the types listed in Table 14.4 are not yet implemented in Microsoft CRM, but will be in a future version. An example of this is the ChatActivity object. If the existence of a CRM object that involves chat piques your curiosity about things to come, be sure and read Chapter 21, “Future Directions of Microsoft CRM.”

Next, we need to identify the current user which is done by the following:

CBizUser objCurrentUser = new CBizUser();
CUserAuth objUserAuth = objCurrentUser.WhoAmI();

We must now retrieve all fields for the source object, which is exactly what the RetrieveObject method we wrote does by calling the Retrieve method of the appropriate CRM object. In the case of an account, for example, this is the code that performs the retrieval:

CRMAccount objAccount = new CRMAccount();
strResult = objAccount.Retrieve( ref objUserAuth, strObjectId, "");

The retrieve method expects three parameters: a reference to a UserAuth object returned by the WhoAmI method, the unique identifier of the object to retrieve, and the list of fields to retrieve.

NOTE

This list of fields must adhere to the ColumnsetXml, format, which is defined in the SDK in the ColumnSet XML Schema section. However, one thing that the SDK does not mention is that an empty string is the equivalent of saying, “I want all fields.”


The last step in this customization is to take the string returned by the Retrieve method, filter out the fields that are not valid when creating a new object, change the description node (depending on the object type, this node can be the name, first name, description, subject, and so on) to say “Clone of…” so that this new record is clearly identified as a clone of another record, and finally create the new record. This is what the CloneRecord method does.

The rest of the code in the ASPX page is client-side JavaScript code to close the current window, open a new one, and display the new record.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.0.10