Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

  1.  
    Hey everyone,

    I've got a date variable that needs to be passed via connector to another application in a specific format. I've looked online at the @NOW() formula usage but I'm struggling with the syntax.

    What I need is the date field to be written with the format as yyyyMMdd hh:mm

    If I try "@NOW(yyyyMMdd hh:mm)" I get an error. And the format for "@NOW()" without modification isn't anywhere near the format I need.

    Anyone have a good resource they could point me to for doing this?

    Thanks!
    • CommentAuthordbuschho
    • CommentTimeJul 29th 2010
     
    Hello Mike,

    Unfortunately Salesforce is very particular about what formats it accepts. The simplest solution is handle it on the Form side ( also simplest to debug ).

    Here's the formula to create a Salesforce formatted now field (include this in your custom code block):
    <script>
    function sf_date(){
    var now = new Date();
    var dy = now.getDate();
    var mo= now.getMonth()+1;
    var yr = now.getFullYear();
    var ind = "AM";
    var hr = now.getHours();
    if(hr >= 12){
    ind = "PM";
    hr = hr - 12;
    }
    if(hr == 0){
    hr = 12;
    }
    var min = now.getMinutes();
    if(min < 10){
    min = String.concat("0",min);
    }
    return mo+"/"+dy+"/"+yr+" "+hr+":"+min+" "+ind;
    }
    </script>

    then in the field you wish to hold a SF formated now date, place the following formula in the formula field:
    sf_date()

    Happy to help further,
    FA Support.
  2.  
    Thanks-- I actually need this for a Goldmine web import connector, not Salesforce... the output needs to be in the following format:

    yyyyMMdd hh:mm

    I tried rearranging this code, but the code for day & month do not give leading zeroes-- what is the command for that?

    Thanks for your help,

    Mike
  3.  
    Here's how I modified the script, it gives me an error now though...

    <script>
    function sf_date(){
    var now = new Date();
    var dy = now.getDate();
    if(dy < 10){
    dy = String.concat("0",dy);
    }
    var mo= now.getMonth()+1;
    if(mo < 10){
    mo = String.concat("0",mo);
    }
    var yr = now.getFullYear();
    var ind = "AM";
    var hr = now.getHours();
    var min = now.getMinutes();
    if(min < 10){
    min = String.concat("0",min);
    }
    return yr+mo+dy+" "+hr+":"+min;
    }
    </script>
    • CommentAuthordbuschho
    • CommentTimeAug 3rd 2010
     
    Hello Mike,

    What error do you get? Javascript or from the connector? Can you send us a link to form where the error is occurring?

    Happy to help,
    FA Support.
  4.  
    Here's a link to the form:
    https://forms.jax.org/forms/view/70

    The form itself shows an error where the hidden field falls, "There was an error computing this field."

    The connector itself works fine, but the variable "creaton" has a value of "error" in the submitted form due to the error.

    Thanks for your help!
    • CommentAuthordbuschho
    • CommentTimeAug 4th 2010
     
    Hello Mike,

    I think you're treating concat as a static function, when in reality it needs an instance to work from:
    String.concat vs String().concat
    http://www.w3schools.com/jsref/jsref_concat_string.asp

    Try the below, and if that still doesn't work for you, try replacing your String.concat("0",n)s with String("0").concat(n) which should be guaranteed to work.
    ---

    function sf_date(){
    var now = new Date();
    var dy = now.getDate();
    if(dy < 10){
    dy = String().concat("0",dy);
    }
    var mo= now.getMonth()+1;
    if(mo < 10){
    mo = String().concat("0",mo);
    }
    var yr = now.getFullYear();
    var ind = "AM";
    var hr = now.getHours();
    var min = now.getMinutes();
    if(min < 10){
    min = String().concat("0",min);
    }
    return yr+mo+dy+" "+hr+":"+min;
    }
  5.  
    That works great! Thanks so much, I'm only as good at Javascript as my google skills allow (I find stuff & reuse it, warts & all).
    • CommentAuthordbuschho
    • CommentTimeAug 5th 2010
     
    Np. Let us know if you need further assistance.