Creating Calculated Fields
You can configure Siebel CRM Desktop to display a calculated field in the client so that it behaves in a way that is similar to how a calculated field behaves in the client of a Siebel Business Application. The example in this topic configures a calculated field in the client. If the user changes the opportunity name, then the value in this field also changes. You do the following:
Expose a calculated field to an integration object and synchronize it with Siebel CRM Desktop. This configuration allows Siebel CRM Desktop to get a correct starting value for the calculated field. In this example, you use a calculated field named JVD Calculated. It includes the following calculated value:
[Name] + " - Calculated"
Use a Siebel CRM Desktop calculated field to make a working copy of the original calculated field. You do this because you cannot configure Siebel CRM Desktop to make changes to a calculated field from Siebel CRM while the user is using Siebel CRM Desktop. Doing so might cause a synchronization error.
Use JavaScript in the form to make sure the copy of the calculated field changes if the user changes the opportunity name. This configuration allows you to use the same behavior that occurs in the client of a Siebel Business Application for the calculated field.
For more information about each of these items, see Alternative Ways to Create Calculated Fields.
To create a calculated field
Open Siebel Tools and then display the object type named Integration Object.
For more information, see Displaying Object Types in Siebel Tools.
In the Object Explorer, click Integration Object.
In the Integration Objects list, query the Name property for CRMDesktopOpportunityIO.
In the Object Explorer, expand the Integration Object tree and then click Integration Component.
In the Integration Components list, add a new integration component using values from the following table.
Property Value Name
JVD Calculated
Data Type
DTYPE_TEXT
Length
285
External Sequence
240
External Name
JVD Calculated
External Data Type
DTYPE_TEXT
XML Sequence
240
XML Tag
JVDCalculated
This integration component exposes the Siebel CRM calculated field to the integration object for the opportunity.
Deploy your changes to the Siebel Runtime Repository.
Use an XML editor open the siebel_meta_info.xml file.
Locate the following object:
TypeId="Opportunity"
Add the following code to the object you located in step 8:
<field Name='JVD Calculated' Label='JVD Calculated' DataType='DTYPE_TEXT' IsFilterable='no' IsHidden='no'IOElemName='JVDCalculated' />
This code adds the JVD Calculated field to the metadata object for Opportunity. For more information, see JavaScript Files in the Customization Package.
Set the calculated field in Siebel CRM Desktop. You add the following code to the siebel_basic_mapping.xml file:
<field id="JVD Calculated"> <reader> <mapi_user> <user_field id="sbl JVD Calculated" ol_field_type="1"></ user_field> <convertor> <string/> </convertor> </mapi_user> </reader> <writer> <Outlook_user> <user_field id="sbl JVD Calculated" ol_field_type="1"></user_field> <convertor> <string/> </convertor> </Outlook_user> </writer> </field>
Use an XML editor to open the forms_xx.xml file.
For more information about the forms_xx.xml file, see Files in the Customization Package.
Locate the Opportunity form. You locate the following code:
<form id="SBL Opportunity">
Add the calculated field to the opportunity form. You add the following code to Opportunity form:
<edit id="jvd_calculated"> <field value="string">JVD Calculated</field> </edit>
Use a JavaScript editor to open the forms.js file.
Make the field read-only. You add the following code to the opportunity_form function:
ctx.form.jvd_calculated.enabled = false;
A calculated field in Siebel CRM is read-only. It is recommended that you also make the calculated field in Siebel CRM Desktop read-only. For more information, see Making Fields Read-Only.
Save your work.
Configure Siebel CRM Desktop to update the field value. You add the following code to the file:
function jvd_calculate() { var NameValue = ctx.form.item.snapshot['Name']; ctx.form.jvd_calculated.value = NameValue + " - Calculated"; }
This function gets the value of the Name field. It then writes to the jvd_calculated field the value of this Name field plus the following string concatenated to the opportunity name:
– Calculated
To calculate the value, Siebel CRM uses the following code:
[Name] + “ – Calculated”??
For more information, see Customizing Form Functions.
Add the following code to the on_focus_lost event:
ctx.events.connect(ctx.form["opportunity"],"on_focus_lost",jvd_calculate);
For more information, see Customizing Event Connectors.
This code makes sure Siebel CRM Desktop calls this function if the user changes the value in a field that the calculation uses. In this example, the calculated value depends only on the opportunity name, so this code only calls this function if the user changes the value in the Opportunity Name field.
This code creates a dependency between an event and a function. If the form field is:
A dropdown list, then you use the changed event.
An edit box, then you use the on_focus_lost event.
The opportunity name field is an edit box so you configure Siebel CRM Desktop to call the function on the on_focus_lost event.
Test your changes and then republish the customization package.
For more information, see Republishing Customization Packages.