title: Adding IF logic within a let body when using Asana API body parameter
body: <p>I am utilizing Zapier and the <a href="https://developers.asana.com/docs/create-a-task" rel="nofollow noreferrer">Asana API</a> to create a task within Zapier's Javascript (uses Node 10) code action. Below is my current code, which currently works as expected.</p>
  <p>However, I'd like to update it, to add logic that will allow me to change some of the data objects if the Start Date and End Date are the same.</p>
  <pre><code>// this is wrapped in an `async` function
  // you can use await throughout the function
  
  // get personName
  var personName = inputData.personName;
  // set dateStart
  const dateStart = inputData.dateStart;
  // convert the format of MM/DD/YYYY to YYYY-MM-DD for Asana's use
  var dateStartFormatted = new Date(dateStart).toISOString().split('T')[0];
  // set dateEnd
  const dateEnd = inputData.dateEnd;
  // convert the format of MM/DD/YYYY to YYYY-MM-DD for Asana's use
  var dateEndFormatted = new Date(dateEnd).toISOString().split('T')[0];
  // get dateDuration
  var dateDuration = inputData.dateDuration;
  // get taskURL from the custom fields above
  var theURL = inputData.eventLink;
  // encode the URL
  var theEventLinkFinal = encodeURI(theURL);
  // get dateStartPretty
  var dateStartPretty = inputData.dateStartPretty;
  // get dateEndPretty
  var dateEndPretty = inputData.dateEndPretty;
  // get projectSection
  var projectSection = inputData.projectSection;
  
  // sets custom dropdown field of Team Member to value of OFF
  // sets the start date and end date
  // sets the task Name based on person chosen in Google Form
  // sets task description (notes) with date range, number of days, and link to Google Calendar event
  // sets Asana project to &quot;Timeline&quot; and section of the person chosen in the Google Form
  // adds Admin and HR users as followers on the task
  let body = {
    &quot;data&quot;: {
      &quot;custom_fields&quot;: {
        &quot;917734345465519&quot;: &quot;917734345465549&quot;
      },
      &quot;start_on&quot;: dateStartFormatted,
      &quot;due_on&quot;: dateEndFormatted,
      &quot;name&quot;: personName + &quot; Off&quot;,
      &quot;notes&quot;: &quot;Date range: &quot; + dateStartPretty + &quot; – &quot; + dateEndPretty + &quot;\n\nTotal number of days: &quot; + dateDuration + &quot;\n\nCalendar link: &quot; + theEventLinkFinal,
      &quot;memberships&quot;: [ 
        {
          &quot;project&quot;: &quot;893079009430519&quot;,
          &quot;section&quot;: projectSection
        }
      ],
      &quot;followers&quot;: [
        &quot;670933960116792&quot;,
        &quot;7747475052050&quot;
      ],
      &quot;workspace&quot;: &quot;301669572129&quot;
    }
  };
  // create the task based on the body and data
  const res = await fetch('https://app.asana.com/api/1.0/tasks', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json', 
      'Authorization': 'Bearer 0/XXXXXXXX'
    },
    body: JSON.stringify(body)
  });
  const data = await res.json();
  output = {data: data};
  </code></pre>
  <p>The goal is to update the above code, so:</p>
  <p>IF dateStartFormatted === dateEndFormatted ... THEN swap out these two lines of data:</p>
  <pre><code>&quot;start_on&quot;: dateStartFormatted,
  &quot;due_on&quot;: dateEndFormatted,
  </code></pre>
  <p>And replace with this line of data:</p>
  <pre><code>&quot;due_at&quot;: dateStartFormatted,
  </code></pre>
  <p>I tried doing if/else statements within the <code>let body</code>, but to no avail.</p>