Refresh Parent Form after Quick Create in Dynamics CRM 2016 - dynamics-crm

In Dynamics CRM 2016 we have a Quick Create Form which works well. But once the Quick Create is done, and the record is saved (and the new record appears in the sub-grid in the parent form), the roll-up field under the sub-grid doesn't get re-refreshed on the screen until the user presses F5.
(we have some C# code to update the roll-up).
Does anyone know how to force the refresh of the main form after the Quick Create has successfully run?

You may add timeout on refresh event, and after 1-2 sec refresh once more.
function OnFormLoad() //add this function onload form
{
var subGrid = window.parent.document.getElementById("id of your subgrid")
if (subGrid !== null) {
if (subGrid.control)
subGrid.control.add_onRefresh(fnOnRefresh)
else
setTimeout(OnFormLoad, 500);
} else {
setTimeout(OnFormLoad, 500);
}
}
function fnOnRefresh() {
setTimeout(function() {
Xrm.Page.ui.controls.get("id of your subgrid").refresh();
}, 2000) //after 2 sec refresh subgrid
}

I would try stopping the OOB save event using the below snippet: Read more
function onSave(context) {
var saveEvent = context.getEventArgs();
saveEvent.preventDefault();
//save explicitly here
//reload the window here
}
And then save the entity in code using:
Xrm.Page.data.entity.save();
And then refresh/reload the browser window. I haven’t tried this but very rough theory :)

We got it working ... used what Timur suggested but just changed the last function to:
function fnOnRefresh() {
setTimeout(function() {
window.parent.location.reload(true);
}, 500)
}
Thank you

Related

dynamics crm 365 online quickform not rendering

I have a form which has a tab and in this tab is a quickview form. On the quickview form, I have a subgrid and a text field.
The tab has a default state of 'collapsed'. When I open the form, only the text field is displayed. It seems as if the subgrid in no rendering at all.
If I change the tab default state to 'expanded', then when I open the form, the
subgrid is rendering correctly.
I have tried to refresh the quickform view outlined here
https://msdn.microsoft.com/en-us/library/mt736908.aspx
But it does not seem to work.
UPDATE:
I have tried the following, but still no success.
FIRST VERSION
// Triggering when the tab is expanded
function onChange(){
console.log('on change');
// get quick view form
var qv = Xrm.Page.ui.quickForms.get("myquickformview");
qv.refresh();
// get subgrid
try {
qv.getControl(0).refresh();
}
catch (e)
{
console.log(e);
}
}
SECOND VERSION
function onLoad(){
console.log('onload');
Xrm.Page.getAttribute('new_person').addOnChange(refresh);
}
function onChange(){
Xrm.Page.getAttribute('new_person').fireOnChange();
}
function refresh(){
console.log('on change');
// get quick view form
var qv = Xrm.Page.ui.quickForms.get("myquickformview");
// get subgrid
try {
qv.getControl(0).setVisible(false);
qv.getControl(0).setVisible(true);
qv.getControl(0).refresh();
}
catch (e)
{
console.log(e);
}
qv.refresh();
}
Any advice appreciated. Thanks in advance.
1.Add onchange event handler for the lookup (on which Quick view form is rendered) to have the code to refresh the quick view control.
Xrm.Page.getAttribute("lookup_fieldname").addOnChange(function);
Keep the below code in function.
var quickViewControl = Xrm.Page.ui.quickForms.get(“your quick view form name”);
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {
quickViewControl.refresh();
}
}
2.Trigger fireOnChange() of lookup on tab expanded handler, so that onchange will refresh QVform totally.
Xrm.Page.getAttribute("lookup_fieldname").fireOnChange();
Got a hint from this. I just answered here (in mobile without testing) to unblock you.

Microsoft Dynamics CRM 2015 – Need to have Subgrid Lookup Filter

Microsoft Dynamics CRM 2015 –
Need to filter the look up on a subgrid
Javascript code I am using:
function SetCustomLookUp() {
debugger;
lookupFieldObject = Xrm.Page.data.entity.attributes.get('account');
if (lookupFieldObject.getValue() != null) {
entityId = lookupFieldObject.getValue()[0].id;
entityName = lookupFieldObject.getValue()[0].entityType;
entityLabel = lookupFieldObject.getValue()[0].name;
}
var filterXML = [
'<filter type="and">',
'<condition attribute="parentcustomerid" value="{54BC1539-C29C-E511-80E9-3863BB2E6258}" operator="eq"/>',
'</filter>'
].join('\n');
var Subgrid = Xrm.Page.getControl("Contacts");
document.getElementById("Contacts").addEventListener("click", function () {
setTimeout(function () {
var gridControl = Xrm.Page.getControl("Contacts");
var me = gridControl.$c_0.$N_4.$Y_3;
me.addPreSearch(function () {
me.addCustomFilter(filterXML);
});
}, 2000);
});
}
Error: "Cannot read property 'addEventListener' of null"
I used this code and erro thet you present, the reason is:
the subgrid is painting at the end of paint all form, and then you must add this even of click when the sub-grid is painting
I write a small code for this:
var objSubGrid = document.getElementById("subgrid_name");
//CRM loads subgrid after form is loaded.. so when we are adding script on form load.. need to wait until sub grid is loaded.
// that's why we are adding a delay..
if (objSubGrid == null) {
setTimeout(functionxxx, 2000);
return;
} else {
Following article contains answer - http://www.magnetismsolutions.com/blog/paulnieuwelaar/2016/06/20/filter-n-n-add-existing-lookup-dynamics-crm-2016-turbo-forms
To Modarators - Yes, I know that it is recommended to retype everything that is mentioned in article but I'm pretty sure that article will be available online for a long time so I just will not retype because it has no sense for me.

jqGrid 'clearToolbar' without grid reload

I need to clear the toolbar without reloading the grid in my jqgrid. It should just reset the toolbar to its default values.
I tried using,
$("#TransactionsGrid")[0].clearToolbar();
My grid datatype:local and i don't use loadonce:true.
This made the toolbar clear and refresh the grid. I dont want that to happen.
Any ideas?
I find the question interesting.
To implement the requirement I suggest to use register jqGridToolbarBeforeClear to execute the handler only once. The handler should 1) unregister itself as the event handler and return "stop" to prevent reloading of the grid:
$grid.jqGrid("filterToolbar", { defaultSearch: "cn" });
$("#clearToolbar").button().click(function () {
var myStopReload = function () {
$grid.unbind("jqGridToolbarBeforeClear", myStopReload);
return "stop"; // stop reload
};
$grid.bind("jqGridToolbarBeforeClear", myStopReload);
if ($grid[0].ftoolbar) {
$grid[0].clearToolbar();
}
});
The corresponding demo shows it live.

joomla 3 custom component checkout record

Iam in the edit view of one of my component views.
When I go back to the list view, with the cancel button of joomlas toolbar, the list view appears, but the record is locked. It seems that the record is not checked out correct.
In this case, there is no special function in the appropriate controler for canceling. Only for saving and some other tasks.
Iam not able to unlocking the records due to my view in the backend.
In the view there is a typical javascript for using the submit button:
<script type="text/javascript">
js = jQuery.noConflict();
js(document).ready(function() {
});
Joomla.submitbutton = function(task)
{
if (task == 'master.cancel') {
Joomla.submitform(task, document.getElementById('master-form'));
}
else {
if (task != 'master.cancel' && document.formvalidator.isValid(document.id('master-form'))) {
Joomla.submitform(task, document.getElementById('master-form'));
}
else {
alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>');
}
}
}
</script>
Where should I go into, to activate the checkout function when leaving back to the listview from the edit view?
Same problem in case of saving records.
thx Perino
I found the problem. The view is build up of different models and I deactivated
$this->item = $this->get('Item');
in view.html.php. Activating, will result in correct checkin/out of the record.

How to know on client side whether a postback occured?

I am developing a Greasemonkey script and this script changes some elements in a table. However, when we click a button in the table an asynchronous postback happens and the table is refreshed.
So, my elements are also refreshed. How do I know a postback has occurred so that I can run my script again to change the new elements in the table? (The page uses Telerik.)
Don't bother trying to check for a postback That's almost always a painful way of doing things. You care about the table content, monitor that.
See:
Run Greasemonkey script on the same page, multiple times?
Fire Greasemonkey script on AJAX request
How can I detect AJAX node insertion without using DOM mutation events?
and several others.
Just as Brock Adams says in his answer, I decided to monitor table and wrote this code:
function repairInputEvents() {
for (var i = 0; i < document.getElementsByTagName("input").length; i++) {
//Add event to buttons that cause postback.
document.getElementsByTagName("input")[i].addEventListener("click", function() {
//Run the following just before postback.
document.getElementsByClassName("table")[0].setAttribute("title", "old");
var checkAjaxInterval = setInterval(function() { checkAjax(); }, 1000);
function checkAjax() {
if (document.getElementsByClassName("table")[0].getAttribute("title") != "old") {
clearInterval(checkAjaxInterval);
repairInputEvents();
repairSelectEvents();
}
}
});
}
}
//First run
repairInputEvents();
repairSelectEvents();

Resources