Need help with building HTML web resource in CRM
Need help with building HTML web resource in CRM
its working thanks for ur kind reply .
Hi Sandee,
In most of situation, your custom lookup field's name attribute would be below(If new_session was the field you want to get):
_new_session_value@OData.Community.Display.V1.FormattedValue
Regards,
Clofly
obj.semester = data["new_session@OData.FormatValue"];
UploadData();
the server responded with status of 404
ok
Hi sandee,
1. You didn't uncomment req.open('GET', window.parent.Xrm.Page.context.getClientUrl() + '/api/data/v9.1/Subject Setup('+id+')', false); it's required for XMLHttpRequest.
2. Please hide you organization URL for each screenshot to prevent your information leak.(very important)
3. I'm not really clear about "sending to client company is good or not?" means for what, but it's necessary that not send any information of company.
Regards,
Clofly
.
<script>
window.onload = function () {
UploadData();
}
function UploadData() {
var accountFetch = new String();
accountFetch += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
accountFetch += " <entity name='new_coursestreamdivisionsession'>";
accountFetch += " <attribute name='new_name'/>";
accountFetch += " <attribute name='createdon' />";
accountFetch += " <attribute name='new_coursestreamdivisionsessionid' />";
accountFetch += " <order attribute='new_name' descending='false' />";
accountFetch += " <filter type='and'>";
accountFetch += " <condition attribute='new_sessionstatus' operator='eq' value='1' />";
accountFetch += " </filter>";
accountFetch += " </entity>";
accountFetch += "</fetch>";
var semesterList = getFetch("new_coursestreamdivisionsession", accountFetch);
console.log(semesterList.value);
alert(semesterList.value[0]["new_name"]);
alert(semesterList);
var length = semesterList.value.length;
alert(length);
var accountFetch = new String();
accountFetch += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
accountFetch += " <entity name='new_subject_course_stream_mapping'>";
accountFetch += " <attribute name='new_subject_course_stream_mappingid' />";
accountFetch += " <attribute name='new_name' />";
accountFetch += " <attribute name='createdon' />";
accountFetch += " <order attribute='new_name' descending='false' />";
accountFetch += " <filter type='and'>";
accountFetch += " <condition attribute='new_session' operator='not-null' />";
accountFetch += " </filter>";
accountFetch += " </entity>";
accountFetch += "</fetch>";
var courseList = getFetch("new_subject_course_stream_mapping", accountFetch);
var length = courseList.value.length;
var accountFetch = new String();
accountFetch += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
accountFetch += " <entity name='new_lessonplan'>";
accountFetch += " <attribute name='new_lessonplanid' />";
accountFetch += " <attribute name='new_name' />";
accountFetch += " <attribute name='createdon' />";
accountFetch += " <order attribute='new_name' descending='false' />";
accountFetch += " <filter type='and'>";
accountFetch += " <condition attribute='new_coursesession' operator='not-null' />";
accountFetch += " <condition attribute='new_subjectsetup' operator='not-null' />";
accountFetch += " <condition attribute='new_subjecttype1' operator='eq' value='72A07C07-9BE8-E811-A96C-000D3AF05828' uitype='new_utility' uiname='Lecture'/>";
accountFetch += " <condition attribute='new_isfacultyload' operator='eq' value='0' />";
accountFetch += " </filter>";
accountFetch += " </entity>";
accountFetch += "</fetch>";
var lessonList = getFetch("new_lessonplan", accountFetch);
var length = lessonList.value.length;
console.log(lessonList.value);
alert(lessonList.value[0]["new_name"]);
alert(lessonList);
var length = lessonList.value.length;
alert(length);
var html = '';
html += '<table class="table">';
html += '<tr>';
html += '<td>Semester</td>';
html += '<td>Module</td>';
html += '<td>Module Leader</td>';
html += '<td><option value>Second Marker</option value></td>';
html += '</tr>';
for (var i = 0; i < lessonList.value.length; i++) {
html += '<tr>;'
html += '<td>' + lessonList.value[i]["new_name"] + '</td>';
html += '<td>' +lessonList.value[i]["new_subject_course_stream_mapping_value@OData.FormatValue"] + '</td>';
var obj = getSingleFetch(lessonList.value[i]["new_subject_course_stream_mapping_value"]);
html += '<td>' + obj.semester + '</td>';
html += '<td>' + obj.employee + '</td>';
html += '</tr>';
}
}
function getSingleFetch(id) {
var obj = new Object();
var req = new XMLHttpRequest();
//req.open('GET', window.parent.Xrm.Page.context.getClientUrl() + '/api/data/v9.1/Subject Setup('+id+')', false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Prefer", 'odata.include-annotations="*"');
req.send();
if (req.readyState == 4 /* complete */ ) {
if (req.status == 200) {
data = JSON.parse(req.response);
} else {
var error = JSON.parse(req.response).error;
}
}
obj.semester = data["new_session@OData.FormatValue"];
obj.employee = data["new_employee@OData.FormatValue"];
alert("semester is:" + obj.semester + ", employee is:" + obj.secondMarker);
return obj;
}
Hi Sandee,
Sorry for late response.
1. "object state must be opened uncaught dom exception":
Because in getSingleFetch function, you've commented req.open('GET', ... thus there is no link for request object (XMLHttpRequest) to open.
2. Sorry for I forgot it sould return an object value then we can get attributes/fields from getSingleFetch function:
please add "return obj;" to the end of getSingleFetch function
3. If you remove window.onload = function () { UploadData(); }, then all data retrieving will not works.
4. relationship name is not supported in data retrieved response, you could console.log(lessonplanList.value[0]) outside for loop to see all available attributes(@OData.FormattedValue) with a specific record, but you should included those 2 lookup fields in your new_lessonplan entity fetchXML query.
Regards,
Clofly
for (var i = 0; i < lessonplanList.value.length; i++) {
html += '<tr>;'
html += '<td>' + lessonplanList.value[i]["new_new_coursestreamdivisionsession_new_lessonplan_CourseSession"] + '</td>';
html += '<td>' + lessonplanList.value[i]["new_new_subject_course_stream_mapping_new_lessonplan_SubjectSetup@OData.FormatValue"] + '</td>';
var obj = getSingleFetch(lessonplanList.value[i]["new_new_subject_course_stream_mapping_new_lessonplan_SubjectSetup"]);
html += '<td>' + obj.semester + '</td>';
html += '<td>' + obj.Employee + '</td>';
html += '</tr>';
}
}
can i give relationship name as shown in code
André Arnaud de Cal... 291,711 Super User 2024 Season 2
Martin Dráb 230,458 Most Valuable Professional
nmaenpaa 101,156