How to use External Data in a calculated field

Help!  We have a customer requirement to use data from an External system and Sage CRM to calculate the available credit of a customer for order processing.

The Sage CRM orders are converted to invoices and imported into the external system.  Therefore, the calculation includes quotes and orders that HAVE NOT yet been converted and imported. 

We added a panel to the company summary screen to display this information. We have also added buttons to the summary screen to allow users to create a quote or order from the company summary screen.  This is what the panel looks like.

Sorry that is not a very good image.  This is what is represented there

Credit Limit  -   Outstanding Amount  -   Quotes  -   Orders  -   Invoices = Available Credit

I have added the calculation for Available Credit to a view which is used for the panel.  Therefore, this data is pulled fresh each time the company summary screen appears.

I am having two issues with the calculation and I am hoping that someone can push me in the right direction to resolve these as this solution is an import and time saving piece of their order process.

My first issue is with the amounts from the external database.  They are Credit Limit and Outstanding Amount.  If I include these fields in my calculation, my available credit comes back as 0 when there should be a value.  The fields are numeric fields.  However, I have CAST them as Money in my view.  However, I still get a zero.  What can I do to get the amounts properly included in my calculation.

My second issue is with the amounts from CRM.  If one of the amounts for Quotes, Orders or Invoices is 0, my Credit Limit is returning zero when there should be a value.

If you can see the screen shot, you will see that the following data i populated there..

Credit Limit  -   Outstanding Amount  -   Quotes  -   Orders  -   Invoices = Available Credit

100000.00  -         0                           -    560.49   -  25,932.79  -   0        =  -26,493.28

This is what I have in my view currently in order to get the -26,493.28 to appear.  This is missing the fields that cause a 0 to be returned.

(-t3.quot_nettamt - t4.orde_nettamt) as comp_availablecredit,

Has anyone else attempted to combine fields from an external database with CRM fields in a calculation and came up with the correct values?

If so, can you let me know what I might need to do to get this to work.

Any assistance is greatly appreciated.  Thanks!

  • I had tried numeric and CONVERT as Money, the last thing I tried was float.

    The data type in the external system for its fields is numeric.  However, the data type in Sage CRM for its fields is currency.

    It does not seem to matter if I CAST, COALESCE or CONVERT.  The system still does not seem to like the zero values.

    This might make sense if I was dividing..but I am subtracting.  Weird.

    PS.  I hope the Flat Stanley reference made sense.  Your icon looks like Flat Stanley.  Also not very funny if you don't know who Flat Stanley is.  Flat Stanley is a book kids read in elementary school. As a project, they create a Flat Stanley and take him on adventures.  Your icon looks like the one my son created. Stuck out tongue winking eye

  • Ahhh.  Ok that helps explain it.  I think I can fix that by putting the calculation in a view that uses the view with the "as" reference.  Going to try that now.  Fingers crossed.

  • Although I got this to work in Management Studio by creating another view and using that view to do the calculation.  However, it does not work when I place those views in Sage CRM.  I don't get any errors in the system.  However, when you pull up the screen that contains the calculated field, the value is zero.

    When I run that same view in SQL, a value is returned.  Does anyone know why that would be?

  • Looking at your view I would suggest trying the link to the external table as an OUTER APPLY 

    e.g. SELECT company.*, ExtTable.* 

    FROM Company 
    OUTER APPLY (SELECT ISNULL(FieldA,0), ISNULL(FieldB,0)
                              FROM ExternalTable
                              WHERE comp_companyID = MasterKeyInExternalTable) AS ExtTable

  • I don't think I have ever used OUTER APPLY.  Does that change the way the CRM interprets the query?

    If I run the query I have in Management Studio, I get a value returned.  However, when the query goes into Sage CRM, the value is displayed as zero.

    In CRM, I think it might be that the field is currency...but I am not sure.