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..
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!
Update to this. It appears that the calculation is correct if the value in the field is not 0.00.
I updated my view to the following and got 73,506.72 which would be correct.
(CCRDLMT-t3.quot_nettamt - t4.orde_nettamt) as comp_availablecredit,
Therefore, I only have one issue and it is the zero balances. If I update my view to the following...
(CCRDLMT - CTARTOT-t3.quot_nettamt - t4.orde_nettamt) as comp_availablecredit, the available credit returned is zero.
The value for CTARTOT is actually NULL rather than zero as displayed on the screen. I am guessing that is my issue.
Therefore, I need to figure out how to replace NULL with zero in my view.
If anyone knows how to do this, I would greatly appreciate assistance.
Thank you for looking! :-)
You can use 'isnull' within the view to treat any null value as a 'zero'. e.g.
select Oppo_Description, isnull(Oppo_Total,0) from Opportunity
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.
I got this sorted out, my final view looks like this...
CREATE VIEW vCompanyCreditCalcASSelectISNULL(CCRDLMT,0)- ISNULL(CTARTOT,0)- ISNULL(quot_netamtnum,0)- ISNULL(orde_netamtnum,0) - ISNULL(invo_netamtnum,0) AS comp_calculatedcredit,*from vCompanyCredit
I greatly appreciated the assistance!