CRM Unable to get property 'refreshRibbon' of undefined or null reference - dynamics-crm-online

When calling Xrm.Page.data.refresh(true) from a web resource, I get this error:
Unable to get property 'refreshRibbon' of undefined or null reference
in the JSProvider.ashx refreshRibbon, from firing an onchange event for an Attribute.
Why is this error occurring?

This is an interesting bug/feature with the onChange event:
function onLoad() {
Xrm.Page.getAttribute("new_att").addOnChange(onChange); // OK!
Xrm.Page.getAttribute("new_att2").addOnChange(Xrm.Page.ui.refreshRibbon); // No Worky!
}
Any calls to Xrm, should be wrapped in another function, or an anonymous method. No passing in the function directly.
function onChange() {
Xrm.Page.ui.refreshRibbon();
}

Related

Uncaught TypeError: strapi.query is not a function

I'm trying to get the value of a field from a single type collection in the home page of a strapi plugin.
const test = strapi.query('global-settings').find({},{'externalUrl':1})
It's returning me an Uncaught TypeError: strapi.query is not a function
Any idea why?
I am not sure about the last part of your request.
But remember that those requests are asynchronous, so try adding await to the call.
This is an example of a query I am using.
const user_settings = await strapi.query('user-settings').find({Send_Monthly_Email: true})
So, that's why I don't understand why you have an empty parameter on that query. >> find({},{'externalUrl':1})
I am assuming you are inside a controller or inside a service.

Emitting a js event to Livewire with data

I have a component where each row is a separate component. I'm emitting an event using Echo + Pusher, and I want to scope the event to only refresh the relevant row.
This isn't described in the docs, but there's an old (and possibly outdated) video by Caleb Porzio (creator of Livewire) in this article (last video, ~8m30s) where this is done by adding the relevant ID into the event name.
In my livewire model, I have:
public function getListeners()
{
return [
"HitReceived:{$this->monitorId}" => 'refresh',
];
}
And in my JS I have:
Livewire.emit('HitReceived:' + data.monitorId);
I can see in the console that data.monitorId is set. When I fire an event with id #1, I get a 500 error:
ERROR: Undefined array key "HitReceived1" {"userId":1,"exception":"[object] (ErrorException(code: 0):
Undefined array key \"HitReceived1\" at /vendor/livewire/livewire/src/ComponentConcerns/ReceivesEvents.php:72)
(This all works if I don't scope my event to a particular model instance, but then everything refreshes.)
I was using $this->monitorId in my array of listeners:
public function getListeners()
{
return [
"HitReceived:{$this->monitorId}" => 'refresh',
];
}
But the variable was declared as protected:
protected $monitorId;
I can't quite see why this would have cause the error I was seeing, but changing it to a public property resolved the issue.

Reset spyOnEvent on document

I'm trying to track a custom event based on some data, for this I'm spying on my custom event and expecting the event to get trigger or not. Here am trying to reset my spyevent all I get is undefined error
TypeError: undefined is not an object (evaluating 'spyOnEvent(document, 'product.trackVariantChanged').calls.reset')
it('selects a variant without triggering the product.trackVariantChanged event on document', function() {
spyOnEvent(document, 'variantChanged');
spyOnEvent(document, 'product.trackVariantChanged').calls.reset();
App.ColorSelector.init(); // this function automatically calls custom triggers when it calls
App.ColorSelector.selectVariant($colorSelector, 'wms_III_black'); //this function has a depedency on init()
expect('variantChanged').toHaveBeenTriggeredOn(document);
expect('product.trackVariantChanged').not.toHaveBeenTriggeredOn(document);
App.ColorSelector.selectVariant($colorSelector, 'wms_III_white');
expect('variantChanged').toHaveBeenTriggeredOn(document);
expect('product.trackVariantChanged').not.toHaveBeenTriggeredOn(document);
});
from above case App.ColorSelector.init(); this function automatically calls/ should get call fisr and triggers custom event and App.ColorSelector.selectVariant($colorSelector, 'wms_III_black'); this function has a dependency on init() function
So I want to reset the spy before the selectVariant function get called.
For spyOnEvent instead of calls.reset() use spyOnEvent(document, 'customEvent').reset(); it will work.

Waiting for mixpanel JS lib to be ready so I can get users distinct_id

We want to use MixPanel to capture events on our site and I'm trying to get hold of the users distinct id, so I'm using the following code snippet:
$(document).ready(function($){
console.log("We have distinct id");
console.log(mixpanel.get_distinct_id());
});
This causes an error saying 'undefined is not a function' when attempting to get the distinct id.
I've checked in the debugger and can confirm that the mixpanel object does not have a get_distinct_id method, However if I wait until the page has loaded and then evaluate mixpanel.get_distinct_id() in the console, I get the distinct id without problem.
I can only guess that the mixpanel object hasn't completed initialisation yet. Is there a callback or an event that I can use to know once the mixpanel object will be able to tell me the users distinct_id?
From a Mixpanel article:
"[...] pass a config object to the mixpanel.init() method with a loaded parameter and a callback function that will execute immediately after our library has finished loading. Inside the callback function, you can use the get_property() and get_distinct_id() methods and ensure that they'll only execute after the library has finished loading."
mixpanel.init('Project Token', {'loaded':function() {
var distinct_id = mixpanel.get_distinct_id()}
});
Source: How to prevent get_distinct_id & get_property from returning undefined
I found a code snippet here: https://gist.github.com/calvinfo/5117821, credit to https://gist.github.com/calvinfo which looks like this:
$(document).ready(function() {
if ($("#mixpanel_distinct_id").length > 0) {
var interval = setInterval(function () {
if (window.mixpanel.get_distinct_id) {
$("#mixpanel_distinct_id").val(window.mixpanel.get_distinct_id());
clearInterval(interval);
}
}, 300);
}
});
Basically this allows you to check every 300 milliseconds whether the mixpanel object has completed initializing and the get_distinct_id function is available.
You make get district_id from cookie:
cookie = document.cookie.split(";")[0];
distinct_id = cookie.substr(74,53);
but correctly use regexp
Good luck!

How to get a Boolean return value from jQuery trigger method?

I have a custom event that I want to fire using jQuery's trigger method:
$(wizard).trigger('validatingStepValues');
Then in the wizard's current step code, I subscribe to this event as follow:
$(wizard).bind('validatingStepValues', function (){
// Validating step's form data here; returning false on invalid state.
});
Then in my wizard, again I want to be able to stop user from going to the next step, if a false value is returned from validation process? I'd like to have something like:
$(wizard).trigger('validatingStepValues', validReturnCallback, invalidReturnCallback)
Have you considered using something like:
function wizardValidator(successCallback, failureCallback) {
return function() {
// Validating step's form data here;
if (wasValid && successCallback) {
successCallback();
}
else if (! wasValid && failureCallback) {
failureCallback();
}
return wasValid;
};
}
$(wizard).bind('validatingStepValues', wizardValidator(validReturnCallback, invalidReturnCallback));
This requires that you know the callbacks that you want to use at the time you bind the event listener. If you want to be able to use different callback functions at different times, you could define additional event types, like:
$(wizard).bind('validatingStep2Values', wizardValidator(validStep2ReturnCallback, invalidStep2ReturnCallback));
$(wizard).bind('validatingStep3Values', wizardValidator(validStep3ReturnCallback, invalidStep3ReturnCallback));
Alternately, events that you create by calling trigger() propagate up the DOM hierarchy. Returning false an event handler cancels this propagation. So you could bind your desired success callback function as an event listener on your wizard's parent node. That won't do anything to allow your failure callback to be executed, however.

Resources