In Dynamics 365(version:8.2), I am loading google map using web resource and then trying to initiate google map by onchange event from CRM input field but it is showing error alert message:
ReferenceError: google is not defined at initMap
I got the solution by finding iframe and then call google map.like this:
var description = Xrm.Page.getAttribute('new_street').getValue();
// Get the HTML iFrame object.
var iFrame = Xrm.Page.ui.controls.get('WebResource_Map').getObject();
// Get the element from the iFrame.
var element = iFrame.contentWindow.document.getElementById('addr_line1');
var ifr = iFrame.contentWindow;
// Set the element's value.
element.value = description+' ';
I need help on this.
Here's how I would suggest you do it:
From your script that loads the google maps (Web Resource), get the form attribute values (address fields).
Whenever you need to refresh the map in case of any field change, just reload the web resource that's embedded on your form and it should automatically call the google maps again resulting in your new location being set.
You can call the reloadMapOnFieldChange() on change of the fields for which you want the map to be refreshed
function refreshWebResource(name) {
var _webResourceControl = Xrm.Page.getControl(name);
if(_webResourceControl!=null && _webResourceControl!="" && _webResourceControl!=undefined)
{
var _src = _webResourceControl.getSrc();
_webResourceControl.setSrc(null);
_webResourceControl.setSrc(_src);
}
}
function reloadMapOnFieldChange(){
refreshWebResource(<Name of your Map Web Resource>);
}
Related
I'm having trouble passing in the name of an element into a Dyanamics CRM web Resource javacript.
This code works:
function OnFormLoad()
{
var subGrid = window.parent.document.getElementById("Claims")
// do work
}
This code doesn't:
function OnFormLoad(GridName)
{
var subGrid = window.parent.document.getElementById(GridName)
// do work
}
How do I pass in the name of the element I want to work with?
Please refrain from using document.getElementById in Dynamics as it is not supported.
I believe you are trying to get GridContext and get Data from that Grid.
For Example on Account entity we have Contacts as Grid and then you wish to get data from that Grid.
I replicated the same on Account Entity (OnLoad) and get tried to get data from Contacts Grid.
When adding OnLoad event I have passed Grid name as Parameter as below.
I have added below onLoad Js on Account entity and was able to retrieve data from grid.
Note: I have added timeout because directly firing onload was not able to load complete page and then grid Name was not available.
function onLoad(executionContext,gridName){
setTimeout(function(){ getGridDatat(executionContext,gridName); }, 3000);
}
function getGridDatat(executionContext,gridName){
debugger
var formContext = executionContext.getFormContext();
var gridContext = formContext.getControl("Contacts"); // get the grid context
var myRows = gridContext.getGrid().getRows();
/*var myRow = myRows.get(arg);
var gridRowData = myRow.getData();*/
var firstRow =myRows.get(0).getData();
var firstRowAllAttributes = firstrow.entity.attributes.getAll()
var firstRowfirstAttributeValue = firstrow.entity.attributes.get(0).getValue()
}
If you want to perform some operation on change of data formGird then there is one more way to achieve this. Make your grid as Editable and then you can find Events for that gird as below and could perform your operations.
I want to know if its possible in Dynamics to stop it from saving the last form you were in?
For example, I go to the main form of an entity, then go to the second form and Dynamics saves that I was last in the second form. I don't want it to do that - so that when i open a record i'll be navigated to the main form and not the second form.
So Dynamics' default behaviour is to save the last form you were in - I want to prevent it from doing that. I appreciate this is the way that Dynamics works but wanted to know if anybody has found any good workarounds.
Thanks :)
You could try to use the function Xrm.Page.ui.formSelector; OnLoad to dynamically set the form every time you load a record from the entity.
This user preference is stored for each Session by CRM in browser LocalStorageCache itself. Unfortunately this cannot be turned off by any User settings or System settings.
Read more
Use this snippet to navigate back to default Form that you want.
var form = Xrm.Page.ui.formSelector.getCurrentItem();
if (form != null) {
var formId = form.getId();
var formLabel = form.getLabel();
}
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items) {
var form = items[i];
var formId = form.getId();
var formLabel = form.getLabel();
if (formLabel == "Required Form Name") {
form.navigate();
return;
}
}
i am using material UI dropdown component and trying to run a callback function only when user fills all the form and submits the form. On the call back function i intend to collect all the form field and generate url to call to api.
My problem is that i can not use onChange as stated solution in #560 as i want to collect all the detail only when user clicks the submit button. It is also weird that at the moment, i am able to get value of all the other form element like slider, textfield which uses material-ui but only dropdown does not seem to be working.
My call back function:
handleFilter: function(event){
event.preventDefault();
var location = this.refs.location.getValue();
var posted_date = this.refs.posted_date.getValue();
var radius = this.refs.distance.getValue();
var salary = this.refs.salary.getValue();
var jobtype = this.refs.jobtype.getValue();
console.log(jobtype);
}
In the above function "location, posted_date, radius, salary" returns value but "jobtype" which happens to be dropdown does not seem to return any value. It returns this error in console:
"Uncaught TypeError: this.refs.jobtype.getValue is not a function"
Here is my dropdown component :
<DropDownMenu menuItems={menuItems} ref="jobtype" />
May not be the right way but i figured out that
console.log(this.refs.jobtype) (jobtype is the refs value of dropdown in my case)
was giving the following result.
R…s.c…s.Constructor {props: Object, context: Object, state: Object, refs: Object, _reactInternalInstance: ReactCompositeComponentWrapper}
Inpecting it i found value of payload index (index number of selected item) inside state object within "selectedIndex" property. I used following code to access the selected index:
var jobtype = this.refs.jobtype.state.selectedIndex;
If there is a better way to do this please suggest.
Purpose
I am trying to make a common answer database for a website form. The form is a description of computer hardware specifications, and I am trying to make it so that based on a model field, other fields are filled in automatically. The extension with have two buttons, "populate" which will based on the model field, check the database for a matching entry, and then populate data into the forms based on that. The second button being "save", which will take data in the fields and marry it to the model field and place it into the database.
Question
So, my main question is on interacting with the webpage itself, how do I grab data from the webpage, and then how do I make changes to fields?
So, my main question is on interacting with the webpage itself, how do I grab data from the webpage, and then how do I make changes to fields?
You can do this with a Firefox Add-on SDK Page-mod, click here for the documentation
Here is an example for getting data:
Example Page-Mod
/lib/main.js:
var tag = "p";
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*.mozilla.org",
contentScriptFile: data.url("element-getter.js"),
onAttach: function(worker) {
worker.port.emit("getElements", tag);
worker.port.on("gotElement", function(elementContent) {
console.log(elementContent);
});
}
});
/data/element-getter.js:
self.port.on("getElements", function(tag) {
var elements = document.getElementsByTagName(tag);
for (var i = 0; i < elements.length; i++) {
self.port.emit("gotElement", elements[i].innerHTML);
}
});
I am using jqGrid to display values on the client side. Initially the grid is empty and the user enters the data inline. According to the requirement, I need to submit the data once the user submits the form.
I intend to, just prior to submitting the form, format contents so that I can store the user entered details in the database. Is their any way I can get a grid data in the form of JSON?
Currently I am doing the same in the following way:
var ids = $(gridId).jqGrid('getDataIDs');
for ( var i =1; i <=ids.length; i++) {
var id = ids[i];
rowData = $("#"+grid).jqGrid('getRowData',id);
}
//add rowData to some global object and inturn to some hidden field and sending it the server.
Is there any other way to do the same?
I would recommend you to use
var gridData=$("#list").jqGrid('getGridParam','data');
to get full data from the grid. After you have all the data in one JavaScript object gridData you can modify it in the way which you need prior to submitting to the server.