This may turn out to be a stupid mistake on my part, but my JSON object array is behaving unexpectedly.  The JSON object insertDoc has startDate and endDate fields and i'm trying to create a new object for each day in between -              var insertDocs = [];             var finalDate = insertDoc.endDate;                  while (insertDoc.startDate &lt;= finalDate) {                     insertDoc.endDate =  insertDoc.startDate;                     console.log('doc is ' + JSON.stringify(insertDoc));                     insertDocs.push(insertDoc);                     insertDoc.startDate = new Date(moment(insertDoc.startDate).add(1, 'days'));                  }              ...              for (var i = 0; i &lt; insertDocs.length; i++) {                 console.log(JSON.stringify(insertDocs[i]));             }   Here's the browser output -   doc is {"description":"testtask","endDate":"2019-04-01T00:00:00.000Z","startDate":"2019-04-01T00:00:00.000Z","status":"OPEN"} doc is {"description":"testtask","endDate":"2019-04-02T00:00:00.000Z","startDate":"2019-04-02T00:00:00.000Z","status":"OPEN"} doc is {"description":"testtask","endDate":"2019-04-03T00:00:00.000Z","startDate":"2019-04-03T00:00:00.000Z","status":"OPEN"} doc is {"description":"testtask","endDate":"2019-04-04T00:00:00.000Z","startDate":"2019-04-04T00:00:00.000Z","status":"OPEN"} doc is {"description":"testtask","endDate":"2019-04-05T00:00:00.000Z","startDate":"2019-04-05T00:00:00.000Z","status":"OPEN"}   Output of stringify - same doc printed 5 times   {"description":"testtask","endDate":"2019-04-05T00:00:00.000Z","startDate":"2019-04-06T00:00:00.000Z","status":"OPEN"}   So it seems each object is different and correctly printed but the array just seems to be 5 of the same object. The date values are different too  Am i missing something here?
330
The primitive types (number, string, etc.) are passed by value, but objects are unknown, because they can be both passed-by-value (in case we consider that a variable holding an object is in fact a reference to the object) and passed-by-reference (when we consider that the variable to the object holds the object itself).  Although it doesn't really matter at the end, I want to know what is the correct way to present the arguments passing conventions. Is there an excerpt from JavaScript specification, which defines what should be the semantics regarding this?
107508
I am working on a form widget for users to enter a time of day into a text input (for a calendar application). Using JavaScript (we are using jQuery FWIW), I want to find the best way to parse the text that the user enters into a JavaScript Date() object so I can easily perform comparisons and other things on it.  I tried the parse() method and it is a little too picky for my needs. I would expect it to be able to successfully parse the following example input times (in addition to other logically similar time formats) as the same Date() object:   1:00 pm 1:00 p.m. 1:00 p 1:00pm 1:00p.m. 1:00p 1 pm 1 p.m. 1 p 1pm 1p.m. 1p 13:00 13   I am thinking that I might use regular expressions to split up the input and extract the information I want to use to create my Date() object. What is the best way to do this?
17067
I have three rows on a Visualforce page. The requirement is that when any value of this field is blank it will show the error message on the page. I have to do this with the help of JSON and by using the following javascript function but I'm stuck. I am new on salesforce and JSON  &lt;script type="text/javascript"&gt;    var text = '{"val":['{"TValueFields"}' ] }';     obj = JSON.parse(text);              function findBlank() {             debugger;                        for (i=0; i&lt; obj.length; i++)               {                         var js = JSON.stringify(obj);              if(document.getElementById(js).value == " ")               {                          alert("TValueFields must be select");               }                     i++        } &lt;/script&gt;
108043
I'm seeing some unexpected behaviour with the locker service enabled when updating two fields on an object, one of which is nested inside a sub-object.   I have a lightning application that initialises a JavaScript object and passes references to fields on the object, and the object itself, as attributes to a contained component:  App Markup  &lt;aura:application &gt;     &lt;aura:attribute name="obj" type="object" /&gt;     &lt;aura:handler name="init" value="{!this}" action="{!c.init}" /&gt;      Top level value: &lt;ui:outputText value="{!v.obj.value1}" /&gt; &lt;br/&gt;     Nested value: &lt;ui:outputText value="{!v.obj.sub.value2}" /&gt; &lt;br/&gt;      &lt;c:MultiFieldTest obj="{!v.obj}" value1="{!v.obj.value1}" value2="{!v.obj.sub.value2}" /&gt;      &lt;br/&gt;      &lt;button onclick="{!c.showObj}"&gt;Show Object&lt;/button&gt; &lt;/aura:application&gt;   app controller  ({     init : function(component, event, helper) {         helper.init(component);     },     showObj : function(component, event, helper) {         helper.showObj(component);     } })   app helper:  ({     init : function(cmp) {         var obj={value1:'', sub:{value2:''}};         cmp.set('v.obj', obj);     },     showObj : function(cmp) {         alert('Object = ' + JSON.stringify(cmp.get('v.obj')));     } })   So the concept is there is an object with the structure:  {value1:'',   sub:{      value2:''} }   and I want to pass value1 and sub.value2 as attributes to a component that will update them. However, to ensure that the changes are propagated up and down the food chain (as per : ) I am also passing in the object itself. Essentially I want the contained component to update a couple of fields and propagate the changes without having to know which fields it is updating.  The containing component markup:  &lt;aura:component&gt;     &lt;aura:attribute name="value1" type="String" /&gt;     &lt;aura:attribute name="value2" type="String" /&gt;     &lt;aura:attribute name="obj" type="object"/&gt;      &lt;button onclick="{!c.setValues}"&gt;Set Values&lt;/button&gt;  &lt;/aura:component&gt;   controller:  ({     setValues : function(component, event, helper) {         helper.setValues(component);     } })   helper:  ({     setValues : function(cmp) {         var obj=cmp.get('v.obj');         console.log('Obj before = ' + JSON.stringify(obj));          cmp.set('v.value1', 'Value 1');         cmp.set('v.value2', 'Value 2');           obj=cmp.get('v.obj');         console.log('Obj after = ' + JSON.stringify(obj));          cmp.set('v.obj', obj);     } })   So when the user clicks the button, strings are set into the value1/value2 attributes and the underlying object 'reset' into the page. I then click on the 'Show Object' button, and the results are as expected with the locker service deactivated.   However, when I activate the locker service, only the second update 'sticks' and obj.value1 is empty, although both ui:outputText elements show the value1/value2 details as expected. What appears to be happening is that setting the first attribute updates the page as expected, and the object, but setting the second attribute updates the page and an earlier version of the object, minus the value1 details.  However, if I don't get the obj attribute at the beginning of the setValues method, it works:  setValues : function(cmp) {     // var obj=cmp.get('v.obj'); &lt;---- removed this      cmp.set('v.value1', 'Value 1');     cmp.set('v.value2', 'Value 2');       var obj=cmp.get('v.obj');     console.log('Obj after = ' + JSON.stringify(obj));      cmp.set('v.obj', obj); }   So pretty easy to work around, but I'm curious as to why this would be necessary with the locker service enabled - there's no secure versions of anything in play and the attributes are all accessible to the component. Its almost like the act of looking at the object fixes a version somewhere, and all updates retrieve that version before applying their update, rather than retrieving the latest version.
26027
How do I append an object (such as a string or number) to an array in JavaScript?
34916
I have an issue which I've been struggling with today. The JSON is returned back to me with a project Id as the key, this Project Id is dynamically generated and due to this I have not been able to come up with a way to deserialize this response. Any suggestions?   {      "success":true,    "numRows":5,    "data":{         "23000079":{            "projectId":"23000079",          "name":"Mcdonalds",          "departmentId":"9383",          "responsibleUserId":"7444434"       }    } }
106040
I've been using Javascript's Date for a project, but noticed today that my code that previously worked is no longer working correctly. Instead of producing Feb as expected, the code below produces March.   My code looks something like this:   current = new Date(); current.setMonth(current.getMonth()+1); //If today is Jan, expect it to be Feb now   This code worked everyday up until today. Is this a Javascript bug or am I going about this the wrong way?
115786
Given this form    $form['date'] = array(   '#prefix'=&gt;t('When do you want to start the featured campaign?'),   '#date_format' =&gt; 'Y-m-d',   '#date_year_range' =&gt; '0:+1',   '#type' =&gt; 'date_popup',   '#weight'=&gt;0   );   is there a way to display only future dates in the javascript popup ?  I can't seem to figure it out. Thanks alot.
26657
Below is my code to read items from a document library.  var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('DocumentList')/items?$select=customerID"; $.ajax({       url: url,       method: "GET",       headers: {           "Accept": "application/json; odata=verbose"       },       success: function(data) {           $.each(data.d.results, function(index, item) {             arrayCustomerID[index] = item.customerID;         });       },       error: function(data) {           console.log("error");       }   });     This work for the normal case but what should I do so that it works if I have more than 5000 items in the document library.
122089
I try to add an item to my sharepoint list from a custom web part. Is there any mistake in my code?  [WebMethod]         public static string AjouterDemande()         {             SPList ListeDemandeConge = SPContext.Current.Site.RootWeb.Lists["DEMANDE CONGÉ"];             SPListItem ListItem = ListeDemandeConge.Items.Add();             ListItem["CODE"] = code;             ListItem["DEMANDEUR"] = Utilisateur.LoginName;             ListItem["DATE DEMANDE"] = DateTime.Today.Date;             ListItem["DATE FIN"] = EndDateD;             ListItem["DATE DEPART"] = StartDateD;             ListItem["DUREE"] = int.Parse(DayCount);             ListItem["PREMIER RESPONSABLE"] = Employe.FirstSuperior.LoginName;             ListItem["DEUXIEME RESPONSABLE"] = Employe.SecondSuperior.LoginName;             ListItem["PRESENCE PRES"] = Boolean.Parse(FirstRespPresent);             ListItem["SOLDE CONGE"] = Conge.SoldeAnneeConge;             ListItem["MOIS"] = int.Parse(StartDateTab[1]);             ListItem["ANNEE"] = int.Parse(StartDateTab[0]);             ListItem["JOURS APPROUVEES"] = 0;             ListItem.Update();             ListeDemandeConge.Update();             return "true";          }   When I use F10 to process debugging step by step and get to my listitem.update(), it went out without giving any error.
116296
Anytime I have to handle dates/times in java it makes me sad   I'm trying to parse a string and turn it into a date object to insert in a preparepared statement. I've been trying to get this working but am having no luck. I also get the helpful error message when I go to compile the class.  "Exception in thread "main" java.lang.Error: Unresolved compilation problem:  The method setDate(int, Date) in the type PreparedStatement is not applicable for the arguments (int, Date)"  Eh WTF?  Here is the offending code.  for(int i = 0; i &lt; flights.size(); i++){      String[] details = flight[i].toString().split(":");      DateFormat formatter ;      formatter = new SimpleDateFormat("ddMMyyyy");     Date date = formatter.parse(details[1]);       PreparedStatement pstmt = conn.prepareStatement(insertsql);     pstmt.setString(1, details[0]);     pstmt.setDate(2, date);     pstmt.setString(3, details[2] + "00");     pstmt.setString(4, details[3]);     pstmt.setString(5, details[4]);     pstmt.setString(6, details[5]);     pstmt.setString(7, details[6]);     pstmt.setString(8, details[7]);     pstmt.setString(9, details[8]);     pstmt.executeUpdate();  }
113519
I'm having a save method with several Conditions in it.Here is my apex class  invoiceset = [select SiteUrl__c, Prefix__c,Seperator__c,Seperator1__c,DateValue__c,DateValue1__c,Date_Format__c,Incrementer__c,Counter_Val1__c,counter__c from Invoice_setting__c limit 1];        if(invoiceSet[0].DateValue__c == 'Date' &amp;&amp; invoiceSet[0].DateValue1__c == 'Date'){         if(invoiceSet[0].Date_Format__c == 'dd-mm-yyyy'){              datenow = DateTime.now().format('dd-MM-yyyy');                   }else if(invoiceSet[0].Date_Format__c == 'MM-dd-yyyy'){              datenow = DateTime.now().format('MM-dd-yyyy');                     }else if(invoiceSet[0].Date_Format__c == 'dd/MM/yyyy'){              datenow = DateTime.now().format('dd/MM/yyyy');          }else if(invoiceSet[0].Date_Format__c == 'mm/dd/yyyy'){              datenow = DateTime.now().format('mm/dd/yyyy');          }else if(invoiceSet[0].Date_Format__c == 'yy'){              datenow = DateTime.now().format('yy');          }else if(invoiceSet[0].Date_Format__c == 'yyyy'){              datenow = DateTime.now().format('yyyy');          }           prefixName = invoiceset[0].prefix__c + invoiceSet[0].seperator__c + datenow + invoiceset[0].Seperator1__c + datenow;       }      else if(invoiceSet[0].DateValue__c == 'Counter' &amp;&amp; invoiceSet[0].DateValue1__c == 'Counter'){       if(invoiceSet[0].counter_val1__c == null){          invoiceSet[0].Counter_Val1__c = invoiceset[0].Counter__c;        }else if(invoiceSet[0].Counter_Val1__c == invoiceset[0].Counter__c){            intt = integer.valueof(invoiceSet[0].Counter__c) + integer.valueOf(invoiceSet[0].Incrementer__c) ;            invoiceSet[0].Counter_Val1__c = string.valueOf(intt) ;        }else {             intt = integer.valueof(invoiceSet[0].Counter_Val1__c) + integer.valueOf(invoiceSet[0].Incrementer__c) ;            invoiceSet[0].Counter_Val1__c = string.valueOf(intt) ;        }        update invoiceset;         prefixName = invoiceset[0].prefix__c + invoiceSet[0].seperator__c + invoiceSet[0].Counter_Val1__c + invoiceset[0].Seperator1__c +invoiceset[0].Counter_Val1__c;       } &amp;&amp; so on........   Inorder to cover all this conditions should I write those many methods or any other easy way?  Here is my Test Code  public static testmethod void test(){    invoice_setting__c setng = new invoice_setting__c(Name='Invoice Settings',SiteUrl__c='www.google.com',Prefix__c='Test',Seperator__c = '-',dateValue__c = 'Date',Seperator1__c = '/',dateValue1__c = 'Date',date_format__c='dd-mm-yyyy');     insert setng; } public static testmethod void test1(){     invoice_setting__c setng1 = new invoice_setting__c(Name='Invoice Settings',Prefix__c='Test',Seperator__c = '-',dateValue__c = 'Counter',Seperator1__c = '/',Counter_Val1__c=null,dateValue1__c = 'Counter',date_format__c='dd-mm-yyyy',Incrementer__c='10');     insert setng1; } &amp; so on......   Any Suggestions for this please
89360
I do not have any idea about this, but I am trying to create JSON using Apex class.  I think it can be done using serialize method.  But I need a simple example so that I can understand the procedure. Any example or easy to understand link would be really appreciated.
3270
How can I serialize an object to JSON in JavaScript?
91152
I have a small requirement where in i need to remove the duplicate values from the array that i am getting.  Overview In the below code, what i am trying to do is to get top 1000 employee names(Should Cost Modeler People Picker Field) through REST API from List A and appending those values in LIST B Drop down. But as i get all the names through REST API there are many duplicate values in the array.   What i would like to do is to remove the duplicate values and then append the values to drop down.  //Get the employee names  function getAllEmployeeNames(){ var results; $.ajax({     url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('Should Cost Projects')/items?$select=Should_x0020_Cost_x0020_Modeler/Title&amp;$expand=Should_x0020_Cost_x0020_Modeler/Id&amp;$top=500",     type: "GET",     async:false,     headers: {         "Accept": "application/json;odata=verbose",     },     success: function (data) {         if(data.d.results.length&gt;0){             results=data.d.results;         }     },     error: function (data) {     //alert("Error");     } }); return results;   }   // To Append the Employee Name to drop down on form load.  var employeeName=$("input[title^='Employee Name']").val(); $("input[title^='Employee Name']").hide(); $("input[title^='Employee Name']").after("&lt;select id='EmployeeField' class='ms-RadioText'&gt;&lt;option value=''&gt;&lt;/option&gt;&lt;/select&gt;"); $("input[title^='Project Name']").hide(); $("input[title^='Project Name']").after("&lt;select id='ProjectField' class='ms-RadioText'&gt;&lt;option value=''&gt;&lt;/option&gt;&lt;/select&gt;"); var allEmployeeNames=getAllEmployeeNames(); console.log(allEmployeeNames);       $.each(allEmployeeNames,function(i,employee){     $.each(employee.Should_x0020_Cost_x0020_Modeler.results,function(j,item){         if(employeeName==item.Title){             $("#EmployeeField").append("&lt;option selected='selected' value='"+item.Title+"'&gt;"+item.Title+"&lt;/option&gt;");         }else{             if(item.Title!=undefined){                 $("#EmployeeField").append("&lt;option value='"+item.Title+"'&gt;"+item.Title+"&lt;/option&gt;");             }                    }        });          });   // the code that i am using to remove duplicates but it is not working.  $(allEmployeeNames).each(function() {     $(this).siblings('[value="'+ $(this).val() +'"]').remove(); });     Please help me solve this problem.  Thanks
80895
Why does this javascript return 108 instead of 2008? it gets the day and month correct but not the year?  myDate = new Date(); year = myDate.getYear();   year = 108?
81419
Is it possible to use the =today() function (or something else) to insert the current date but then not update each time the file is opened?  I want to create a numbers template for my invoices. I'd like it to auto fill invoice date and date due then, when I save the document, store the values, not the function.