JavaScript Toolkit Library

This following section describes the JavaScript library components included with the current version of the toolkit. The toolkit has a set of core objects used for UI control, Data Access and Application state or navigation. The core Library Objects are as follows:

BPSystem: Used to access and manage all UI and application state variables as well as initialization of the toolkit’s Metadata and Data Access features.

BPObject: Abstract class from which all base, data objects are extended

BRMAggregate: Object type used for Aggregate Query results where actual BPObject and field types no longer apply due to column aliasing and aggregation in column functions such as SUM, COUNT, AVG, etc.. The BRMAggregate Object consists of simple name/value pairs of column aliases and the associated value. They values are all returned as strings and must be cast to the appropriate data type after retrieval.

BPUI: Primary object for all Tag components

BPActions: Used for refreshing, showing and hiding different elements of the UI or Tag structure.

BPConnection: Used for all database interaction and DML.

BPCollection: Intelegent collection of BPObjects. Part of the query and retrieve response objects and also used for bulk DML.

 

System Methods and Attributes

System Methods and Attributes are accessed via the BPSystem class and are used for retrieving managing state variables associated with the standard application as well as the Toolkit Widgets. The following is a list of Attributes and Functions that are part of the BPSystem class.

BPSystem Class Methods

Method
getSelectedEntityId(String entityType)

Retrieves the Id of the currently selected Record using the given the Entity Name

Parameters entityType:
Type: String
The Name of the type of Entity for which the selected record Id is associated.
Return Value Type: String
The Record Id or “Key” of the currently selected record

Example

var accountId = BPSystem.getSelectedEntityId(“Account”);

Method
initialize()

Initiates the Session and AJaX for application and data access

Parameters none
Return Value Type: void

Example

BPSystem.initaite();

Method
toBPObject(Object jsonObject, Object entityType)

Used to convert a JSON object or a related Object retrieved via query method to a BPObject instance of a specified Type

Parameters jsonObject:
Type: JSON Object array
The Object to Convert.

entity:
Type: Object
A new Instance of the type of object to Convert to.
Return Value Type: BPObject
The Resulting Object instance

Example

var result = BPConnection.BillingProfile.query(“select Id, BillingProfileObj.Id, BillingProfileObj.AccountId from BillingProfile where Id = “ +BPSystem.nodeKey);

var myBillingProfile = BPSystem.toBPObject(result.elements[0].BillingProfileObj ,new BillingProfile());

Method
toBPCollection(Object[] jsonObject, Object entityType)

Used to convert a JSON array to a collection of BPObjects of a specified Type

Parameters jsonObject:
Type: JSON Object array
The Object to Convert.

entity:
Type: Object
A new Instance of the type of object to Convert to.
Return Value Type: BPObject
The Resulting Object instance

Example

window.activities = new BPUI.ReferenceObject(); 

//create an array of three new Activity objects
activities.set(BPSystem.toBPCollection([{},{},{}],new Activity()));

 

BPSystem Class Attributes

 

Attribute Name Data Type Description
rootNodeId  Number  Metadata Id of the Active Tab 
nodeId  Number  Metadata Id of the Current Node 
nodeKey  node key  The Key or Record Id of the Currently selected Record 
nodeName  node name  The Name of the Currently Selected or Active Node 
rootNodeName  name  The Name of the Active Tab 
pageName string  The Name of the Active Page Widget 

 

UI Component Management

UI Interactions and Page state refreshes (such as changes to underlying data, error display, etc) are managed by two core Classes: BPUI and BPActions. The two classes and their associated methods and attributes are described below.

BPActions Class Methods

Method
changeState(string tagId, Object newStateData)

Used to refresh UI components or BPUI Tags once their data has changed in in the controller.

Parameters tagId:
Type: String
The Id of Name of the Tag whose state will be changed.

newStateData:
Type: Object
The Updated version of the object that the Tag is referencing.
Return Value Type: void

Example

<BPUI.EmbeddedList variable={activities} name="activities" width="100%"  > 
      <BPUI.TableColumn name="ProductId" index="2" label="Product"/>
      <BPUI.TableColumn name="Quantity" index="4" label="Quantity"/>
</BPUI.EmbeddedList>


//Refresh The table and allow for adding rows
BPActions.changeState("activities", {
       canAdd: true,
       columns: [{ name: "ProductId ", label: " ProductId", index: "0" }
                , { name: " Quantity", label: "Quantity", index: "1"}]
});

Method
clearErrors()

Used to reset or clear the error state of a form or Page Widget.

Parameters none
Return Value Type: void

Example

BPActions.clearErrors();

Method
closeDialog()

Used to hide a specified BPUI.Dialog component.

Parameters componentName: String: The name of theBPUI.Dialog component to close.
Return Value Type: void

Example

---------------------------HTML----------------------------------
<BPUI.Dialog name="billingProfileDialog">
  <BPUI.PopupForm>
      <BPUI.Panel style ={{width: 100 + "%", height: 100 + "%"}}>
          <BPUI.InputField variable={billingProfile}  field="AccountId"/>
          <BPUI.InputField variable={billingProfile}  field="Email"/>
          <BPUI.InputField variable={billingProfile}   field="Status"/>
      </BPUI.Panel>
  </BPUI.PopupForm>
</BPUI.Dialog>

------------------------------JAVA---------------------------------
BPActions.closeDialog(“billingProfileDialog”);

Method
showDialog(String componentName, Object dialogAttributes)

Used to Display a specified BPUI.Dialog component.

Parameters componentName:
Name of the BPUI.Dialog component to show

dialogAttributes
List of Attributes for sizing, title, etc.
Return Value Type: void

Example

---------------------------HTML----------------------------------
<BPUI.Dialog name="billingProfileDialog">
  <BPUI.PopupForm>
      <BPUI.Panel style ={{width: 100 + "%", height: 100 + "%"}}>
          <BPUI.InputField variable={billingProfile}  field="AccountId"/>
          <BPUI.InputField variable={billingProfile}  field="Email"/>
          <BPUI.InputField variable={billingProfile}   field="Status"/>
      </BPUI.Panel>
  </BPUI.PopupForm>
</BPUI.Dialog>

-----------------------------JAVA---------------------------------
BPActions.showDialog("billingProfileDialog", {
   resizable: false,
   draggable: true,
   title: title,
   modal: true,
   width: 390,
   maxHeight: (window.innerHeight * 2 / 2),
   dialogClass: 'dialog-lookup',
   maxWidth: 450
});

Method
handleError(String errorMessage)

Used to display a specified error message for the page.  The function will propagate errors to the data components that have DML or validation errors as a result of processing.

Parameters errors
array of errors or javascript native error.
Return Value Type: void

Example

BPConnection.Invoice.create({BillingProfileId:”BadData”}).done(function(res){}).fail(function(error){
//This will propagate errors to the appropriate Invoice Fields
BPActions.handleError(error);
})

Method
loadData(String componentName, Object[] dataToLoad)

Used to load data to component if it not possible to use our standart two way binding mechanism. For example javascript as a string ( <a href=”javascript:BPActions.loadData(‘test’,someGlobalObject)”>

Parameters componentName
The Name of the component to load data for.

dataToLoad
Object or array to load the referenced component with.
Return Value Type: void

Example

BPActions.loadData("packageSelect", dropBox);

Method
overrideSubmitButton()

Used for pre and post submit processing and error handling. The Override specification comes with two built-in functions: beforeSubmit and afterSubmit.

Parameters Object containing the before and after functions
Return Value Type: void

Example

BPActions.overrideSubmitButton({beforeSubmit:function () {
alert("Before Submit!!");

},afterSubmit:function () {
alert("After Submit!!");
}})

Method
overrideDeleteButton()

Used for pre and post submit processing and error handling. The Override specification comes with two built-in functions: beforeDelete and afterDelete.

Parameters Object containing the before and after functions
Return Value Type: void

Example

BPActions.overrideDeleteButton({beforeSubmit:function () {
alert("Before Delete!!");

},afterSubmit:function () {
alert("After Delete!!");
}})

Method
uploadFile(String fileAttributes, String entityType, String fieldname, String recordId)

Upload File Method saves a selected file from a document control to the server given an Object Name, Field Name and Object Id.

Parameters fileAttributes
The name and type of Document.

entityType
The type of entity ex: ACCOUNT, INVOICE.

fieldName
the Name of the field on the specified record that the file is stored under.

recordId
The Id of the record this file is associated with.
Return Value Type: void

Example

// Create the Invoice record
BPConnection.Invoice.create(invoice.get());

//Attach the file to the Invoice Record in the “Attachment1” document field
BPActions.uploadFile("[data-name=myfile.doc] [type=file]" 
                      ,"INVOICE"
                      ,"Attachment1"
                      ,invoice.get().Id);

 

 
 

BPUI Class Methods

The BPUI class is used strictly for page rendering and is the primary class supporting the Web Toolkit Tag Library. It currently exposes only one JavaScript Method and one JavaScript attribute. We will cover the majority of the BPUI structure in the Web Toolkit tag section.

Method
afterRender()

The afterRender function is used to initialize the data in components after the page loads and the components have loaded with their proper references (names).

Parameters none
Return Value Type: void

Example

// Method Called after the Page renders. This will be used to initialize and render the Google Map      
BPUI.afterRender = function () {
    
//Standard jQuery function for loading remote scripts
$.getScript("https://maps.google.com/maps/api/js?sensor=true&region=nz&async=2&callback=MapApiLoaded", 
                  function () {    
        });
     }  

Method
ReferenceObject()

A ReferenceObject is used to pass values into BPUI tag elements by reference in order to bind them to the JavaScript controller. A ReferenceObject can be set or Initialized from a value, a single BPObject or a BPCollection. All values will automatically assign to BPUI tags reference the variable in the “value” attribute of the Tag. The Tags for binding are BPUI.InputField, BPUI.OutputField, BPUI.EmbeddedList, and BPUI.Grid.

Methods get() return value from ReferenceObject. The value have same type and consist all changes which is made by user throw BPUI tags

set() set value \ BPObject or BPCollection in ReferenceObject.
Attributes No attributes

Example

JSON Text Example

-------------------------------------------JavaScript---------------------------------------
// Manually load set of option values using a JSON array
var radioOptions = new BPUI.ReferenceObject({value:"value 1",values:["value 1","value 1","value 3"]});

-------------------------------------------HTML----------------------------------------------
<BPUI.InputField variable={radioOptions} type="RADIO_GROUP_VERTICAL" label="My Radio Options"/>

Single BPOBject Example

-------------------------------------------JavaScript---------------------------------------
//Declare a reference object to bind to the BPUI tag
var billingProfile = new BPUI.ReferenceObject();
// Retrieve the Billing Profile and load the reference object
billingProfile.set(BPConnection.BillingProfile.retrieveFiltered("AccountId = " + BPSystem.nodeKey ).single());

-------------------------------------------HTML----------------------------------------------
<BPUI.InputField name="BillingProfileEmail" variable={billingProfile} field="Email"/>

BPCollection Example

-------------------------------------------JavaScript---------------------------------------
//Declare a reference object to hold the Invoice and Line Items and bind them to the UI
window.activities = new BPUI.ReferenceObject();

//create a query for the Activities associated with the selected invoice
var bpql = "select ProductId,"
+ "SubscriptionFromDate, "
+ "SubscriptionToDate, "
+ "RatedAmount,"
+ "ActivityDate, "
+ "Quantity, "
+ "Rate, "
+ "RateOverride "
+ "from Activity "
+"where InvoiceId = "+invoiceId
+" order by ActivityDate";

//Load the Activities ReferenceObject from the database
activities.set(BPConnection.Activity.query(bpql).collection());

-------------------------------------------HTML----------------------------------------------
<BPUI.Divider Name="ActivityDiv">Invoice Line Items</BPUI.Divider>
<BPUI.Panel style ={{width: 900 + "px"}}>
<BPUI.PanelRow>
<BPUI.PanelRowColumn colSpan="4">
<BPUI.EmbeddedList variable={activities} name="activities" width="100%"
onCellBlur={calculateAmount} onAdd={addActivity}>
<BPUI.TableColumn name="ActivityDate" type="DATE_SELECTOR"
displayTransform={formatDate} index="1" label="Service Date" />
<BPUI.TableColumn name="ProductId" index="2" label="Product"/>
<BPUI.TableColumn name="Quantity" index="3" label="Quantity"/>
<BPUI.TableColumn name="Rate" index="4" label="Rate"/>
<BPUI.TableColumn name="RatedAmount" index="5" label="Amount" editable="false"/>
</BPUI.EmbeddedList>
</BPUI.PanelRowColumn>
</BPUI.PanelRow>
</BPUI.Panel>

 

BPUI Class Attributes

 

Attribute Name Data Type Description
viewMode String The current view mode of the Standard User Interface. 
  • R – Read Mode
  • E – Edit Mode
  • N – New Mode
  • L – List Mode

 

Data Access

The Web toolkit’s JavaScript library provides simple yet robust access to application and business data. The Toolkit methods leverage the native REST API so anything that is available to the REST API is included in the Toolkit. The Primary classes used for data Access are as follows:

BPObject: Abstract class from which all base, data objects are extended

BRMAggregate: Object type used for Aggregate Query results where actual BPObject and field types no longer apply due to column aliasing and aggregation in column functions such as SUM, COUNT, AVG, etc.. The BRMAggregate Object consists of simple name/value pairs of column aliases and the associated value. They values are all returned as strings and must be cast to the appropriate data type after retrieval.

BPConnection: Used for all database interaction and DML.

BPCollection: Intelligent collection of BPObjects. Part of the query and retrieve response objects and also used for bulk DML.

All data access is done via the BPConection object. In order to utilize the BPConnection methods you must call BPSystem.initialize() at the top of your JavaScript controller. The BPConnection methods offer synchronous as well asynchronous methods for accessing data for a more real-time UI experience.

 

 

BPConnection Class Methods

Method
addNew()

Used to add a new element to a collection.

Parameters element
position
Return Value Type: void

Example

//Declare a global activities collection reference variable
         window.activities = new BPUI.ReferenceObject();

//Load the Activities from the database
BPConnection.Activity.queryAsync("select Quantity,ActivityDate,Rate,RatedAmount,ProductId 
                                +”  from Activity where rownum<20 and “
                                +” AccountObj.Id="+value).collection().done(
                                    function(collection) {
               activities.set(collection);
              });

function addRows(value,field,entity) {

   // add 5 new elements to activity collection. elements are empty
   var i = 0;
   while (i<5) {
       activities.get().addNew({});
       i++;
   }
   BPActions.refreshState("activities");
}

Method
query(String bpqlStatement)

Method for synchronously querying data using a BPQL (Billing Platform Query Language) string.

Parameters bpqlStatement
The BPQL statement to execute
Return Value Type:
.raw: JSON String
.single: A single BPObject instance. This will trhow an error if there is more than one element returned.
.collection: A collection of BPObjects in a BPCollection collection object

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var bpql = "select BillingProfileId, "
                      + "Attachment1, "
                      + "Attachment2, "
                      + "Attachment3, "
                      + "Status, "
                      + "ApprovalStatus, "
                      + "ManualCloseApprovedFlag, "
                      + "BillingProfileObj.Id, "
                      + "BillingProfileObj.Email, "
                      + "BillingProfileObj.AccountObj.Id, "
                      + "BillingProfileObj.AccountObj.Name, "
                      + "BillingProfileObj.AccountObj.Status, "
                //Invoice Line Items (AKA Activity)
                      + "(select ProductId,"
                              + "SubscriptionFromDate, "
                              + "SubscriptionToDate, "
                              + "RatedAmount,"
                              + "ActivityDate, "
                              + "Quantity, "
                              + "Rate, "
                              + "RateOverride "
                         + "from Activity.InvoiceObj "
                        + "order by ActivityDate) "
                + "from INVOICE where Id=" + invoiceId;

//Execute a query to retrievethe single instance of the Invoice and associated Activity Items
var invoice = BPConnection.Invoice.query(bpql).single();

//Execute a query to retrievethe a collection of the Invoices and associated Activity Items
var invoiceCollection = BPConnection.Invoice.query(bpql).collection();

//Execute the query to return a JSON string representation of the query result
var jsonCollection = BPConnection.Invoice.query(bpql).raw();

Method
queryAsync(String bpqlStatement)

Method for asynchronously querying data using a BPQL (Billing Platform Query Language) string. Asynchronous operations utilize the “Promise” JavaScript infrastructure providing built-in done() and error() callback functions.

Parameters bpqlStatement
The BPQL statement to execute
Return Value Type:
.raw: JSON String
.single: A single BPObject instance. This will trhow an error if there is more than one element returned.
.collection: A collection of BPObjects in a BPCollection collection object

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var bpql = "select BillingProfileId, "
                      + "Attachment1, "
                      + "Attachment2, "
                      + "Attachment3, "
                      + "Status, "
                      + "ApprovalStatus, "
                      + "ManualCloseApprovedFlag, "
                      + "BillingProfileObj.Id, "
                      + "BillingProfileObj.Email, "
                      + "BillingProfileObj.AccountObj.Id, "
                      + "BillingProfileObj.AccountObj.Name, "
                      + "BillingProfileObj.AccountObj.Status, "
                //Invoice Line Items (AKA Activity)
                      + "(select ProductId,"
                              + "SubscriptionFromDate, "
                              + "SubscriptionToDate, "
                              + "RatedAmount,"
                              + "ActivityDate, "
                              + "Quantity, "
                              + "Rate, "
                              + "RateOverride "
                         + "from Activity.InvoiceObj "
                        + "order by ActivityDate) "
                + "from INVOICE where Id=" + invoiceId;

//Execute a query to retrievethe single instance of the Invoice and associated 
//Activity Items Asynchronously
var invoicePromise = BPConnection.Invoice.queryAsync(bpql).single();
invoicePromise.done(function(invoice) {
    // process invoice
}).fail(function(errors) {
    // process errors
});

//Execute a query to retrieve a collection of the Invoices and associated associated 
//Activity Items Asynchronously

var invoiceCollectionPromise = BPConnection.Invoice.queryAsync(bpql).collection();
invoiceCollectionPromise.done(function(invoiceCollection) {
    // process invoice collection
}).fail(function(errors) {
    // process errors
});

//Execute the query to return a JSON string representation of the query result asynchronously
var jsonCollectionPromise = BPConnection.Invoice.queryAsync(bpql).raw();
jsonCollectionPromise.done(function(string) {
    // process string
}).fail(function(errors) {
    // process errors
});

Method
retrieve(String objectId)

Method for retrieving an instance of an object by its Id. The resulting object will only contain fields directly related to the referenced object – Parent and child collections are not implicitly included in the retrieve results.

Parameters objectId
The primary key of the referenced object
Return Value Type: BPObject

Example

 //retrieve the BillingProfile Object by Id
var billingProfile = BPConnection.BillingProfile.retrieve(“19897645”);

Method
retrieveAsync(String objectId)

Asynchronous method for retrieving an instance of an object by its Id. The resulting object will only contain fields directly related to the referenced object – Parent and child collections are not implicitly included in the retrieve results. Asynchronous operations utilize the “Promise” JavaScript infrastructure providing built-in done() and error() callback functions.

Parameters objectId
The primary key of the referenced object
Return Value Type: BPObject

Example

 //Asynchronously retrieve the BillingProfile by Id
var billingProfilePromise = BPConnection.BillingProfile.retrieveAsync(“19897645”);
billingProfilePromise.done(function(billingProfile) {
// process billingProfile
}).fail(function(errors) {
// process errors
});

Method
retrieveFiltered(String bpqlFilter)

Method for retrieving collection of a specified object type by its Id. The resulting objects will only contain fields directly related to the referenced object – Parent and child collections are not implicitly included in the retrieve results.

Parameters bpqlFilter
equivalent to a bpql “where” clause using in the standard, BPQL query language. The “WHERE” key word is omitted
Return Value Type:
.raw: JSON String
.single: A single BPObject instance. This will trhow an error if there is more than one element returned.
.collection: A collection of BPObjects in a BPCollection collection object

Example

//retrieve a single BillingProfile Object by related Account Id
var billingProfile = BPConnection.BillingProfile.retrieveFiltered(“AccountId = 100213”).single();

//retrieve a collection of BillingProfile Objects whose Parent Account Names start with “ATT”
var billingProfiles
= BPConnection.BillingProfile.retrieveFiltered(“AccountObj.Name like ‘ATT%’”).collection();

//retrieve a JSON string representation of a BillingProfile filtering on AccountId
var jsonBillingProfile = BPConnection.BillingProfile.retrieveFiltered(“AccountId = 100213”).raw();

Method
retrieveFilteredAsync(String bpqlFilter)

Asynchronous method for retrieving collection of a specified object type by its Id. The resulting objects will only contain fields directly related to the referenced object – Parent and child collections are not implicitly included in the retrieve results. Asynchronous operations utilize the “Promise” JavaScript infrastructure providing built-in done() and error() callback functions.

Parameters bpqlFilter
equivalent to a bpql “where” clause using in the standard, BPQL query language. The “WHERE” keyword is omitted
Return Value Type:
.raw: JSON String
.single: A single BPObject instance. This will throw an error if there is more than one element returned.
.collection: A collection of BPObjects in a BPCollection collection object

Example

//retrieve a single BillingProfile Object by related Account Id
var billingProfilePromise = BPConnection.BillingProfile.retrieveFilteredAsync(“AccountId = 100213”).single();


billingProfilePromise.done(function(billingProfile) {
// process billingProfile
}).fail(function(errors) {
// process errors
});
//retrieve a collection of BillingProfile Objects whose Parent Account Names start with “ATT”
var billingProfilesPromise
= BPConnection.BillingProfile.retrieveFilteredAsync(“AccountObj.Name like ‘ATT%’”).collection();

billingProfilesPromise.done(function(billingProfilesCollection) {
// process billingProfilesCollection
}).fail(function(errors) {
// process errors
});

//retrieve a JSON string representation of a BillingProfile filtering on AccountId
var jsonBillingProfile = BPConnection.BillingProfile.retrieveFilteredAsync(“AccountId = 100213”).raw();

 

 
 

BPCollection Class Methods

Method
find(String field, String value)

Returns an array of elements from the collection that match the specified value for the specified field.

Parameters field
the field to search

value
the value to search contained in the specified field
Return Value Type: none

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var selectedProductId = “”;
var bpql = "select ProductId,"
+ "SubscriptionFromDate, "
+ "SubscriptionToDate, "
+ "RatedAmount,"
+ "ActivityDate, "
+ "Quantity, "
+ "Rate, "
+ "RateOverride "
+ "from Activity "
+"where InvoiceId = "+invoiceId
+" order by ActivityDate";

//Execute a query to retrieve the a collection of the Activity Items and associated Invoice
var activities = BPConnection.Activity.query(bpql).collection();

//Find the Invoice Activity Item associated with the specified Product Id
var activityItem = activities.find(“ProductId”,selectedProductId);

Method
forEach (function)

Used to iterate through the elements in a collection. Uses a function to execute on each element in the collection

Parameters function(element, index, array)
function used to process each element in the collection.
The function can have one to three parameters function (element, index, array)
element – current element in array
index - current index of the collection
array – the entire whole array or collection of elements
Return Value Type: none

Example

//retrieve a collection of BrmAggregate via query and add them to an array
BPConnection.BrmAggregate.query("Select ProductObj.Name, "
                                +     " Sum(RatedAmount) as RatedAmountSum "
                                +" from ACTIVITY "
                                +" where InvoiceObj.BillingProfileObj.AccountObj.Id= "+ accountId
                                +" group by ProductObj.Name"
                                ).collection().forEach (function(el){
                                        data.addRow([el.Name, parseFloat(el.RatedAmountSum)]); 
                                          });

Method
list()

Returns the array of elements in collection.

Parameters none
Return Value Type: BPObject[]

Example

//get the list of Account elements returned from the Account query
var accounts = BPConnection.Account.retrieveFiltered("Id<10600").collection().list();

//retrieve the first element in a list of accounts
var accounts = BPConnection.Account.retrieveFiltered("Id<10600").collection().list()[0]; 

Collection of Objects
updatedelements

Subset of elements that have changed in a specified collection.

Parameters none
Return Value Type: BPCollection

Example

//retrieve a list Accounts
var accounts = BPConnection.Account.retrieveFiltered("Id<10600").collection();

//update the names of the first two accounts
accounts.list()[0].name = “FOO”;

accounts.list()[1].name = “BAR”;

//update only the elements that have changed in the collection of accounts
BPConnection.Account.update(accounts.updatedelements);

Method
create(Boolean allOrChanged)

Allows you to create a collection of like records with a single call.

Parameters allOrChanged
(Optional) Insert all items in the collection or only those that have changed since being added to the collection
Return Value Type: void

Example

//create an empty list of Invoice Activity Objects for user input
var activities = new BPUI.ReferenceObject();
activities.set(BPSystem.toBPCollection([{},{},{}],new Activity()));

//Insert the New Activities
activities.get().create(true);

Method
delete(Boolean allOrChanged)

Allows you to delete a collection of like records with a single call.

Parameters allOrChanged
Optional: delete all items in the collection or only those that have changed since being added to the collection
Return Value Type: void

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var selectedProductId = “”;
var bpql = "select ProductId,"
                 + "SubscriptionFromDate, "
                 + "SubscriptionToDate, "
                 + "RatedAmount,"
                 + "ActivityDate, "
                 + "Quantity, "
                 + "Rate, "
                 + "RateOverride "
           + "from Activity "
           + "where InvoiceId = "+invoiceId
           + " order by ActivityDate";

//Execute a query to retrieve the a collection of the Activity Items and associated Invoice
var activities = BPConnection.Activity.query(bpql).collection(); 

//Delete the Activities
activities.get().delete(true);

Method
undelete(Boolean allOrChanged)

Allows you to undelete a collection of like, deleted records with a single call (recovers recently deleted items from the recycle bin).

Parameters allOrChanged
undelete all items in the collection or only those that have changed since being added to the collection
Return Value Type: void

Example

//Construct the BPQL Query to retrieve Invoice Activities
var selectedProductId = “”;
var bpql = "select ProductId,"
                + "SubscriptionFromDate, "
                + "SubscriptionToDate, "
                + "RatedAmount,"
                + "ActivityDate, "
                + "Quantity, "
                + "Rate, "
                + "RateOverride "
          + "from Activity "
          + "where InvoiceId = "+invoiceId
          + " order by ActivityDate";

//Execute a query to retrieve the a collection of the Activity Items and associated Invoice
var activities = BPConnection.Activity.query(bpql).collection(); 

//Delete the Activities
activities.get().delete();

//undelete the Activities
activities.get().undelete();

Method
update(Boolean allOrChanged)

Allows you to update a collection of like records with a single call.

Parameters allOrChanged
Optional: update all items in the collection or only those that have changed since being added to the collection
Return Value Type: void

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var selectedProductId = “”;
var bpql = "select ProductId,"
                + "SubscriptionFromDate, "
                + "SubscriptionToDate, "
                + "RatedAmount,"
                + "ActivityDate, "
                + "Quantity, "
                + "Rate, "
                + "RateOverride "
           + "from Activity "
           + "where InvoiceId = "+invoiceId
           + " order by ActivityDate";

//Execute a query to retrieve the a collection of the Activity Items and associated Invoice
var activities = BPConnection.Activity.query(bpql).collection(); 
    
//Update the Activities
activities.get().update(false);

Method
upsert(String keyField, Boolean allOrChanged)

Allows you to upsert a collection of like records with a single call. The upsert will either update or insert records based on a specified key field and associated value. If the specified Key value is present, the record will be updated. If not, the record will be created and the Id returned to the collection.

Parameters keyField
The name of the field to use as the upsert Key

allOrChanged
(Optional) upsert all items in the collection or only those that have changed since being added to the collection
Return Value Type: void

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var selectedProductId = “”;
var bpql = "select ProductId,"
                 + "SubscriptionFromDate, "
                 + "SubscriptionToDate, "
                 + "RatedAmount,"
                 + "ActivityDate, "
                 + "Quantity, "
                 + "Rate, "
                 + "RateOverride "
           + "from Activity "
           + "where InvoiceId = "+invoiceId
           + " order by ActivityDate";

//Execute a query to retrieve the a collection of the Activity Items and associated Invoice
var activities = BPConnection.Activity.query(bpql).collection(); 
    
//Update the Activities
activities.get().upsert(“Id”, false);

BPObject Class Methods

The BPObject class is an abstract template for every Entity in your application. The BPObject class comes with all of the DML operations needed to manage data in the system. The primary DML methods for every Entity along with descriptions and examples are listed below.

Method
create()

Method for creating a new record.

Parameters none
Return Value Type: void
populates the Id of the Record that was created.

Example

//create an new Account Object
var account = new Account();

account.Name = “TEST ACCOUNT”;

//Insert the New Account
account.create();

Method
delete()

Method for deleting a single record.

Parameters none
Return Value Type: void

Example

//retrieve an account for deletion
var account = BPConnection.Account.retrieve(“89767”);

//Delete Account
account.delete();

Method
undelete()

Method for undeleting a single record (recovering it from the recycle bin).

Parameters none
Return Value Type: void

Example

//retrieve an account for deletion
var account = BPConnection.Account.retrieve(“89767”);

//Delete Account
account.delete();

//Undelete the Account
account.undelete();

Method
update()

Method for update a single record.

Parameters none
Return Value Type: void

Example

//retrieve an account for deletion
var account = BPConnection.Account.retrieve(“89767”);
//Modify the account’s Name
account.Name = “AccTest”;
//Update Account
account.update();

Method
upsert(String keyField)

Method for updating or inserting a single record based on the existence of a specified key. The upsert method will either update or insert records based on a specified key field and associated value. If the specified Key value is present in the system, the record will be updated. If not, the record will be created and the Id returned to the object. If no key field is specified the system uses the standard, Id field as the upsert key.

Parameters keyField
The name of the field to use as the upsert Key.
Return Value Type: void

Example

 //retrieve an account for deletion
var account = BPConnection.Account.retrieve(“89767”);

//modify the the Account’s Name
account.Name = “AccTest”;

//upsert uses the Id by default. If no arguments are supplied to the upsert operation then the 
//framework assumes that the Id is the upsert key. This will simply update the selected record.
account.upsert();
    
//modify the account’s name
account.Name = “AccTest123”;

//The Account Object’s Name field is a one of the systems built in, “external” Keys. 
//Here we use the Name field as the Upsert Key. In this case, if there is an existing Account with 
//the name = “AccTest123”, then this record (not the currently selected one) will be updated. If not,
//a new Account record will be created with all the attributes of the selected account but with the 
//Name “AccTest123”.
account.upsert(“Name”);

 

 

BrmAggregate Class

The BrmAggregate Object is used for Aggregate Query results where actual BPObject and field types no longer apply due to column aliasing and aggregation in functions such as SUM, COUNT, AVG, etc.. The BRMAggregate Object consists of simple name/value pairs of column aliases and the associated value. They values are all returned as strings and must be cast to the appropriate data type after retrieval.

Method
query(String bpqlStatement)

Method for synchronously querying data using a BPQL (Billing Platform Query Language) string.

Parameters bpqlStatement
The BPQL statement to execute
Return Value Type:
.raw: JSON String
.single: A single BPObject instance. This will trhow an error if there is more than one element returned.
.collection: A collection of BPObjects in a BPCollection collection object

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var bpql = "Select ProductObj.Name, "
                +" Sum(RatedAmount) as RatedAmountSum "
         +" from ACTIVITY "
         +" where InvoiceObj.BillingProfileObj.AccountObj.Id= "+ accountId
         +" group by ProductObj.Name";

//Execute a query to retrievethe single instance of the Invoice and associated Activity Items
var result = BPConnection.BrmAggregate.query(bpql).single();

//Execute a query to retrievethe a collection of the Invoices and associated Activity Items
var results = BPConnection.BrmAggregate .query(bpql).collection();

//Execute the query to return a JSON string representation of the query result
var jsonResult = BPConnection.BrmAggregate.query(bpql).raw();

Method
queryAsync(String bpqlStatement)

Method for asynchronously querying data using a BPQL (Billing Platform Query Language) string. Asynchronous operations utilize the “Promise” JavaScript infrastructure providing built-in done() and error() callback functions.

Parameters bpqlStatement
The BPQL statement to execute
Return Value Type:
.raw: JSON String
.single: A single BPObject instance. This will trhow an error if there is more than one element returned.
.collection: A collection of BPObjects in a BPCollection collection object

Example

//Construct the BPQL Query to retrieve Invoices and their associated line items
var bpql = "Select ProductObj.Name, "
             + " Sum(RatedAmount) as RatedAmountSum "
         +" from ACTIVITY "
         +" where InvoiceObj.BillingProfileObj.AccountObj.Id= "+ accountId
         +" group by ProductObj.Name";

//Execute a query to retrievethe single instance of the Invoice and associated 
//Activity Items Asynchronously
var resultPromise = BPConnection.BrmAggregate.queryAsync(bpql).single();

//With Async queries we have access to the “done” and “fail” callback 
//functions built into the “promise” pattern for asynchronous, JavaScript processing
resultPromise.done(function(invoice) {
// process invoice
}).fail(function(errors) {
// process errors
});

//Execute a query to retrieve a collection of the Invoices and associated associated 
//Activity Items Asynchronously
var resultCollectionPromise = BPConnection.BrmAggregate.queryAsync(bpql).collection();
resultCollectionPromise.done(function(invoiceCollection) {
    // process invoiceCollection
}).fail(function(errors) {
    // process errors
});

//Execute the query to return a JSON string representation of the query result asynchronously
var jsonResultPromise = BPConnection.BrmAggregate.queryAsync(bpql).raw();
jsonResultPromise.done(function(string) {
    // process invoice collection string
}).fail(function(errors) {
    // process errors
});
Have more questions? Submit a request

Comments

Powered by Zendesk