githubbob42 / mingle2github2

0 stars 1 forks source link

Support JS Bitwise Operators (Setup a price book for multiple offices) #4112

Closed githubbob42 closed 8 years ago

githubbob42 commented 8 years ago

Mingle Card: 4446 Narrative

This customer (Key Energy) has a price book that should only be used on jobs tied to a particular office. However, in this case, it is not 1 office but 8 offices. With our current functionality, in the static resource FX_Mobile_Filters, a price book can only be tied to a single account.

    "FX5\_\_Price\_Book\_\_c": {
        "FX5\_\_Job\_\_c.FX5\_\_Price\_Book\_\_c": {
            "predicate": "(ISNULL($Source.FX5\_\_CustomerAccount\_\_c) || _**$Source.FX5\_\_CustomerAccount\_\_c==FX5\_\_Price\_Book\_\_c.FX5\_\_Account\_\_r.Id**_ || ISNULL(FX5\_\_Price\_Book\_\_c.FX5\_\_Account\_\_r.Id)) && (ISNULL($Source.FX5\_\_Office\_\_c) || $Source.FX5\_\_Office\_\_c==FX5\_\_Price\_Book\_\_c.FX5\_\_Office\_\_r.Id || ISNULL(FX5\_\_Price\_Book\_\_c.FX5\_\_Office\_\_r.Id)) && (ISNULL($Source.FX5\_\_Segment\_\_c) || $Source.FX5\_\_Segment\_\_c==FX5\_\_Price\_Book\_\_c.FX5\_\_Segment\_\_c || ISNULL(FX5\_\_Price\_Book\_\_c.FX5\_\_Segment\_\_c))"
        }
    },

For example, our customer has offices in Karnes City, Kenedy and Hobson. Only these offices should be able to use the Eagle Ford 2016 price book.

In this case, when a field user selects one of these offices, then they should have the Eagle Ford 2016 price book as an option when creating a new job. If the field user selects a different office, then the Eagle Ford 2016 price book should not be an available option.

Alternative Narrative

We also have scenarios where a customer’s top level account is listed in the Account object.  For example, Exxon is listed as a customer.  Under that Account record we have several sub-customers such as Exxon USA, Exxon Chemical, Exxon Refining and many others. In the case of our Exxon 2016 Turnaround price book, we have negotiated that for Jobs that are done for Exxon Chemical and Exxon Refining.  Any Job setup for either of those two Accounts should be able to use that price book, but we do not want to copy that price book due to data management issues.  Ideally, we could setup a way to associate a price book with multiple offices, customers and other custom attributes such as line of business, marketplace, etc.   

**Acceptance Criteria**

Support the following operators in validations and filters

| | |
|-|-|

   |[Bitwise AND](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_AND)|
|`a & b`|
|Returns a one in each bit position for which the corresponding bits of both operands are ones.|

   |[Bitwise OR](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_OR)|
|`a | b`|
|Returns a one in each bit position for which the corresponding bits of either or both operands are ones.|

   |[Bitwise XOR](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR)|
|`a ^ b`|
|Returns a one in each bit position for which the corresponding bits of either but not both operands are ones.|

   |[Bitwise NOT](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_NOT)|
|`~ a`|
|Inverts the bits of its operand.|

Something like this should work in the filters:

window.FX_Mobile_Filters = {
               "FX5__Price_Book__c": {
                              "FX5__Job__c.FX5__Price_Book__c": {
                                             "predicate":"(($Source.FX5__Office__r.Bitwise_Value__c | FX5__Price_Book__c.Bitwise_Value_Rollup__c) == FX5__Price_Book__c.Bitwise_Value_Rollup__c)"
                              }
               }
}

Analysis

Bitwise operators need to be added to formula-force to support this:

Note: & and ^ can’t ever be supported as operators because they are in conflict with salesforce formulas: https://help.salesforce.com/htviewhelpdoc?id=customize_functions.htm&siteLang=en_US

& is used for string concatenation

^ is use for exponents

4 | 14 = 14

4 | 0 = 4

4 | -1 = -1

4 | null = error

‘a’ | ‘b’ = error

‘4’ | 14 = error

Related Stories

Tasks

{{table query: SELECT Number, Name, Owner, 'Task Status' WHERE Type = Task and Story = THIS CARD}}

Defects

{{ table query: SELECT Number, Name, Owner, 'Status' WHERE Type = Defect and 'Related Story' = THIS CARD }}

Test Plan

This is formula-force PR #5 and alpine-mobile PR #2028

When testing, set your mobile version to 4.0.1.pr2028

Extended Narrative

This functionality can easily be configured in a FieldFX SFDC org if Mobile provides support for native JavaScript bitwise operators.  The implementation manager will do the following…   Assign (via apex trigger) each Office record a value which will be a power of 2.  A new object will be created to associate a Price Book to one or more Offices.  Using a Rollup Summary Field we will add up the bitwise power of 2 value for all Offices ties to a Price Book.   When the Mobile user selects an office for a job being newly created and then hits the Price Book filter, we will configure a JSON filter that takes the selected office’s value and then performs a BITWISE OR against the price book’s rolled up bitwise value and compare that value to the price book’s bitwise value.  If these two values are true, the filter will evaluate to true thereby including the price book in the selection list.  

Therefore, we need Mobile JSON filters to support the native bitwise operators.  For example, we need it to be able to handle the following…

4 | 14 == 14 would yield TRUE

as in…

window.FX_Mobile_Filters = {
               "FX5__Price_Book__c": {
                              "FX5__Job__c.FX5__Price_Book__c": {
                                             "predicate":"(($Source.FX5__Office__r.Bitwise_Value__c | FX5__Price_Book__c.Bitwise_Value_Rollup__c) == FX5__Price_Book__c.Bitwise_Value_Rollup__c)"
                              }
               }
}

githubbob42 commented 8 years ago

Feature: #3841 Guided Pricing - Hierarchical Price Books (Mingle)

githubbob42 commented 8 years ago

Pull Request #5