Javascript Page Security Plugin

Use Javascript functions to control field visibility and editability on your CPQ quotes.
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.

  • 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

Note

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.

Table 1. isFieldVisible (Summer '15)
Parameter Type Definition
fieldname string If isFieldVisible returns False, this quote line field is hidden.
line SObject The quote line object
conn Object Methods access jsforce through the optional parameter conn.
Table 2. isFieldEditable (Summer '15)
Parameter Type Definition
fieldname string If isFieldEditable returns False, this quote line field is locked from edits.
line SObject The quote line object
conn Object Methods access jsforce through the optional parameter conn.
Table 3. isFieldVisibleForObject (Summer '19)
Parameter Type Definition
fieldName String if isFieldVisibleForObject returns False, this field is hidden.
quote or line SObject The object containing the field that you're evaluating to determine whether fieldName is visible.
conn Object Methods access jsforce through the optional parameter conn.
objectName String

The object that contains fieldName. If your second parameter is quote, use Quote__c. If your second parameter is quoteline, use QuoteLine__c. Leave this parameter undefined to target the same field on the quote and the quote line.

Table 4. isFieldEditableForObject (Summer '19)
Parameter Type Definition
fieldName String if isFieldEditableForObject returns False, this field is locked from edits.
quote or line SObject The object containing the field that you're evaluating to determine whether fieldName is editable.
conn Object Methods access jsforce through the optional parameter conn.
objectName String The object that contains fieldName. If your second parameter is quote, use Quote__c. If your second parameter is quoteline, 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 using 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 objectNamein 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.

Example

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

Example

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

Example

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.

Example