Occasionally we need to be able to correct data that has been submitted to bring it within tolerance. An example of this maybe where someone has chosen a customer credit limit level that is too high and we need to change this to the maximum allowed value based on the customer current outstanding orders. We can make this change using the table level scripts.

Table Level scripts allow us to look at any of the existing data in the system and implement the business rules we need. The key thing that enables us to bring data within tolerance is that the Values() collection in tablelevel scripts is addressable. We can change or overwrite the inbound values to what we need them to be.

Another example of this maybe where we need to ensure that when an opportunity is re-assigned from a user in one team, to a user in another team, that the opportunity is also moved to the correct new team. The opportunity should be assigned to the team to which the new user belongs. We need to get round the problem of users reassigning opportunities against the incorrect teams but correct users.

This snippet of code shows how this can be done in the UpdateRecord event function:

function UpdateRecord()

{

if (eWare.GetContextInfo("opportunity","oppo_assigneduserid")!=Values("oppo_assigneduserid"))
{
var userRecord = eWare.FindRecord("user","user_userid="+Values("oppo_assigneduserid"));
Values("oppo_channelid") = userRecord.user_primarychannelid;
}

}


The trick here is spotting when the assigned user has changed. The GetContextInfo() method returns the originally assigned user and the Values() collection contains the inbound userid data. When they are different, the record has been reassigned.