I am using web resource in CRM of Dynamics 365. Recently, such an error occurred, and I didn't know why it happened and I asked a question.
Error log content:
ReferenceError: $ is not defined
I'll attach the part where the error log appears.
function setSerialnoinfo(){
var serialno = Xrm.Page.data.entity.attributes.get("skr_serialno");
if(Xrm.Page.getAttribute("skr_serialno").getValue() != null){
var serialnoid = serialno.getValue()[0].id;
var query = "/skr_installationSet(guid'"+serialnoid+"')";
$.ajax({
type: "GET",
async : false,
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "/XRMServices/2011/OrganizationData.svc"+query,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function(data, textStatus, XmlHttpRequest) {
var result = data.d;
var skr_productid = result.skr_product.Id;
var skr_productname = result.skr_product.Name;
var skr_productentity = result.skr_product.LogicalName;
if (!(skr_productid == null || skr_productid == "")){
Xrm.Page.data.entity.attributes.get("skr_product").setValue([{id: skr_productid, name: skr_productname, entityType: skr_productentity}]);
}
//var skr_salestype = result.skr_salestype.Value;
var skr_warrantytype = result.skr_warrantytype.Value;
if(skr_warrantytype == 1){
skr_warrantytype = 0;
}
Xrm.Page.data.entity.attributes.get("skr_servicefeetype").setValue(skr_warrantytype);
var skr_servicecontracttype = result.skr_servicecontracttype.Value;
Xrm.Page.data.entity.attributes.get("skr_servicecontracttype").setValue(skr_servicecontracttype);
var skr_modelid = result.skr_model.Id;
var skr_modelname = result.skr_model.Name;
var skr_modelentity = result.skr_model.LogicalName;
if (!(skr_modelid == null || skr_modelid == "")){
Xrm.Page.data.entity.attributes.get("skr_setname").setValue([{id: skr_modelid, name: skr_modelname, entityType: skr_modelentity}]);
setsetname();
setErrorModel();
}
Xrm.Page.getAttribute("skr_product").setSubmitMode("always");
Xrm.Page.getAttribute("skr_servicefeetype").setSubmitMode("always");
Xrm.Page.getAttribute("skr_setname").setSubmitMode("always");
Xrm.Page.getAttribute("skr_servicecontracttype").setSubmitMode("always");
Xrm.Page.getAttribute("skr_productseries").setSubmitMode("always");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
var userlcid = Xrm.Page.context.getUserLcid();
if(userlcid == "1042"){
alert("오류가 발생 했습니다. 다시 시도해 주세요.");
}else if(userlcid == "1033"){
alert("Unknown Error: Try again.");
}
}
});
}
}
This is an error in testing with the user's new UI version before Microsoft's 10 update.
I also want to know if the grammar of web resource changes a little after the update.
You are using jQuery library in your web resource, somehow the link is broken or conflict happening.
Validate you are adding/loading jquery.js or jquery.min.js in your HTML. Check entity form before this function residing library being referred - this is unsupported for this very same broken behavior
Otherwise if you are relying on native library reference, rather add your own library reference like above & use jQuery.noConflict(). Read more
Stick with XMLHttpRequest for supported scope & most important Xrm.Page is deprecated, pls start using the ExecutionContext.getFormContext
Related
I have tried many suggestions from stack overflow earlier threads, but the issue still do not seem to be resolving.
Client Side Code:
var file = document.getElementById('MainForm_main_panel_company_code_change_file').files[0];
var formData = new FormData();
formData.append("file", file);
data = '[0, {"data":{"args":"'+formData+'"}}]';
$.ajax({
url: 'Control/MainForm.main_panel.company_code_change/GetData',
type: 'POST',
data: data,
contentType: false,
processData: false,
dataType: 'json',
success: function (result) {
if (result.msg === undefined) {
JSMessage.show("Success", "Report Generated Successfully");
} else
JSMessage.show("Error", "Report Generation Failed:" +result.msg.text);
}
Note: If I don't mention data = '[0, {"data":{"args":"......., it throws error: 'data is required'
Server Side Code:
public class CompanyCodeChangeArg
{
public string args;
public CompanyCodeChangeArg()
{
F<IMNull<CompanyCodeChangeArg>>.Instance.SetNull(this);
}
}
[HttpPost]public string GetData(CompanyCodeChangeArg arg)
{
var file = System.Web.HttpContext.Current.Request.Files[0];
HttpPostedFileBase filebase = new HttpPostedFileWrapper(file);
var fileName = Path.GetFileName(filebase.FileName);
var path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Uploads/"), fileName);
filebase.SaveAs(path);
return "";
}
Please help me here, I need to upload the file using WebApi Method and JQuery AJAX,
Tried various suggestions on stack overflow but it did not worked
I am trying to set the message to "Data Loading.." whenever the data is loading in the grid. It is working fine if I don't make an Ajax call. But, when I try to make Ajax Request, It is not showing up the message "Loading data..", when it is taking time to load the data. Can someone please try to help me with this.. Thanks in Advance.
_loadData: function(x){
var that = this;
if(this.project!=undefined) {
this.setLoading("Loading data..");
this.projectObjectID = this.project.value.split("/project/");
var that = this;
this._ajaxCall().then( function(content) {
console.log("assigned then:",content,this.pendingProjects, content.data);
that._createGrid(content);
})
}
},
_ajaxCall: function(){
var deferred = Ext.create('Deft.Deferred');
console.log("the project object ID is:",this.projectObjectID[1]);
var that = this;
console.log("User Reference:",that.userref,this.curLen);
var userObjID = that.userref.split("/user/");
Ext.Ajax.request({
url: 'https://rally1.rallydev.com/slm/webservice/v2.0/project/'+this.projectObjectID[1]+'/projectusers?fetch=true&start=1&pagesize=2000',
method: 'GET',
async: false,
headers:
{
'Content-Type': 'application/json'
},
success: function (response) {
console.log("entered the response:",response);
var jsonData = Ext.decode(response.responseText);
console.log("jsonData:",jsonData);
var blankdata = '';
var resultMessage = jsonData.QueryResult.Results;
console.log("entered the response:",resultMessage.length);
this.CurrentLength = resultMessage.length;
this.testCaseStore = Ext.create('Rally.data.custom.Store', {
data:resultMessage
});
this.pendingProjects = resultMessage.length
console.log("this testcase store:",resultMessage);
_.each(resultMessage, function (data) {
var objID = data.ObjectID;
var column1 = data.Permission;
console.log("this result message:",column1);
if(userObjID[1]==objID) {
console.log("obj id 1 is:",objID);
console.log("User Reference 2:",userObjID[1]);
if (data.Permission != 'Editor') {
deferred.resolve(this.testCaseStore);
}else{
this.testCaseStore = Ext.create('Rally.data.custom.Store', {
data:blankdata
});
deferred.resolve(this.testCaseStore);
}
}
},this)
},
failure: function (response) {
deferred.reject(response.status);
Ext.Msg.alert('Status', 'Request Failed.');
}
});
return deferred;
},
The main issue comes from your Ajax request which is using
async:false
This is blocking the javascript (unique) thread.
Consider removing it if possible. Note that there is no guarantee XMLHttpRequest synchronous requests will be supported in the future.
You'll also have to add in your success and failure callbacks:
that.setLoading(false);
I am using the example here as a starting point. Everything works fine, I can submit the data back to the server and get a response. However I don't know how to connect the callback from the ajax to the jqgrid onclickSubmitLocal. I don't want to use alerts because even if there is an error the row is updated. I would like some how if there is an error the modal edit dialog to show the error and prevent it from updating the row. On success I would like the user to get a message saying data was saved.
Here is the relevant code:
function submitData(rowData){
var dataToSend = JSON.stringify(rowData);
$.ajax({
url: '/save',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: dataToSend,
dataType: 'json',
success: function (result) {
alert(' successfully saved.');
},
error: function(xhr, status, error) {
alert('Error processing submit ' + xhr.responseText);
}
});
}
I called the previous function from
onclickSubmitLocal = function (options, postdata) {
var $this = $(this), p = $(this).jqGrid("getGridParam"),// p = this.p,
idname = p.prmNames.id,
id = this.id,
idInPostdata = id + "_id",
rowid = postdata[idInPostdata],
addMode = rowid === "_empty",
oldValueOfSortColumn,
newId,
idOfTreeParentNode;
... same as in example from link above
if (postdata[p.sortname] !== oldValueOfSortColumn) {
// if the data are changed in the column by which are currently sorted
// we need resort the grid
setTimeout(function () {
$this.trigger("reloadGrid", [{current: true}]);
}, 100);
}
// !!! the most important step: skip ajax request to the server
options.processing = true;
submitData([postdata]);
},
I have a strange problem here (May be the silly one).
In the below code I declare the variable retVal and assigned null to it.
On the successful execution of code and I reassigned it with the return value (msg.d).
It successfully show the value at alert(retVal + " divyansh"); but when I tried the same at alert(retVal + " divyansh again"); I got null.
I know I can get the value by putting the "return retVal" inside the success but I want to know why this happen and if there is way to return the value at the bottom.
function getGrpParent() {
var retVal = null;
var hidType = $('[Id$=hidType]').val();
var hidGpId = $('[Id$=hidSelectedId]').val();
if (hidType == 'gp') {
var url = "../User/UserHierar.aspx/GetParentGroup";
var option = {
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: url,
data: JSON.stringify({ GroupId: hidGpId }),
success: function (msg) {
if (msg.d != "") {
retVal = msg.d;
alert(retVal + " divyansh");
}
},
error: function (err) {
alert('error');
}
};
$.ajax(option);
}
alert(retVal + " divyansh again");
return retVal;
}
A simple fix would be to move the variable retVal outside of the scope of just your function, to make it global. The success function as Jason correctly points out above is executed in its own context, outside of the scope of getGrpParent().
I hope this helps.
P.S. You should ask Jason to create an answer and accept it.
I am trying to submit a form using ajax and want to check to see if the
correct values are sent. How do I do it using the following. Currently, it is sending it to a MVC controller, but I do not want to do that. Is there a way to just sent to the same view page and show all the values???
$(document).ready(function () {
$("#btnSubmit").click(sendValues);
});
function sendValues() {
var a = store.data.items;
var array = new Array();
for (var i = 0; i < store.data.items.length; i++) {
array[i] = store.data.items[i].data;
}
for (var i = 0; i < array.length; i++) {
if (array[i].value == "Using") {
array[i].value = true;
}
else {
array[i].value = false;
}
}
var ClintJSON =
{
"Exempt": Ext.getCmp("mmrComboBox").isIndexSelected(2),
"MM1": Ext.getCmp("mmrComboBox").isIndexSelected(3),
"MM2": Ext.getCmp("mmrComboBox").isIndexSelected(4),
"MM3": Ext.getCmp("mmrComboBox").isIndexSelected(5),
"B1": Ext.getCmp("BComboBox").isIndexSelected(2),
"B2": Ext.getCmp("BComboBox").isIndexSelected(3),
"B3": Ext.getCmp("BComboBox").isIndexSelected(4)
};
$.ajax({
jsonp: null,
jsonpCallback: null,
type: 'POST',
url: '#Url.Content("~/Site/Test")',
data: "{clinsite: " + Ext.util.JSON.encode(ClintJSON) + ", List: " + `
Ext.util.JSON.encode(array) + "}",
dataType: 'json'
, contentType: 'application/json; charset=utf-8'
, success: function (data) {
if (data.success) {
showMessage('Site requirements have been updated successfully');
store.load({ params: { start: 0, limit: 52} });
} else {
showMessage('Site requirements have NOT been updated!!! ');
store.load({ params: { start: 0, limit: 50} });
}
}
});
There is one tool that I cannot recommend enough in this type of scenario, Fiddler2.
You can download it here
It enabled you to examine exactly what is passed to and from the server and you can view the data in various formats i.e. json, web form data or plain old text.
You can also use Composer to simulate http requests, which has its obvious benefits.
As a profession web applications developer, I use this tool all day every day, like I said I can't recommend it enough!!
Cheers
Baz
you can inspect the values in firefox using firebug console or in chrome tools, just press f12 and a window will open infront of your
moreover you can log the ClientJaon to the console liek
console.log(ClintJSON );