Closed phuocle closed 7 years ago
Hello @phuocle,
This is not yet possible, however I was also thinking about this. I'll add an option for this, so that synchronous requests can be sent as well.
Kind Regards, Florian
Hey @phuocle,
The latest release includes the possibility to send requests synchronously.
How to do this is described here.
I'd be happy to receive some feedback on this.
Kind Regards, Florian
My Custom Rule in ribbon command (it worked)
var canSendExtend = false;
function canSendExtendTrial() {
if (canSendExtend) return true;
require(["WebApiClient", "Alert", "Lib", "entity/pl_License.Minify"], function (WebApiClient) {
var f = new PL.pl_License.Form();
var o = PL.pl_License.OptionSet;
var fetchXml = [
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>",
" <entity name='email'>",
" <attribute name='activityid' />",
" <filter type='and'>",
" <condition attribute='pl_emailtype' operator='eq' value='500000000' />",
" <condition attribute='regardingobjectid' operator='eq' uitype='account' value='", f.pl_AccountId.getValue(), "' />",
" </filter>",
" </entity>",
"</fetch>"
].join("");
var request = {
entityName: "email",
fetchXml: fetchXml,
async: false
};
var response = WebApiClient.Retrieve(request);
if (response.value.length === 0) {
canSendExtend = true;
Xrm.Page.ui.refreshRibbon();
}
});
return false;
}
WebApiClient
now load in the synchronously
. But, because it inside the require
function, so the function load in the asynchronous
. Now I use a template variable canSendExtend
with Xrm.Page.ui.refreshRibbon()
to control the button enable.
I want to completed remove template variable also the call function refresh ribbon. Now changed the function below, the code throw exception
function canSendExtendTrial() {
var WebApiClient = require("WebApiClient"); //exception here
//var WebApiClient = require("full path to WebApiClient");//exception here too
var f = new PL.pl_License.Form();
var o = PL.pl_License.OptionSet;
var fetchXml = [
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>",
" <entity name='email'>",
" <attribute name='activityid' />",
" <filter type='and'>",
" <condition attribute='pl_emailtype' operator='eq' value='500000000' />",
" <condition attribute='regardingobjectid' operator='eq' uitype='account' value='", f.pl_AccountId.getValue(), "' />",
" </filter>",
" </entity>",
"</fetch>"
].join("");
var request = {
entityName: "email",
fetchXml: fetchXml,
async: false
};
var response = WebApiClient.Retrieve(request);
if (response.value.length === 0) return true;
return false;
}
Could you tell me how I can archive this ? Thanks
Hello @phuocle,
Your second approach is still executing asynchronously because of the require call. If it has to be synchronous, you'll have to add the WebApiClient to your form as library. It will then be present automatically once the form is loaded, so you can just leave the require calls away and send your synchronous requests. Hope it helps.
Kind Regards, Florian
Hey @phuocle,
did it work for you in the end?
Kind Regards, Florian
Some time, need return data from fetchXml in the synchronous mode. Then continue process the business logic. Can WebApiClient have an option do that ?
Thank.