Javascript Page Security Plugin

Use Javascript functions to control field visibility and editability on your CPQ quotes.

Required Editions
Available in: Salesforce CPQ Summer '15 and later

The Javascript Page Security plugin supports four functions. The functions isFieldVisible and isFieldEditable are available starting in Salesforce CPQ Summer '15 and control quote line field visibility and editability. The functions isFieldVisibleForObject and isFieldEditableForObject are available starting in Salesforce CPQ Summer '19 and can control field visibility and editability for both quote fields and quote line fields. When a method using one of these functions returns False, Salesforce CPQ locks or hides the chosen fields. The fields are unchanged if the method returns Null or True.

Because isFieldVisibleForObject and isFieldEditableForObject can accept a quote or quote line, we recommend naming your object parameter quoteOrLine.

  • Salesforce CPQ prioritizes field-level security over page security plugins. If a field is read-only and an editability function for that field returns True, the field remains read-only.
  • Use the page security plugin only for hiding, showing, and adjusting the editability of fields. If you want change field values, use the Javascript Quote Calculator Plugin.
  • The quote line editor shows blank empty spaces for quote line drawer fields hidden by the page security plugin. To remove these spaces, go to Salesforce CPQ line editor package settings and select Enable Compact Mode.

To create a page security plugin, define your code in a custom script record and then reference that record's name in the Quote Calculator Plugin field within Salesforce CPQ Plugin package settings. If you’re already using a quote calculator plugin in that field, you can add your page security plugin code to the calculator plugin’s custom script record.

ParameterTypeDefinition
fieldnamestringIf isFieldVisible returns False, this quote line field is hidden.
lineSObjectThe quote line object
connObjectMethods access jsforce through the optional parameter conn.
ParameterTypeDefinition
fieldnamestringIf isFieldEditable returns False, this quote line field is locked from edits.
lineSObjectThe quote line object
connObjectMethods access jsforce through the optional parameter conn.
ParameterTypeDefinition
fieldNameStringA field on the quote or quote line. If isFieldVisibleForObject returns False, this field is hidden.
quoteOrLineSObjectThe object containing the field that you're evaluating to determine whether fieldName is visible. Can be a quote or a quote line.
connObjectMethods access jsforce through the optional parameter conn.
objectNameStringThe object that contains fieldName. If quoteOrLine is evaluating a quote, use Quote__c. If quoteOrLine is evaluating a quote line, use QuoteLine__c. Leave this parameter undefined to target the same field on the quote and the quote line.
ParameterTypeDefinition
fieldNameStringA field on the quote or quote line. If isFieldEditableForObject returns False, this field is locked from edits.
quoteOrLineSObjectThe object containing the field that you're evaluating to determine whether fieldName is editable. Can be a quote or a quote line.
connObjectMethods access jsforce through the optional parameter conn.
objectNameStringThe object that contains fieldName. If quoteOrLine is evaluating a quote, use Quote__c. If quoteOrLine is evaluating a quote line, use QuoteLine__c. Leave this parameter undefined to target the same field on the quote and the quote line.

We strongly recommend that users on Salesforce CPQ Summer '19 and later use the new functions given their improved flexibility. If your plugin uses pre-Summer '19 functions with isFieldEditableForObject or isFieldVisibleForObject functions that use the line parameter, Salesforce CPQ ignores the new functions and uses the old functions instead.

To specify whether your changes apply to a field on the quote or on the quote line, use an if statement for your objectName in the isFieldVisibleForObject or isFieldEditableForObject code block. For example, in the following code segment, we're targeting the Markup Rate field on the quote.

However, the following code segment targets Markup Rate on both the quote and the quote line.

In this example, if a quote's Customer Discount is greater than 10%, we lock the quote's Markup Rate field from edits.

In this example, if a quote line's Distributor Discount is greater than 10%, we hide the quote line's Markup Rate field.

One function can also evaluate and act on quote and quote line fields at the same time, including twin fields. In this example, if a quote's Customer Discount is greater than 10%, we lock the quote's Markup Rate field from edits. If the quote line's Distributor Discount is greater than 10%, we hide the quote line's Markup Rate field.