Hi,
I'm trying to accomplish a relatively simple task as a test and a learning exercise. I have a jscript web resource and an html web resource. I have a function in the jscript web resource that runs onload:
function getEventCatId() {
var eventCatId, eventCatName, lookupFieldObject;
lookupFieldObject = Xrm.Page.data.entity.attributes.get("new_eventcategoryid");
if (lookupFieldObject.getValue() != null) {
eventCatId = lookupFieldObject.getValue()[0].id;
eventCatName = lookupFieldObject.getValue()[0].name;
}
alert(eventCatId);
};
I've included the alert at the end to ensure that the data I desire is actually found, and when I try it out, it is successful.
My html web resource just includes a button that is supposed to show the same alert as above onClick. In my html page I included my js web resource as a "src" and using the console, it appears there is no issue with the html finding the js web resource. I've tried two methods to get my desired alert -- 1.) <td><button onclick="alert(eventCatId)">Click here</button></td></tr>, and 2.) <td><button onclick="getEventCatId()">Click here</button></td></tr>.
When using method number 1, I get the following error in the console: "Uncaught ReferenceError: eventCatId is not defined," and when I use method number 2, I get the following error in the console: "Uncaught TypeError: Cannot read property 'entity' of null" and it points me to this line: "lookupFieldObject = Xrm.Page.data.entity.attributes.get("new_eventcategoryid");"
I know that the js web resource is able to successfully run the code because the alert shows on load of the page. So, I'm confused why the html web resource fails. Any ideas on how to fix this? Thanks for any help!