• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Detecting an empty date field with liquid

Participant ,
May 05, 2015 May 05, 2015

Copy link to clipboard

Copied

I have a Extended  CRM date field and I want to use liquid to detect whether it is an empty field (i.e no date has been selected yet)

My code so far (doesn't work)

{% capture datechanged -%}

      {module_customerfield,161768,19984689}

{% endcapture %}

{% if datechanged == "" -%}

   <p>Please select a date</p>

{% endif %}

The value that appears in the code seems to be an empty string, but it has a size value of 10, so I can't use a size filter either

What is the value of an empty date field?

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , May 06, 2015 May 06, 2015

I think I've got it to work.

I had to assign datechanged|strip|size to a variable. Code now is:

{% capture datechanged -%}

  {module_customerfield,161768,19984689}

{% endcapture %}

{% assign datesize = datechanged|strip|size %}

{% if datesize  == 0 -%}

<p>Please select a date</p>

{% endif %}

That seems to work, but it seems to be an excessively convoluted way of doing it.

Votes

Translate

Translate
LEGEND ,
May 05, 2015 May 05, 2015

Copy link to clipboard

Copied

Try applying filters to strip html, new lines, spaces etc and see if after that an if will work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 05, 2015 May 05, 2015

Copy link to clipboard

Copied

You are setting Datechanged capture to pick up a field that may be blank to begin with.  This may be a null value.  It may simply be the system representation of NULL.  It's not anything really, just that an object is completely empty.  You are using a text representation, which may not match the actual object's NULL value or default value.  If it has a base size of ten, then "" isn't 10 spaces, and would be different in value than an empty field of 10 characters.  Try filling a NULL string of size 10, then compare that to the value you get from the blank to see if they match.  If not, the object you're reading is using a NULL mask, or sets a state of NULL for the object so you can use that to check for an empty field.

Not really getting the code you're using, but I've done some minimal html and java in the past and noticed this can happen in modular environments.  Maybe it helps, maybe not.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 05, 2015 May 05, 2015

Copy link to clipboard

Copied

Thanks for that suggestion Liam. I applied the |strip filter, so {{datechanged|strip|size}} returned a value of 0

Unfortunately when I did an if statement on it, this

{% if datechanged|strip|size == 0 -%}

   <p>Please select a date</p>

{% endif %}

still returned true for a date that was present, even though {{datechanged|strip|size}} returned 19

Any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2015 May 06, 2015

Copy link to clipboard

Copied

What about if you do

{% if {module_customerfield,161768,19984689} == "" -%} Direct to avoid whitespace from the capture

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2015 May 06, 2015

Copy link to clipboard

Copied

Or an assignment with that as the value along with some strip in there

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 06, 2015 May 06, 2015

Copy link to clipboard

Copied

That doesn't seem to work in any combination. Always returns false.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 06, 2015 May 06, 2015

Copy link to clipboard

Copied

Surely there's got to be some sort of bug in there. If datechanged|strip|size  returns 19, but datechanged|strip|size < 1 returns true, it doesn't sound like correct behaviour to me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 06, 2015 May 06, 2015

Copy link to clipboard

Copied

I'm only guessing, but would it be a string/number issue?

Where your {% if datechanged|strip|size == 0 -%} might be interpreted as a string not a number - or the value being checked against is a string not a number???

Jut a guess, but maybe try converting all values to numbers just in case.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 06, 2015 May 06, 2015

Copy link to clipboard

Copied

I think I've got it to work.

I had to assign datechanged|strip|size to a variable. Code now is:

{% capture datechanged -%}

  {module_customerfield,161768,19984689}

{% endcapture %}

{% assign datesize = datechanged|strip|size %}

{% if datesize  == 0 -%}

<p>Please select a date</p>

{% endif %}

That seems to work, but it seems to be an excessively convoluted way of doing it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 07, 2015 May 07, 2015

Copy link to clipboard

Copied

You can assign the module to a variable as I mentioned and then strip - I have done this, and did mention it above and its less code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 12, 2015 May 12, 2015

Copy link to clipboard

Copied

Convoluted?  Think about what it's doing.  Instead of trying to capture the value of the field, which may be empty anyway, you're catching a number that defines whether or not anything has been entered to begin with.  If it has been filled at all, now you can check the value against changes by comparing it to some other piece of data, or just capture what is in it and do something with it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2015 May 12, 2015

Copy link to clipboard

Copied

Not really relevant to how date field works and what he is trying to do and what liquid is capable of.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 12, 2015 May 12, 2015

Copy link to clipboard

Copied

HI Peter!

I would be interested how you can access  your Extended  CRM with Liquid, as i can't find any documentation yet on how to..

I can access it via SOAP and webServices but I am keen to change it to Liquid ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2015 May 12, 2015

Copy link to clipboard

Copied

LATEST

Not related to what you are doing. You can and have for a while get CRM fields through the customerfield Module - This is not liquid and custom CRM fields not exposed in the liquid user object and not available in the V3 API at this time.

Easiest way to get the modules is in the admin, go to make a page insert the update details form for customer and make sure you select the option to add the custom CRM fields. From there The module will be in the value="" bit of the input fields.


These will only be for the Person who is logged in at the time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines