UNPKG

dynamicsnode

Version:

Create simple scripts to interact with Dynamics CRM using Node.js

75 lines (74 loc) 3.92 kB
export declare class DataTable { name: string; rows: Array<any>; /** Default constructor * @class DataTable * @classdesc Represents a DataTable object. Contains methods to save and load the row values from a file. */ constructor(name?: string, rows?: Array<any>); /** * Callback that receives a row of a data table and returns a value for a column * @callback DataTable~lookupCallback * @param {object} row Object containing the values of a row * @return {object} The value to apply to a specific column of that particular row */ /** Method to convert all the existing values in a column. * Iterates through all the existing rows, and for every value in the specified column calls to the specified callback method. * Then, the returning value will be applied to the column. * The idea behind this functionality is that you can resolve the lookup data that you may have in a DataTable, before sending * those values to CRM. * For example, you may want to load a list of contacts, and you want to associate your contacts to existing parent accounts. * What you can do, is use the phone number on the contact to try to find the parent account of the contact. * @param {string} columnName Name of the column which values are going to be updated * @param {DataTable~lookupCallback} updater Function that will process every record in the Table. * @method DataTable#lookup * @example <caption>Lookup using simple values</caption> * var dt = new DataTable(); * dt.rows.push({val1:1,val2:2}, * {val1:2,val2:2}); * dt.lookup('val1',row=>++row.val1); * console.log(dt.rows[0].val1); // prints out 2 * console.log(dt.rows[1].val1); // prints out 3 * @example <caption>Find the parent account of a contact using the phone number</caption> * // create a contact using a data table and associate to the create account using the phone number * var dtContacts = DataTable.load("MyContactsToLoad.json"); * * // resolve the parentcustomerid field * dtContacts.lookup("parentcustomerid",row=>{ return {id:crm.retrieve("account",{telephone1:row.telephone1}).accountid,type:"account"}}); * * // create the record * crm.create(dtContacts); */ lookup(columnName: string, updater: (row: any) => any, useCache?: boolean): void; /** Removes a column from the Table * @method DataTable#removeColumn * @param columnName {string} Name of the column to remove * @example <caption>Remove an existing column</caption> * var dt = new DataTable(); * dt.rows.push({val1:1,val2:2}, * {val1:2,val2:2}); * dt.removeColumn('val1'); * console.log(dt.rows[0].val1); // prints undefined * console.log(dt.rows[1].val1); // prints undefined * console.log(dt.rows[0].val2); // prints 2 * console.log(dt.rows[1].val2); // prints 2 */ removeColumn(columnName: string): void; /** Renames an existing column in the Table * @method DataTable#rename * @param columnName {string} Name of the existing column to rename * @param newName {string} New Name to apply to the column * @example <caption>Rename an existing column</caption> * var dt = new DataTable(); * dt.rows.push({val1:1,val2:2}, * {val1:2,val2:2}); * dt.renameColumn('val1','val3'); * console.log(dt.rows[0].val1); // prints undefined * console.log(dt.rows[1].val1); // prints undefined * console.log(dt.rows[0].val2); // prints 2 * console.log(dt.rows[1].val2); // prints 2 * console.log(dt.rows[0].val3); // prints 1 * console.log(dt.rows[1].val3); // prints 2 */ renameColumn(columnName: string, newName: string): void; }