Omitting blank arrays in deliveries

Follow

Typically, when posting to another CRM blank arrays aren't an issue. However if the CRM you're posting to is unable to deal with an array in the post with no data, this article should help you solve the problem.

Take the below XML delivery as an example:

<delivery>
<section_one>

<field1>[data1]</field1>
<field2>[data2]</field2>
</section_one>
<section_two>
<field3>[data3]</field3>
<field4>[data4]</field4>
</section_two>
</delivery>

 

Even if the entire section_two array was blank it would still be posted out as shown below:

<section_two>
<field3></field3>
<field4></field4>
</section_two>

 

However if the CRM you're posting to is unable to accept blank arrays, LeadByte allows you to use the IF statement within your delivery to prevent them from being posted out in the delivery.

Using the example delivery above:

<delivery>
<section_one>

<field1>[data1]</field1>
<field2>[data2]</field2>
</section_one>
{if $data3 != '' || $data4 != ''}
<section_two>
<field3>[data3]</field3>
<field4>[data4]</field4>
</section_two>
{/if}
</delivery>

 

The below key explains how the IF statement has been formatted in the post:

!= is not equal to
|| or
'' no data

 

Using this we can see the IF statement translates to IF "data3" "is not equal to" "no data" OR  "data4" "is not equal to" "no data" include the array in the delivery.

Or written in plain English: IF data3 is not empty OR data4 is not empty, post the section_two array.

 

The IF statement grants you a lot of flexibility and you can structure this statement as you require.

Make sure you enclose the array you wish to omit (when blank) with your IF statement.

If you would prefer to use an AND statement rather than or simply replace || with &&.

If you would prefer to use is equal to rather than is NOT equal to simply replace != with ==

 

Once you've written your statement you'll need to save you delivery, go back into the edit screen and enable the "advanced scripting" checkbox shown below:

Image_2019-11-26_at_2.55.36_PM.png

 

We've included a few examples below to help get you started:

{if $data1 == ''}
This will get outputted only if data1 is empty
{/if}
{if $data1 == 'horse'}
This will get outputted only if data1 equals "horse"
{/if}
{if $data1 != 'horse'}
This will get outputted only if data1 does not equal "horse"
{/if}
{if $data1 == 'horse' && $data2 == 'cow'}
This will get outputted only if data1 equals "horse" and data2 equals "cow"
{/if}
{if $data1 == 'sheep' || $data1 == 'donkey'}
This will get outputted only if data1 equals "sheep" or "donkey"
{/if}
Was this article helpful?
0 out of 0 found this helpful

Comments