-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtsexamples.ts
71 lines (49 loc) · 2.43 KB
/
tsexamples.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {CRMClient} from "./src/CRMClient";
import {DataTable} from "./src/DataTable";
import {DataTableSerializer} from "./src/DataTableSerializer";
//var crm = new CRMClient("default");
var crm = new CRMClient("Url=http://crm.contoso.com/xrmContoso");
var who = crm.whoAmI();
console.log(who);
var myUser = crm.retrieve("systemuser",who);
console.log(myUser);
var account1 = crm.retrieve("account","4C1ECDF4-633B-E211-9EB5-0050568A69E2",["accountid","name","ownerid","createdon"]);
console.log(account1);
var account2 = crm.retrieve("account","4C1ECDF4-633B-E211-9EB5-0050568A69E2");
console.log(account2);
var guid = crm.create("account",{name:"test account", description:"this is a test"});
console.log("created account with id " + guid);
crm.delete("account",guid);
//var guid = crm.create("account",[{name:"account1"},{name:"account2"}]);
for(var i=0;i<10;i++){
guid = crm.create("account",{name:"test account "+i, description:"this is a test",AccountCategoryCode:1});
console.log("created account with id " + guid);
crm.delete("account",guid);
}
var accounts = DataTableSerializer.load("accounts.xml");
//crm.create("account",accounts.rows);
var contacts = DataTableSerializer.load("contacts.xml");
// Perform some transformations before insert
//contacts.lookup("accountid", row => crm.retrieve("account",{name:row.accountid}).accountid);
// The User ID is not the same, so we need to get the existing one
//contacts.lookup("ownerid", row => crm.retrieve("systemuser",{domainname:row.ownerid}).systemuserid);
//crm.create("contacts",contacts.rows);
//crm.fetchAll("accounts").save("accounts.xml");
//crm.fetchAll("accounts").save("accounts.json");
crm.update("account",{accountid:"2ad7a34f-11db-4910-8f1c-397b1352f0e3",name:"updated"});
crm.update("account",{name:"updated"},{name:{like:"%test%"}});
// Export the list of attributes of an entity to an excel file
var dn = require("dynamicsnode");
// set the environment where to execute this script
crm = new dn.CRMClient("UAT");
// Get the entity metadata
var entityName = "account";
var metadata = crm.getEntityMetadata(entityName);
var outputTable = new dn.DataTable();
for (var i = 0; i < metadata.Attributes.length; i++) {
var attr = metadata.Attributes[i];
outputTable.rows.push({name:attr.LogicalName,type:attr.AttributeType});
console.log(attr.LogicalName);
}
// save the results to an external excel file
dn.DataTableSerializer.save(outputTable, `${entityName}Attributes.xlsx`);