While I was working on eScript I came across the method GetMVGBusComp which is one of Best Practices in eScripting and I thought of posting it here. Details about this method below.
Tip 11:Use GetMVGBusComp Method to get the MVG records
As the method name suggests it gets the Business Component of the record that MVG is based on. This is a very helpful Method that would save a several lines of unnecessary code.
For example, we have Accounts and there are Sales Reps associated to each of these accounts. These Sales Reps are based on Position BC. Position BC is the MVG Business Component of Account BC. The requirement is to get all the sales rep associated to the details of all the sales rep associated to this account using eScript. Now a developer who is writing this eScript and not aware of this Method would write an eScript something like this.
- Get Account Row ID
- Get Account Position BC
- Query for Account ID
- Get the corresponding Position Id
- Get Postion BC
- Query for that Postion Id from step 4
- Get Employee details from this Position BC
Instead we could write something like this
- Get Account RowId
- Get all the sales rep records using GetMVGBusComp
- Get Employee details from this Position BC.
Here is the code for your reference.
oAccBC = oAccBO.GetBusComp("Account");
//Get the corresponding Sales Rep Bus Comp — eScript Best practice here.
var oAccPostnBC = oAccBC.GetMVGBusComp("Sales Rep");
//Add search spec to already filtered records
//No Need to get the Sales Rep that are associated to only this account
//The Method already gets sales rep that belongs to only this account
//Do not to use ClearToQuery here.
//You could add more Search Spec if you desire
oAccPostnBC.SetSearchSpec("Position Type","Partner Sales Rep");
oAccPostnBC.ExecuteQuery();
var rAccPostn = oAccPostnBC.FirstRecord();
//Here I am getting all the email Addresses
while(rAccPostn)
{
sEmailAddr = sEmailAddr + oAccPostnBC.GetFieldValue("Active Email"a) + ";";
rAccPostn = oAccPostnBC.NextRecord();
}
Tip 12: Verify Existence of Valid Record after Querying
After you execute the method ExecuteQuery() make sure to check if there is at least one valid record that you desire otherwise it might result in an invalid scripting. For example in the code above before I get the email addresses I check there is a valid record returned from my ExecuteQuery Method using the while statement. Otherwise GetFieldValue on the BC record will behave weird by throwing error. Also you could use IF statement to check if you expect the result to have just one record.
Hope this post has helped you. If you any tips that you would like to share, please email me using the Participate form.
Related posts(Auto Generated):




