Answered by:
Create a table in the section of an account form with respective to the contacts of that specific account

Question
-
Hi,
I have created a table which shows rows and columns dynamically on the "account form" through html webresource using script=JAVASCRIPT.. Now i want to show the table in such a way that the number of columns shouls be 3 .. and number of rows should be equal to the number of contacts related to that specific account and cell name shouls be contact name..
I need help on how to do this...
This is the code which iam using and i need to modify this according to the above requirement
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title>Add dynamic rows in HTML table </title> <script type="text/javascript" > function addRow() { debugger; var tab = document.createElement("table"); tab.border = 1; var count = window.parent.Xrm.Page.data.entity.attributes.get("new_number_table").getValue(); for (var i = 0; i < count ; i++) { var row = document.createElement("tr"); // cell.textContent = "xyz"; for (var j = 0; j < count ; j++) { var cell = document.createElement("td"); cell.textContent = "xyz"; row.appendChild(cell); } tab.appendChild(row); } var div = document.getElementById("div1"); div.appendChild(tab); } </script> </head> <body onload="addRow()"> <div id ="div1" ></div> </body> </html>
- Edited by Amy.4 Thursday, May 15, 2014 5:23 AM
Thursday, May 15, 2014 5:22 AM
Answers
-
In that case, the following OData Query would return all Contacts:
ContactSet?$select=FullName
Once you have the Contacts, render the HTML table by looping through the Contact records..
- Marked as answer by Amy.4 Thursday, May 15, 2014 9:01 AM
Thursday, May 15, 2014 8:49 AM -
Where are you calling this function "retrieveMultipleSync" from? If you're calling it from the HTML webresource, you'll need to use the following:
var clientUrl = window.parent.Xrm.Page.context.getClientUrl();
instead of
var clientUrl = Xrm.Page.context.getClientUrl();
since the HTML page doesn't understand Xrm.- Marked as answer by Amy.4 Tuesday, May 20, 2014 11:31 AM
Thursday, May 15, 2014 12:16 PM
All replies
-
Hi Amy,
You need to implement this from the HTML webresource that you've embedded inside the iFrame in your account:
1. Fetch the Account Id by using the following code:
window.parent.Xrm.Page.data.entity.getId
2. Once you have the Id of the Account, make a REST call to CRM to fetch all Contacts related to that Account. You can get a SDK sample in this path once you download the CRM SDK : "\SDK\SampleCode\JS\RESTEndpoint\JavaScriptRESTRetrieveMultiple".
3. Now that you have the Contact details (names, other fields, etc.) use JavaScript to render the table using the Contact data.
Thursday, May 15, 2014 6:22 AM -
I need to retrieve all the contacts using the odata query in my html webpage.. and display the same as a table in accounts form.. Can u help me with any code for this...Thursday, May 15, 2014 6:27 AM
-
Hi Amy,
You can use the code in the CRM SDK in this path "\SDK\SampleCode\JS\RESTEndpoint\JavaScriptRESTRetrieveMultiple\JavaScriptRESTRetrieveMultiple". It's a very similar example. To construct the OData Query, you can use the OData Query Designer, which you download from here : http://crm2011odatatool.codeplex.com/
The OData Query would look something like the following:
ContactSet?$select=EMailAddress1,FullName,ParentCustomerId&$filter=AccountId/Id eq guid'xxxxxxxxxxxxxxxxxxxxx'
Thursday, May 15, 2014 6:38 AM -
Hey, i do not have any filter conditions here... i just need to retrieve all the records of contact entity and put it into a table in html webpage.... where im creating the rows dynamically...
it should look in this manner in a a section...
Thursday, May 15, 2014 7:30 AM -
In that case, the following OData Query would return all Contacts:
ContactSet?$select=FullName
Once you have the Contacts, render the HTML table by looping through the Contact records..
- Marked as answer by Amy.4 Thursday, May 15, 2014 9:01 AM
Thursday, May 15, 2014 8:49 AM -
Iam using this function for retrieving.. but it throws an error at Context.page.. it says page is undefined....What is the correct syntax i can use
Iam using crm 2013.,.....function retrieveMultipleSync(odataSetName, select, filter) { var clientUrl = Xrm.Page.context.getClientUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; var odataSetName = "ContactSet"; var odataUri = serverUrl + ODATA_ENDPOINT + "/ContactSet?$orderby=FullName asc" + odataSetName + "?";
- Edited by Amy.4 Thursday, May 15, 2014 11:38 AM
Thursday, May 15, 2014 11:38 AM -
Where are you calling this function "retrieveMultipleSync" from? If you're calling it from the HTML webresource, you'll need to use the following:
var clientUrl = window.parent.Xrm.Page.context.getClientUrl();
instead of
var clientUrl = Xrm.Page.context.getClientUrl();
since the HTML page doesn't understand Xrm.- Marked as answer by Amy.4 Tuesday, May 20, 2014 11:31 AM
Thursday, May 15, 2014 12:16 PM