I want to code an html button with jQuery, when chart button is pressed, will take values from some text inputs, prepare a json of them and will perform a get request including the json with values.
$(".chart").click(function(){
var args = {}
args['fx'] = $("#tolerancia").val()
args['a'] = $("#a").val()
args['b'] = $("#b").val()
args['tolerancia'] = $("#tolerancia").val()
args['iteracionesMaximas'] = $("#iteracionesMaximas").val()
$.get("/taylor",{args},function(resultado){
console.log(resultado)
})
})
I'm getting an Invalid object initializer message in console right on line of:
$.get("/taylor",{args},function(resultado){
What have I got wrong?
Change your code to:
$.get("/taylor", args, function(resultado) {
console.log(resultado)
});
Note: {args} is invalid syntax. args is already an object, so you don't need to wrap it in any other brackets.
Related
I've created Multi-select option-set field (category) in Dynamics CRM on-premise for Contact and Projects. Now using button click I'm trying to set the value of multi-select field on Project. But each time I am coming across with Error:
Error converting value 920650008 to type System.Collections.Generic.List 1[System.Int32].
Since the multi-select optionset field is global so there is no chance of specified values available or not.
Here is what I am trying previously:
var name = formContext.getAttribute(new.account_metada.CompanyName).getValue();
var entityFormOptions["entityName"] = "new_projects";
entityFormOptions["openInNewWindow"] = true;
var formParameters["new_company"] = id;
formParameters["new_companyname"] = name;
formParameters["new_category"] = formContext.getAttribute("new_category").getValue()
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
Please let me know how to can I set value of multi-select optionset using Xrm.Navigation.openForm
I got fix the issue by replacing below source code line:
Existing
formParameters["new_multiselectpicklist"] = formContext.getAttribute("new_multiselectpicklist").getValue();
Updated
formParameters["new_multiselectpicklist"] = "["+formContext.getAttribute("new_multiselectpicklist").getValue()+"]";
I tested this personally and getting the same error result with the below snippet. Though the syntax is right - Something could be wrong with the Xrm.Navigation.openForm() method or this could be expected behavior because of unsupported Array datatype.
var entityFormOptions = new Array();
entityFormOptions["entityName"] = "my_entity";
entityFormOptions["openInNewWindow"] = false;
var formParameters = new Array();
formParameters["new_multiselectpicklist"] = formContext.getAttribute("new_multiselectpicklist").getValue();
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
Even a hard code assignment getting the same error:
formParameters["new_multiselectpicklist"] = [962080001, 962080002];
Edit:
The above line should be like this to make it work.
formParameters["new_multiselectpicklist"] = "[962080001, 962080002]";
I tried this alternate option using extraqs and it worked.
https://mycrmdev.crm.dynamics.com/main.aspx?etn=my_entity&pagetype=entityrecord&extraqs=new_multiselectpicklist=[962080001, 962080002]
I am trying to see if a value in the "apply" sublist for customer payment data has changed and do some action based on it.
My SuiteScript is as follows:
define(['N/record', 'N/https'],
function(record,https)
{
function afterSubmit(context)
{
var oldRec = context.oldRecord;
log.debug({title: 'oldRec ', details: oldRec });
// This log shows that the JSON has an
// attribute called sublists which contains "apply" which has all the applied payments
// eg: {"id":"1234", "type":"customerpayment", "fields":{all the fields},
// "sublists": {"apply" : {"line 1"...}}}
var oldRecSublists = oldRec.sublists;
log.debug({title: 'oldRecApply ', details: oldRecSublists });
// This returns empty or null though there is data
What am I doing wrong here?
Basically what I am trying to achieve is compare the context.oldRecord.sublists.apply and context.newRecord.sublists.apply to find if the amt has changed or not.
Is there a better way to do this is SuiteScript 2.0?
Thanks in advance!
Part of what is going on there is that it looks like you are trying to spelunk the NS data structure by what you see in the print statement. You are not using the NS api at all.
When you send the NS object to the log function I believe it goes through a custom JSON.stringify process so if you want to just inspect values you can do:
var oldRecObj = JSON.parse(JSON.stringify(oldRec));
now oldRecObj can be inspected as though it were a simple object. But you won't be able to manipulate it at all.
You should be using the NS schema browser
and referring to the help docs for operations on N/record
A snippet I often use for dealing with sublists is:
function iter(rec, listName, cb){
var lim = rec.getLineCount({sublistId:listName});
var i = 0;
var getV = function (fld){
return rec.getSublistValue({sublistId:listName, fieldId:fld, line:i});
};
var setV = function(fld, val){
rec.setSublistValue({sublistId:listName, fieldId:fld, line:i, value:val});
};
for(; i< lim; i++){
cb(i, getV, setV);
}
}
and then
iter(oldRec, 'apply', function(idx, getV, setV){
var oldApplied = getV('applied');
});
I can't get my head around setting up an array in Google script (Which is based off Javascript).
I have a list of countries, 'AU' and 'NZ' that I need in the array, this will be added to later. I will need to search the array later to check if a string matches a value in the array.
I've tried adding the array several ways in Google script.
First attempt:
List<String> country_list = new ArrayList<String>();
country_list.add("AU");
country_list.add("NZ");
This Throws up a Syntax error. on the 1st line.
A variation on this:
Second attempt:
var country_list = [];
country_list.add("AU")
country_list.add("NZ")
Throws up the error TypeError: Cannot find function add in object . on the 2nd line.
Third attempt:
var Country_List = ["AU","NZ"];
if (country_list.contains("AU")) {
// is valid
ui.alert("great success");
} else {
// not valid
ui.alert('Nope try again');
}
This throws up an error 'TypeError: Cannot find function contains in object...'
That makes sense so I tried converting to Array.asList().
Fourth attempt:
var original_country_list = ["AU","NZ"];
List<String> country_list = Arrays.asList(original_country_list)
if (country_list.contains("AU")) {
// is valid
ui.alert("great sucsess");
} else {
// not valid
ui.alert('Nah Mate try again');
}
This throws up the error Invalid assignment left-hand side when using [] and () to hold original_country_list. When using {} to hold original_country_list it throws up the error Missing : after property ID.
The last thing I tried was:
Fifth attempt:
var original_country_list = ["AU","NZ"];
var country_list = Arrays.asList(original_country_list)
and this throws up the error ReferenceError: "Arrays" is not defined.
Apologies if this is obvious but what is going wrong here?
Most of what I see here looks closer to Java than Javascript. But #2 can be Javascript like this:
var country_list = [];
country_list.push("AU");
country_list.push("NZ");
3 can be fixed easily too:
var Country_List = ["AU","NZ"];
if (Country_list.indexOf("AU") > -1) {
// is valid
ui.alert("great success");
} else {
// not valid
ui.alert('Nope try again');
}
I just build a jquery plugin to handle some data storages.
when i try to read from storage, the result is the read item data. fine for now....
when i add
sessionStorage.setItem('test','some data');
or remove
sessionStorage.removeItem('test');
a item, i allways get a undefined in the console.log
but it do what i it should do.
how can i get rid of the undefined, any ideas ???
what i tried was
var result = sessionStorage.setItem('test','some data');
thought this would print it to a var but it won't ^^
my code:
(function ($) {
$.storage = {
add: function(name,value){
if(typeof value === 'object' )
{
/** convert object to json **/
value = JSON.stringify(value);
}
/** add to storage **/
sessionStorage.setItem(name,value);
},
read: function(name){
/** read from storage **/
var item = sessionStorage.getItem(name);
try {
item = $.parseJSON(item);
}catch(e){}
return item;
},
remove: function(name){
/** delete from storage **/
sessionStorage.removeItem(name);
},
clear: function(){
/** clear storage **/
sessionStorage.clear();
}
}
})(jQuery);
SOLUTION
I tried to add storage in console... when i used it in my script it returned nothing! SORRY
setItem and removeItem doesn't return any value. Thus you are getting undefined. Also note removeItem only accept one parameter.
Reference, Here is function sign for above methods
setItem(key:string, data:string):void
This public method stores data via specified key. Please note that if key was already stored, it will overwrite it. Another thing to consider is that if we store a key, and via sessionStorage.key(0) we obtain that key, then we store another key/data and finally we store again the first key, sessionStorage.key(0) will return the second key/data stored, and not the first one.
removeItem(key:string):void
This public method simply removes a key and related data from the storage.
var result = sessionStorage.setItem('test','some data');
does not return anything.
sessionStorage.setItem('test','some data');
assigns value to 'test'therefore the right hand side does not have any value.
What you want is
sessionStorage.setItem('test','some data');
var result = sessionStorage.getItem('test'); //<- here the right hand side is 'some data'
I am trying to implement the autocomplete with data from a database.
The data looks like
[
{"id":"1",name:"Jon"},
{"id":"2",name:"Carl"},
{"id":"3",name:"Jon"},
]
There is no example using such data even though this would be more common than selecting a string from a bunch of strings. Having the user select "Jon" doesn't mean anything unless you know the ID.
I was trying to add code to the following page and listen to an event when the user selects an item but first of all it's not documented in code and in the api what event that is and second none of the events seem to be triggered. Hopefully the event object would pass the object that was selected by the user (not the string) or the index of the selected item so I don't have to use access the private variable to get the object that was chosen.
ac1.dispose();
var DataItem = function(id,value){
this.id=id;
this.value=value;
};
DataItem.prototype.toString=function(){
return this.value;
};
DataItem.prototype.valueOf=function(){
return this.value;
};
var tcMovies = [
new DataItem(1,"one"),
new DataItem(2,"onetwo")
];
var ac1 = goog.ui.ac.createSimpleAutoComplete(
tcMovies, document.getElementById('txtInput1'), false);
goog.events.listen(ac1,goog.ui.ac.AutoComplete.EventType.SELECT,
function(e){
//never gets called
console.log(e);
//hoping to get an index so I can do something like
// ac1.getMatcher().rows_[selectedindex].id
// probably should not use rows_ but there is no get
// method for that either
}
);
Fiddling around a bit and looking through the source code I did find what hopefully is the way to implement it. The following comment in autocomplete.js would suggest it is the correct way:
/**
* Field value was updated. A row field is included and is non-null when a
* row has been selected. The value of the row typically includes fields:
* contactData and formattedValue as well as a toString function (though none
* of these fields are guaranteed to exist). The row field may be used to
* return custom-type row data.
*/
UPDATE: 'update',
Open the following page, press F12 and run the following code in the console.
//remove existing autocomplete
ac1.dispose();
//define data, need toString
// to display the values
var DataItem = function(id,value){
this.id=id;
this.value=value;
};
DataItem.prototype.toString=function(){
return this.value;
};
// create data
var tcMovies = [
new DataItem(1,"abbbbbbbb"),
new DataItem(2,"aabbbbbbb"),
new DataItem(3,"aaabbbbbb"),
new DataItem(4,"aaaabbbbb"),
new DataItem(5,"aaaaabbbb"),
new DataItem(6,"aaaaaabbb"),
];
// use easy method to create and attach the autocomplete
var ac1 = goog.ui.ac.createSimpleAutoComplete(
tcMovies, document.getElementById('txtInput1'), false);
//listen to UPDATE
goog.events.listen(ac1,goog.ui.ac.AutoComplete.EventType.UPDATE,
function(e){
//e.row should be the selected value
console.log("user selected",e.row);
}
);