Table Scripting: Difference between revisions
From Sage CRM Knowledge Base
No edit summary |
No edit summary |
||
| Line 25: | Line 25: | ||
Ref: https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2011/03/07/setting-or-updating-date-fields-using-a-table-level-script.aspx | Ref: https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2011/03/07/setting-or-updating-date-fields-using-a-table-level-script.aspx | ||
---- | |||
Comparing previous values | |||
Within the UpdateRecord method stub you would first query the current record using | |||
var crec=CRM.FindRecord("agreement",WhereClause); | |||
You would then compare values as in | |||
if (crec("comp_name")!=Values("comp_name"))... | |||
For date fields you have to create a Date object | |||
var c_comp_renewaldate = new Date(crec("comp_renewaldate")); | |||
var v_comp_renewaldate = new Date(Values("comp_renewaldate")); | |||
and then call the getDate() method of the Date object to do the comparison. | |||
You cannot compare the date objects as it will never match | |||
if (c_comp_renewaldate.getDate() != v_comp_renewaldate.getDate())... | |||
Revision as of 11:28, 8 February 2013
This sample shows you how to check if the field has been changed from one value to another
function UpdateRecord()
{
if (Values("case_AssignedUserId")+""=="undefined")
return; //bad update from crm..or field not changed
var CaseRec=CRM.CreateQueryObj("SELECT * FROM Cases WITH (NOLOCK) WHERE " + WhereClause);
CaseRec.SelectSQL();
if (CaseRec("case_assigneduserid")!=Values("Case_AssignedUserId"))
{
ErrorStr="field value has changed from "+CaseRec("case_assigneduserid") +" to "+Values("Case_AssignedUserId");
}
}
Altering CRM dates in Table level scripts
var mydate = new Date();
mydate.setDate(mydate.getDate() +7);
Values("comp_customerstartdate") = mydate.getVarDate();
Comparing previous values
Within the UpdateRecord method stub you would first query the current record using
var crec=CRM.FindRecord("agreement",WhereClause);
You would then compare values as in
if (crec("comp_name")!=Values("comp_name"))...
For date fields you have to create a Date object
var c_comp_renewaldate = new Date(crec("comp_renewaldate"));
var v_comp_renewaldate = new Date(Values("comp_renewaldate"));
and then call the getDate() method of the Date object to do the comparison. You cannot compare the date objects as it will never match
if (c_comp_renewaldate.getDate() != v_comp_renewaldate.getDate())...