# Unexpected formatting on Entity Custom Data

**URL:** <https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736>\
**Category:** V5 Question\
**Created:** [November 12, 2024, 9:26pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736 "2024-11-12T21:26:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 12, 2024, 9:26pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/1 "2024-11-12T21:26:42Z")

</div>

Hello again -

I’m getting some unexpected results while using automation to create and Entity and I’m curious if anyone else has experienced the same.

I have a script that parses information from US Issued drivers licenses which is working as it should pulling all the pertinent info from the license to use while creating a Member Entity for our new members. Everything works expect one part, the zip code and I can’t put my finger on why…

It reflects correctly on the Entity Screen before and after the entity is made. If I did a show message with the Local Setting it appears correclty, however when creating the entity it formats it as though it’s a date? I’ve checked the Custom Entity Field for formatting and there is none as I’ve not gotten that far along in setting this up. (None of the fields have formatting)

Can anyone think of why this is reflecting data that isn’t correct?

 ![Member Enrollment - Entity Screen](https://forum.sambapos.com/uploads/default/original/3X/b/4/b4e047c6e64e88b606026efc010952893aa44aa7.jpeg)  
 ![Member Enrollment - Step 2](https://forum.sambapos.com/uploads/default/original/3X/c/f/cff466828a0f49236202d320beb8f6d7e369b8e2.jpeg)  
 ![Rules - Step 4](https://forum.sambapos.com/uploads/default/original/3X/b/8/b84b2a74ec4a616cc8ffdc23401657078c430f1e.jpeg)  
That full CustomData Entry is : Member ID={LOCAL SETTING:MP\_ME\_MemberID\_Local};Status=New;VIP Level={LOCAL SETTING:MP\_ME\_VIPLevel};Address={LOCAL SETTING:MP\_ME\_SCAN\_ID\_ADDR};City={LOCAL SETTING:MP\_ME\_SCAN\_ID\_CITY};State={LOCAL SETTING:MP\_ME\_SCAN\_ID\_STAT};Zip Code={LOCAL SETTING:MP\_ME\_SCAN\_ID\_CODE};Phone={LOCAL SETTING:MP\_ME\_Phone};Email={LOCAL SETTING:MP\_ME\_Email};Govt ID={LOCAL SETTING:MP\_ME\_SCAN\_ID\_NUMB};Govt ID Exp={LOCAL SETTING:MP\_ME\_SCAN\_ID\_EXPY};Date of Birth={LOCAL SETTING:MP\_ME\_SCAN\_ID\_BRTH};Access ID={LOCAL SETTING:MP\_ME\_AccessID\_Local};Image=URL;Comments={LOCAL SETTING:MP\_Comments};Zip={LOCAL SETTING:MP\_ME\_SCAN\_ID\_CODE}

 ![Script Editor](https://forum.sambapos.com/uploads/default/original/3X/a/5/a5a5a1092b36f4637fd32142caf3cef8e5d96351.jpeg)  
 ![Settings - Entities1](https://forum.sambapos.com/uploads/default/original/3X/9/1/9114c08b96ff62945649ecba3f47919cbca5481a.jpeg)

 ![Entity Types - Member](https://forum.sambapos.com/uploads/default/original/3X/0/0/00092211e1b71505a1026db71b47fc0f1b3b7dd8.jpeg)

Any insight is most appreciated! Thanks as always!

---

<div class="post-metadata">

**Author:** ![Posflow](https://forum.sambapos.com/user_avatar/forum.sambapos.com/posflow/32/63001_2.png) [@Posflow](https://forum.sambapos.com/u/Posflow)\
**Post date:** [November 13, 2024, 3:35am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/2 "2024-11-13T03:35:21Z")

</div>

Its a bug that was reported few years ago that hasn’t been patched.

> [@An entity Custom Field gets converted to date when set from rules or scripts](https://forum.sambapos.com/t/an-entity-custom-field-gets-converted-to-date-when-set-from-rules-or-scripts/22429):
>
> I have created a simple “Samples” entity with a string Custom Field named Field I can add a new entity with “123-456” as value for the Custom Field by clicking on “Add Entity” on the Entities window [imagen] If I try to create an entity using rules, actions or scritps the “123-456” gets transformed into a date value So, if I click “Add Entity” at Entities and I enter a value for the Custom Field, this value goes directly into the database. While set…

If it includes characters `\ / | - _` , API processing of custom data will try to convert it into date.

I cant remember how I bypassed that off the top of my head when doing PMS integration, I will look into the code and entity type custom data settings and get back to you when I have a moment

---

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 13, 2024, 5:06am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/3 "2024-11-13T05:06:23Z")

</div>

I’m creating the Entity via the Application, though - Not with the API/GQL. Or am I misunderstanding?

Either way. I appreciate the help!

---

<div class="post-metadata">

**Author:** ![Posflow](https://forum.sambapos.com/user_avatar/forum.sambapos.com/posflow/32/63001_2.png) [@Posflow](https://forum.sambapos.com/u/Posflow)\
**Post date:** [November 13, 2024, 5:09am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/4 "2024-11-13T05:09:12Z")

</div>

I can see in the code you are using GQL execute for mutations and queries.  
You are using SambaPOS API

---

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 13, 2024, 5:14am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/5 "2024-11-13T05:14:11Z")

</div>

That’s a fail safe. If I remove that it should correct the issue? I’m setting the program setting via Rules. At least that was my intention. Lol I’ll remove the API calls and see if I get the same result.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Posflow](https://forum.sambapos.com/user_avatar/forum.sambapos.com/posflow/32/63001_2.png) [@Posflow](https://forum.sambapos.com/u/Posflow)\
**Post date:** [November 13, 2024, 5:21am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/6 "2024-11-13T05:21:48Z")

</div>

On the entity screen you are loading value of the ZIP setting.

When you are processing to update / insert an entity via GQL, you are using SambaPOS API to process this request and update the database.

Update entity custom data endpoint has a tendency to convert anything with the characters mentioned into date because of the bug.

So technically, on the entity screen you are showing the user value of the setting {LOCAL SETTING:ZIP} which is 72007-8736, but after its processed and stored by the API - because of the bug it becomes 9/20/1827.

---

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 13, 2024, 9:12am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/7 "2024-11-13T09:12:34Z")

</div>

Confirmed. Same result having removed any references to GraphQL.

 ![1](https://forum.sambapos.com/uploads/default/original/3X/7/2/720f0435343ea553a89278ab49d82562c01781b3.jpeg)  
 ![2](https://forum.sambapos.com/uploads/default/original/3X/d/f/df45dc4dfb13e64fb092620702dcc408a2888d55.jpeg)  
 ![3](https://forum.sambapos.com/uploads/default/original/3X/c/0/c042c57ec09e8db8e4514e75cf6d66be16ccbc7f.jpeg)

---

<div class="post-metadata">

**Author:** ![Posflow](https://forum.sambapos.com/user_avatar/forum.sambapos.com/posflow/32/63001_2.png) [@Posflow](https://forum.sambapos.com/u/Posflow)\
**Post date:** [November 13, 2024, 11:30am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/8 "2024-11-13T11:30:00Z")

</div>

I haven’t had a time to check it today, but Ill check tomorrow and get back to you on how to bypass this issue

---

<div class="post-metadata">

**Author:** ![Jesse](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jesse/32/61493_2.png) [@Jesse](https://forum.sambapos.com/u/Jesse)\
**Post date:** [November 13, 2024, 3:04pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/9 "2024-11-13T15:04:27Z")

</div>

Can you try setting the ECD field type to number and setting a mask in editing format as #####

---

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 13, 2024, 9:27pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/10 "2024-11-13T21:27:02Z")

</div>

Same result only shorter. 🙂

 ![1](https://forum.sambapos.com/uploads/default/original/3X/4/a/4a8a1a0cfbc6034bbe717ca77d9d55b0c9f09668.jpeg)  
 ![2](https://forum.sambapos.com/uploads/default/original/3X/1/5/15bc64700d57bb2222c8abc1594c76299ab82af1.jpeg)

---

<div class="post-metadata">

**Author:** ![Jesse](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jesse/32/61493_2.png) [@Jesse](https://forum.sambapos.com/u/Jesse)\
**Post date:** [November 14, 2024, 3:56am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/11 "2024-11-14T03:56:01Z")

</div>

I told you wrong mask. Try #####-####

---

<div class="post-metadata">

**Author:** ![Posflow](https://forum.sambapos.com/user_avatar/forum.sambapos.com/posflow/32/63001_2.png) [@Posflow](https://forum.sambapos.com/u/Posflow)\
**Post date:** [November 14, 2024, 10:55am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/12 "2024-11-14T10:55:48Z")

</div>

@cpeckat

Similar problem to yours was that I would get room names from the PMS like `046-047 (DFG)`which when stored would convert to date like they do for you.

Changing masks types didn’t yield any results so adding a string followed by space character solved it for me.

So my code would output a value `Room 046-047 (DFG)`, in your case it can be `ZIP 72007-8736`  
 ![image](https://forum.sambapos.com/uploads/default/original/3X/a/5/a5b6a6b43406ebc1753534050b6695180ff91c7e.png)

That should prevent it from converting it to date, in your reports when querying ZIP you can use substr() to cut out first 4 characters.

 ![image](https://forum.sambapos.com/uploads/default/original/3X/4/7/4789c3506f4312ea708e5bbb76e75a45eb6fe41d.png)

---

<div class="post-metadata">

**Author:** ![Bob\_be](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@Bob\_be](https://forum.sambapos.com/u/Bob_be)\
**Post date:** [November 14, 2024, 6:42pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/13 "2024-11-14T18:42:37Z")

</div>

What if followed the Create Entity action with an Update Entity Data to update the zip code field. Does that have any effect?

---

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 14, 2024, 8:01pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/14 "2024-11-14T20:01:51Z")

</div>

> [@Bob\_be](#):
>
> What if followed the Create Entity action with an Update Entity Data to update the zip code field. Does that have any effect?

Unfortunately I get the same result.

> [@Jesse](#):
>
> I told you wrong mask. Try #####-####

Same result.

> [@Posflow](#):
>
> So my code would output a value `Room 046-047 (DFG)`, in your case it can be `ZIP 72007-8736`

I think this may work for our needs. I know this data is important to our owners as they use it to track demographics and advertising. Since you bring up parsing after the fact… is it the “-” that is the culprit here? If so I could just parse out the dash from the get go and hope ABC regulations do not require the last four. 🙂 I’ll give it a try and see.

Thank you everyone for your help!

---

<div class="post-metadata">

**Author:** ![Bob\_be](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@Bob\_be](https://forum.sambapos.com/u/Bob_be)\
**Post date:** [November 15, 2024, 1:08am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/15 "2024-11-15T01:08:23Z")

</div>

What if you store the full zip code as all numbers, then format it whenever you need to pull the zip code out.

---

<div class="post-metadata">

**Author:** ![Jesse](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jesse/32/61493_2.png) [@Jesse](https://forum.sambapos.com/u/Jesse)\
**Post date:** [November 15, 2024, 2:05am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/16 "2024-11-15T02:05:48Z")

</div>

One more thing to try. Have you tried setting the Mask Type to Numeric instead of Simple.

Try setting Field Type to Number and Mask Type to Numeric then use mask #####-####

---

<div class="post-metadata">

**Author:** ![Posflow](https://forum.sambapos.com/user_avatar/forum.sambapos.com/posflow/32/63001_2.png) [@Posflow](https://forum.sambapos.com/u/Posflow)\
**Post date:** [November 15, 2024, 5:56am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/17 "2024-11-15T05:56:19Z")

</div>

> [@cpeckat](#):
>
> ey use it to track demographics and advertising. Since you bring up parsing after the fact… is it the “-” that is the culprit here?

You can try and replace `_ - / \` characters with space character before passing it to API to update.

Or you could simply add word `ZIP ` before it. When running reports you can simply substring first 4 characters to trim out ZIP and space character - leaving only the actual value.

> [@Jesse](#):
>
> One more thing to try. Have you tried setting the Mask Type to Numeric instead of Simple.
> 
> Try setting Field Type to Number and Mask Type to Numeric then use mask #####-####

It doesn’t work, I’ve tried all the combinations too.

---

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 16, 2024, 8:20pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/20 "2024-11-16T20:20:22Z")

</div>

> [@anon75022180](#):
>
> Select Editing Format as **Regex** and try applying the format as follows.
> 
> `[0-9]{5}-[0-9]{4}`

This didn’t work either. I ended up just parsing out the “-” and the last 4 pending confirmation we don’t need it due to state law here. If we do I will add Zip to the beginning and take Posflow’s advice. Thanks again, Sir! Thank you everyone for your input.

---

<div class="post-metadata">

**Author:** ![cpeckat](https://forum.sambapos.com/user_avatar/forum.sambapos.com/cpeckat/32/27159_2.png) [@cpeckat](https://forum.sambapos.com/u/cpeckat)\
**Post date:** [November 16, 2024, 8:49pm UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/22 "2024-11-16T20:49:01Z")

</div>

I’m not sure where the error could be honestly… The zip+4 is parsed from the ID and stored in a program setting. The program setting is reflected correctly on the entity screen. When the entity is created via the create entity action using the program setting to set the zip it gets converted to this weird date format(see above for explanation). Unless I’m missing something I’m not sure where there could be an error. I mean I could go and manually type in each zip code for each of our members and skip the automation but that takes time and adds confusion to our on-boarding process.

Hopefully all that made sense. I’ve been working on this project for so long I’m crosseyed. haha

---

<div class="post-metadata">

**Author:** ![Memo](https://forum.sambapos.com/user_avatar/forum.sambapos.com/memo/32/55443_2.png) [@Memo](https://forum.sambapos.com/u/Memo)\
**Post date:** [November 18, 2024, 12:58am UTC](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736/24 "2024-11-18T00:58:45Z")

</div>

No formatting changes, field type changes will solve this. It’s something that needs to be addressed in the source code.

Here’s a stored procedure you can call to update custom entity fields:

```auto
/* Adds or Updates Entity Custom Data */

IF OBJECT_ID('dbo.p_AddOrUpdateEntityCustomField') IS NOT NULL
  DROP PROCEDURE dbo.p_AddOrUpdateEntityCustomField;
GO

CREATE PROCEDURE dbo.p_AddOrUpdateEntityCustomField
  @EntityName NVARCHAR(MAX),
  @CustomFieldName NVARCHAR(MAX),
  @NewCustomFieldValue NVARCHAR(MAX)
AS
  BEGIN
    SET NOCOUNT ON;

    DECLARE @EntityId INT;
    DECLARE @CustomData NVARCHAR(MAX);

    SELECT @EntityId = Id,
           @CustomData = CustomData
        FROM dbo.Entities
        WHERE Name = @EntityName;

    IF (@EntityId IS NOT NULL AND @CustomData IS NOT NULL)
      BEGIN
        IF NOT EXISTS ( SELECT 1
                            FROM OPENJSON(@CustomData)
                            WHERE JSON_VALUE(value, '$.Name') = @CustomFieldName)
          BEGIN
            SET @CustomData =
              JSON_MODIFY(
                @CustomData,
                'append $',
                JSON_QUERY('{"Name":"' + @CustomFieldName + '","Value":"' + @NewCustomFieldValue + '"}'));
          END;
        ELSE
          BEGIN
            SET @CustomData =
              JSON_MODIFY(
                @CustomData,
                '$[' + ( SELECT [key]
                             FROM OPENJSON(@CustomData)
                             WHERE JSON_VALUE(value, '$.Name') = @CustomFieldName) + '].Value',
                @NewCustomFieldValue);
          END;

        UPDATE dbo.Entities
            SET CustomData = @CustomData
            WHERE Id = @EntityId;
      END;
  END;

```

script to call sp:

```auto
function updateField(entityName,fieldName,fieldValue)
{
    var dml = "dbo.p_AddOrUpdateEntityCustomField '" + entityName + "', '" + fieldName + "', '" + fieldValue + "'";
    
    sql.Query(dml).First;
}

```

[Next page](https://forum.sambapos.com/t/unexpected-formatting-on-entity-custom-data/29736.md?page=2)
