# Binding Service Variable of type Datetime to a query parameter results in undefined

**URL:** <https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340>\
**Category:** Ask the community\
**Tags:** service\
**Created:** [March 13, 2023, 2:04pm UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340 "2023-03-13T14:04:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaspar](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kaspar/32/3073_2.png) [@Kaspar](https://community.appfarm.io/u/Kaspar)\
**Post date:** [March 13, 2023, 2:04pm UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340/1 "2023-03-13T14:04:44Z")

</div>

**Updated post to reflect actual issue [14-03-23]**  
When binding Service Variable of type Datetime to a query parameter with validation, the Datetime value results in ‘undefined’.

**Answer:**

> [@HJT](#):
>
> We have a closed challenge registered on that.  
> So this is fixed in a future release.

**Solution:**  
Set input validation to ‘None’ until future release fixes this issue.

> **Original post**
>
> Hi!  
> I am trying to set up a simple service that sends some data when called upon. The data read into a runtime data source should be filtered on its created date based on an input parameter called “from date”. I am trying to use the built-in createdDate parameter for this filter but then nothing gets read to the data source (see the below image for setup).
> 
> For testing purposes, I have tried using another “custom” dateTime-property. This returns data so it doesn’t seem that the service setup is the issue.
> 
> This might be a bug(?), and a workaround could be to create another custom “created date” parameter but that doesn’t feel like the best solution here. Any ideas on why this is happening and how to get it to work as intended?
> 
> ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/5a92ddb0f9bf821a667e5ae9bd34e6fb96d3120e.png)

---

<div class="post-metadata">

**Author:** ![HJT](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/hjt/32/64_2.png) [@HJT](https://community.appfarm.io/u/HJT)\
**Post date:** [March 13, 2023, 2:54pm UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340/2 "2023-03-13T14:54:58Z")

</div>

Hi,

The Service Variabels.From date, how is this value set? Does it get a default value on create? And how far back in time is this value set to?

Does it look like this?

 ![Skjermbilde 2023-03-13 kl. 15.53.53](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/896ae957de3127c33f8e345638833b9628fdd338.png)

---

<div class="post-metadata">

**Author:** ![Kaspar](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kaspar/32/3073_2.png) [@Kaspar](https://community.appfarm.io/u/Kaspar)\
**Post date:** [March 13, 2023, 3:14pm UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340/3 "2023-03-13T15:14:54Z")

</div>

Running some more tests on this, it is not the Created Date property that is the issue. Having the same setup as you and without using a query parameter I am getting some data. The issue appears to be the query param (see image below for setup).

When setting the query param to any ISO 8601 datetime value (e.g. “2023-03-01T00:00:00.001Z” (without quotes)) - and using log to console - printing Service Variabels.From date resolves in ‘undefined’. So it’s a different issue than originally assumed. Any ideas?

![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/5be3ad712d53b2cc459800e02ff276b5b4837c64.png)

---

<div class="post-metadata">

**Author:** ![Kaspar](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kaspar/32/3073_2.png) [@Kaspar](https://community.appfarm.io/u/Kaspar)\
**Post date:** [March 13, 2023, 4:07pm UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340/4 "2023-03-13T16:07:07Z")

</div>

For a temporary workaround, I was able to get the data requested using a Service Variable of type String as the query parameter:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/7241ca27cd15706c59c27752555678e170856f39.png)

![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/0ddd9af9f960999d4405316784bf9ec74302011b.png)

With this setup and using the ‘Update Object’ action on the Service Variable Data Source, I get the desired result by running the code below:

```auto
const momentObj = moment(fromDateAsString);
const isoString = momentObj.toISOString();
return isoString;

```

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/efe2292a1ec0463ce1705bbe99d529349b2b1223.png)

---

<div class="post-metadata">

**Author:** ![HJT](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/hjt/32/64_2.png) [@HJT](https://community.appfarm.io/u/HJT)\
**Post date:** [March 14, 2023, 7:30am UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340/5 "2023-03-14T07:30:29Z")

</div>

I changed my setup to look like yours with a datetime field and was able to console log the date from the query param.

My current setup:

 ![Skjermbilde 2023-03-14 kl. 08.24.20](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/2ddcdd1d046ae8451f8e642504a9247e32326b60.png)

 ![Skjermbilde 2023-03-14 kl. 08.25.06](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/10d81acb53c8bacf1d591a8a8bc6fe737e8f2c89.png)

![Skjermbilde 2023-03-14 kl. 08.25.12](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/d8686b2258cd49131097e5f5a67a9263469b4785.png)

 ![Skjermbilde 2023-03-14 kl. 08.25.39](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/f06deac9dbba44e9e7732a609f34d7314ca71326.png)

This setup will read 4 objects, but also console log the date from the query param.

NB, the From date field should no longer have a “value on create”

Can you spot any difference between our two setups? 😃

---

<div class="post-metadata">

**Author:** ![Kaspar](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kaspar/32/3073_2.png) [@Kaspar](https://community.appfarm.io/u/Kaspar)\
**Post date:** [March 14, 2023, 8:38am UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340/6 "2023-03-14T08:38:52Z")

</div>

It appears that the issue occurs when ‘Validation’ is set on the query parameter.

Turning the validation off results in correct execution:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/ac17ef075067ced88a1059e57750e643a035f260.png)

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/763b292378d3dbe52c80e2706b39110767fafafd.png)

But when turning the validation on (any value other than ‘none’), the Service Variable of type datetime results in ‘undefined’:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/829089376d261c7b56c6d554dd0564a04a407baf.png)

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/edbbc171b890a8a08cf23c602dc94bddf46e7302.png)

---

<div class="post-metadata">

**Author:** ![HJT](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/hjt/32/64_2.png) [@HJT](https://community.appfarm.io/u/HJT)\
**Post date:** [March 14, 2023, 8:41am UTC](https://community.appfarm.io/t/binding-service-variable-of-type-datetime-to-a-query-parameter-results-in-undefined/340/7 "2023-03-14T08:41:53Z")

</div>

Good catch!  
We actually have a closed challenge registered on that.  
So this is fixed in a future release.
