Retrieve Contacts.html:
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Untitled Page</TITLE>
<META charset=utf-8></HEAD>
<BODY spellcheck="true">
<SCRIPT type=text/javascript src="sample_/Scripts/SDK.REST.js"></SCRIPT>
<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx"></SCRIPT>
<SCRIPT type=text/javascript src="sample_/Scripts/json2.js"></SCRIPT>
<SCRIPT type=text/javascript src="my_RetrieveContacts"></SCRIPT>
<BUTTON id=btnRetrieveAccounts onclick=retrieveContacts();>Retrieve contacts</BUTTON><BUTTON id=btnGetUsers onclick="assignContacts('contactsTable');">Get Users</BUTTON>
<TABLE id=tableHeadings border=1 summary="This table provides the headings for the list of accounts displayed in a grid.">
<THEAD></THEAD>
<TBODY></TBODY></TABLE>
<TABLE id=contactsTable border=1>
<TBODY></TBODY></TABLE></BODY></HTML>
RetrieveContacs.js
var contactsGrid;
var ContactsCol;
var totalcontactsCount = 0;
function retrieveContacts() {
var options = "$select=FullName,ContactId&$filter=Telephone1 eq '555-0109'";
SDK.REST.retrieveMultipleRecords("Contact", options, retrieveContactsCallBack, function (error) { alert(error.message); }, contactsRetrieveComplete);
}
function retrieveContactsCallBack(retrievedContacts) {
contactsGrid = document.getElementById('contactsTable');
deleteAllRows("contactsTable");
totalcontactsCount = retrievedContacts.length;
ContactsCol=retrievedContacts;
for (var i = 0; i < retrievedContacts.length; i++) {
var contact = retrievedContacts[i];
var rowCount = contactsGrid.rows.length;
var row = contactsGrid.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement();
cell2.innerHTML = contact.FullName;
cell2.appendChild(element2);
}
}
function contactsRetrieveComplete() {
}
function clearaccountsGrid() {
totalcontactsCount = 0;
for (var i = contactsGrid.rows.length - 1; i >= 0; i--) {
contactsGrid.deleteRow(i);
}
}
function deleteAllRows(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
table.deleteRow(i); rowCount--; i--;
}
}
catch (e) {
alert(e);
}
}
function assignContacts(tableID){
var obj =new Array();
var ids="";
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
obj[i]=new Object();
obj[i]= ContactsCol[i].ContactId;
ids=ids+obj[i]+" ";
}
}
window.open("https://crmtrail2011.crm5.dynamics.com//WebResources/my_usersList?orglcid=1033&orgname=crmtrail2011&userlcid=1033&data="+ids);
}
Userslist.htm:
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Untitled Page</TITLE>
<META charset=utf-8></HEAD>
<BODY onload=getUsers(); spellcheck="true">
<SCRIPT type=text/javascript src="sample_/Scripts/SDK.REST.js"></SCRIPT>
<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx"></SCRIPT>
<SCRIPT type=text/javascript src="sample_/Scripts/json2.js"></SCRIPT>
<SCRIPT type=text/javascript src="sample_/Scripts/SDK.SOAPSample.Assign.js"></SCRIPT>
<SCRIPT type=text/javascript>
var UsersGrid;
var UsersCol;
var totalUsersCount = 0;
function getUsers() {
var options = "$select=FullName,CALType,SystemUserId&$filter=AccessMode/Value ne 3 and IsDisabled eq false";
SDK.REST.retrieveMultipleRecords("SystemUser", options, retrieveUsersCallBack, function (error) { alert(error.message); }, UsersRetrieveComplete);
}
function retrieveUsersCallBack(retrievedUsers) {
UsersGrid = document.getElementById('UsersTable');
totalUsersCount = totalUsersCount + retrievedUsers.length;
UsersCol=retrievedUsers;
for (var i = 0; i < retrievedUsers.length; i++) {
var user= retrievedUsers[i];
var rowCount = UsersGrid.rows.length;
var row = UsersGrid.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "radio";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement();
cell2.innerHTML = user.FullName;
cell2.appendChild(element2);
var lt=user.CALType;
alert(lt.getText());
}
}
function UsersRetrieveComplete() {
}
function assign(tableID){
var uid;
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
uid=new Object();
uid= UsersCol[i].SystemUserId;
}
}
var vals = new Array();
if (location.search != "") {
vals = location.search.substr(1).split("&");
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
}
//look for the parameter named 'data'
for (var i in vals) {
if (vals[i][0].toLowerCase() == "data") {
var split=vals[i][1].split(" ");
for(var count=0;count<split.length;count++){
var contactid = split[count];
SDK.SOAPSamples.assignRequest(uid,contactid ,"contact",scb,ecb);
}
}
}
}
}
function scb(){
alert("success");
}
function ecb(){
alert("error");
}
</SCRIPT>
<BUTTON id=btnAssign onclick="assign('usersTable');">Assign</BUTTON>
<TABLE id=tableHeadings border=1 summary="This table provides the headings for the list of users displayed in a grid.">
<THEAD></THEAD>
<TBODY></TBODY></TABLE>
<TABLE id=usersTable border=1>
<TBODY></TBODY></TABLE></BODY></HTML>
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Untitled Page</TITLE>
<META charset=utf-8></HEAD>
<BODY spellcheck="true">
<SCRIPT type=text/javascript src="sample_/Scripts/SDK.REST.js"></SCRIPT>
<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx"></SCRIPT>
<SCRIPT type=text/javascript src="sample_/Scripts/json2.js"></SCRIPT>
<SCRIPT type=text/javascript src="my_RetrieveContacts"></SCRIPT>
<BUTTON id=btnRetrieveAccounts onclick=retrieveContacts();>Retrieve contacts</BUTTON><BUTTON id=btnGetUsers onclick="assignContacts('contactsTable');">Get Users</BUTTON>
<TABLE id=tableHeadings border=1 summary="This table provides the headings for the list of accounts displayed in a grid.">
<THEAD></THEAD>
<TBODY></TBODY></TABLE>
<TABLE id=contactsTable border=1>
<TBODY></TBODY></TABLE></BODY></HTML>
RetrieveContacs.js
var contactsGrid;
var ContactsCol;
var totalcontactsCount = 0;
function retrieveContacts() {
var options = "$select=FullName,ContactId&$filter=Telephone1 eq '555-0109'";
SDK.REST.retrieveMultipleRecords("Contact", options, retrieveContactsCallBack, function (error) { alert(error.message); }, contactsRetrieveComplete);
}
function retrieveContactsCallBack(retrievedContacts) {
contactsGrid = document.getElementById('contactsTable');
deleteAllRows("contactsTable");
totalcontactsCount = retrievedContacts.length;
ContactsCol=retrievedContacts;
for (var i = 0; i < retrievedContacts.length; i++) {
var contact = retrievedContacts[i];
var rowCount = contactsGrid.rows.length;
var row = contactsGrid.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement();
cell2.innerHTML = contact.FullName;
cell2.appendChild(element2);
}
}
function contactsRetrieveComplete() {
}
function clearaccountsGrid() {
totalcontactsCount = 0;
for (var i = contactsGrid.rows.length - 1; i >= 0; i--) {
contactsGrid.deleteRow(i);
}
}
function deleteAllRows(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
table.deleteRow(i); rowCount--; i--;
}
}
catch (e) {
alert(e);
}
}
function assignContacts(tableID){
var obj =new Array();
var ids="";
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
obj[i]=new Object();
obj[i]= ContactsCol[i].ContactId;
ids=ids+obj[i]+" ";
}
}
window.open("https://crmtrail2011.crm5.dynamics.com//WebResources/my_usersList?orglcid=1033&orgname=crmtrail2011&userlcid=1033&data="+ids);
}
Userslist.htm:
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Untitled Page</TITLE>
<META charset=utf-8></HEAD>
<BODY onload=getUsers(); spellcheck="true">
<SCRIPT type=text/javascript src="sample_/Scripts/SDK.REST.js"></SCRIPT>
<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx"></SCRIPT>
<SCRIPT type=text/javascript src="sample_/Scripts/json2.js"></SCRIPT>
<SCRIPT type=text/javascript src="sample_/Scripts/SDK.SOAPSample.Assign.js"></SCRIPT>
<SCRIPT type=text/javascript>
var UsersGrid;
var UsersCol;
var totalUsersCount = 0;
function getUsers() {
var options = "$select=FullName,CALType,SystemUserId&$filter=AccessMode/Value ne 3 and IsDisabled eq false";
SDK.REST.retrieveMultipleRecords("SystemUser", options, retrieveUsersCallBack, function (error) { alert(error.message); }, UsersRetrieveComplete);
}
function retrieveUsersCallBack(retrievedUsers) {
UsersGrid = document.getElementById('UsersTable');
totalUsersCount = totalUsersCount + retrievedUsers.length;
UsersCol=retrievedUsers;
for (var i = 0; i < retrievedUsers.length; i++) {
var user= retrievedUsers[i];
var rowCount = UsersGrid.rows.length;
var row = UsersGrid.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "radio";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement();
cell2.innerHTML = user.FullName;
cell2.appendChild(element2);
var lt=user.CALType;
alert(lt.getText());
}
}
function UsersRetrieveComplete() {
}
function assign(tableID){
var uid;
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
uid=new Object();
uid= UsersCol[i].SystemUserId;
}
}
var vals = new Array();
if (location.search != "") {
vals = location.search.substr(1).split("&");
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
}
//look for the parameter named 'data'
for (var i in vals) {
if (vals[i][0].toLowerCase() == "data") {
var split=vals[i][1].split(" ");
for(var count=0;count<split.length;count++){
var contactid = split[count];
SDK.SOAPSamples.assignRequest(uid,contactid ,"contact",scb,ecb);
}
}
}
}
}
function scb(){
alert("success");
}
function ecb(){
alert("error");
}
</SCRIPT>
<BUTTON id=btnAssign onclick="assign('usersTable');">Assign</BUTTON>
<TABLE id=tableHeadings border=1 summary="This table provides the headings for the list of users displayed in a grid.">
<THEAD></THEAD>
<TBODY></TBODY></TABLE>
<TABLE id=usersTable border=1>
<TBODY></TBODY></TABLE></BODY></HTML>
No comments:
Post a Comment