Gettin Null response in calculation

Answered

Comments

15 comments

  • Victor Lavrentyev

    if (!string) {
    string = '';
    }

    0
    Comment actions Permalink
  • Christopher Gibbins

    I used the script below and I get "Unexpected token if"

    if (!string) {
    string = '';
    }

    0
    Comment actions Permalink
  • Victor Lavrentyev

    http://puu.sh/a1Z83/039d3890bb.png

    var MyString = @MyTextField;
    if (!MyString) {
    MyString = "";
    }
    MyString;

    0
    Comment actions Permalink
  • Ganesh Shankar

    Hi, try using a , a = (@variable 1 + ' ' + @variable 2) ;

    thanks

    0
    Comment actions Permalink
  • Christopher Gibbins

    Thank you for your contributions I added what you suggested and I am still getting a null response.
    Here is what I have.

    var MyString = First Name + " " + Last Name; if (!MyString) {
    MyString = "";
    }
    MyString;

    0
    Comment actions Permalink
  • Ganesh Shankar

    Hi,

    Check whether those field are "required " and try ,use single quotes as i have put here please , thanks

    0
    Comment actions Permalink
  • Victor Lavrentyev

    I realized. You need to check a Null before concatination. For example:

    var result = (@First Name ? @First Name : "");
    result += " " + (@Last Name ? @Last Name : "");
    result;

    1
    Comment actions Permalink
  • Christopher Gibbins

    That did the trick. Thanks

    0
    Comment actions Permalink
  • Robert Taylor

    I need some help with this exact same thing, but I know no javascript at all. I am completely unfamiliar with the syntax other that what I've seen here. I have this in my calcuation field:

    @Salutation + @Frist Name + @Last Name + @Suffix

    Of course if the Salutation and Suffix fields are empy, it outputs this: null John Doe null

    Can you share with me exactly what javascript to place in the calculation field to remove null for empty fields?

    Thanks.

    0
    Comment actions Permalink
  • Robert Taylor

    Well I'm not sure what it means or why it works, but this successfully removes null for empty fields:

    var result = (Salutation ? Salutation : "");
    result += " " + (First Name ? First Name : "");
    result += " " + (Last Name ? Last Name : "");
    result += " " + (Suffix ? Suffix : "");

    0
    Comment actions Permalink
  • Joshua C Melum, EA

    I am trying to do the same as Robert with one small difference.  I will always have a TP Last Name and TP First Name, however the SP First name is really the only variable.  This calc leaves "AND" at the end in all cases.  I only want it to appear and separte TP First Name and SP First Name if SP First Name actually exists.

    result = (@TP Last Name ? @TP Last Name : "");
    result+=", "+(@TP First Name ? @TP First Name:"");
    result+=" AND "+(@SP First Name ? @SP First Name:"");

    Thank you

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Joshua,

    this should work:

    var tpLast  = @TP Last Name ? @TP Last Name : "";
    var tpFirst = @TP First Name ? ", " + @TP First Name : "";
    var spFirst = @SP First Name ? " AND " + @SP First Name : "";
    tpLast + tpFirst + spFirst

    Or shorter, cause you always have tpLast and tpFirst:

    var spFirst = @SP First Name ? " AND " + @SP First Name : "";
    @TP Last Name + ", " + @TP First name + spFirst

    Rainer

    0
    Comment actions Permalink
  • Joshua C Melum, EA

    Both worked perfectly.  Thank you Rainer!

    0
    Comment actions Permalink
  • Lee Standell

    I've also got an issue which is similar to your problem and the solutions below don't seem to fit what I'm trying to do.

    I have a Calculation field at the top of my contact app Called Contact. Below this I have 2 text fields 1 called Company name and another called Customer Name.

    What I want to happen is that if there isn't a company name, the contact calculation will only show the customer name but if there is a company name as well as a customer name I only want the Company name to show in the contact calculation.

    I need this to show right as when I ping the details over to Xero, it's been sending over the Company Name - Customer name which is making xero create the customer as a new contact as the name is different.

    Does that make sense? :)

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Lee,

    this should work:

    var com = @Company Name;
    var cust = @Customer Name;
    com == null ? cust : com

    Rainer

    1
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk