Hi,
I'm doing calculation to find remaining day of the membership. Everything looks find except when I set 'DefaultValue', it was not updated at the first time.
For instance, today date = 21 Feb and membership expiry date = 28 Feb so Days remaining should be 7 but it still display the old value (not 7). I need to click refresh then the value is updated.
Here's my code that I put in 'Create Script':
var strCompanyId = CRM.GetContextInfo("Company", "comp_companyId");
var SQLQuery = "SELECT DATEDIFF(day, GETDATE(), comp_enddate) as Value FROM Company WHERE Comp_CompanyId = " + strCompanyId;
var Query = CRM.CreateQueryObj(SQLQuery);
Query.SelectSQL();
if(!Query.eof)
{
var SQLUpd = "UPDATE Company SET comp_remainingday = " + Query("Value") + " WHERE Comp_CompanyId = " + strCompanyId;
var UpdQuery = CRM.CreateQueryObj(SQLUpd);
UpdQuery.ExecSQL();
var strRemainingDay = Query("Value");
DefaultValue = strRemainingDay;
}
else
{
ErrorStr = "No Membership expiry date";
}
I'm very new with sage CRM so anyone has any idea? I've been stuck here for a week now.
Thank you.