0

Hi i have a problem with principles how to pass return value from apex method into the client.

I have an Apex class to create current Datetime

@AuraEnabled
public static Datetime calcPuDate() {
    Datetime puDate = Datetime.now();
    System.debug('PU IS YES #### ' + puDate);
    return puDate;
}

And i want to send puDate into the helper, where i have a function where i am calling apex method.

    calcDate : function (cmp, event, helper) {
          console.log("### calc date time in helper 1");
          var action = cmp.get("c.calcPuDate");
          setCallback(this, function(actionResult) {
                var status = actionResult.getState();
                console.log(actionResult.getState());
                console.log('Datetime vracene z APEXU ### ' + actionResult.getReturnValue())
         console.log(response.getReturnValue());

          });
          $A.enqueueAction(action);
console.log("### calc date time in helper 2");

},

But there is a problem with executing, it calling Action failed [setCallback is not defined] in client side controller function, where i need to set result into the field value.

passDateHere : function(cmp, event, helper) {               
var allCells = cmp.find("table-cell");
                if (allCells != null) {
                    for (var i = 0; i < allCells.length; i++) {
                        var cell = allCells[i];
                        if (cell.get("v.id") == event.getSource().get("v.id") && cell.get("v.fieldName") == 'Date_of_PU__c')  {
                            if ((cell.get("v.value")) == null) {
                                console.log("### calc date time in controller");
                                helper.calcDate(cmp);
    //                            allCells[i].set("v.value", today);
                            } else {
                                console.log("nic nesetovat");
                                return;
                            }
                        }
                    }
                }
1

First of all, did you know that you can get the current date and time using only Javascript with: var currentdate = new Date();

Then, the problem in your code is that the setCallback method is only available using your action variable with: action.setCallback(this, function(actionResult) {

  • yes i know about var currentdate = new Date(); but its sending it into apex in wrong format, its putting into the string letter "T". for example 2018-09-13T09:37:08.792Z – David Sep 13 '18 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.