Jump to content

Third normal form with processwire: How to reference data?


HarryPhone
 Share

Recommended Posts

Hello,

in my first Processwire-site I need a periodical import of data.

One imported dataset saved as a page looks like this:

Kundenstamm.png.0fabbe868ca7d23dd92694ea98e336bf.png

In this dataset I have a field with values like "JA1, NE1, NE2".

But the backend-user should see the values "Bestätigt, o.Datenschutzerklär, n. Endkundenrelevant"

That's why I made a ProField Table:

 Tabelle_Homepage_Listung.png.163a06fbf31a4fa263614a4d6d09041b.png

After that I created a field with this FieldType:

Fieldtype_Select_External_Option.png.1131e630a1fe3e798b3010d4ff691035.png

Finally I wanted zu label the values. But unfortunately I need an integer field:

KATR7.png.c76a2e207a370c7a06b887506149e746.png

With the field "Branche" in the first picture of this post, it worked, but with non integer values I failed.

Is there any other way to solve this problem?

Many thanks in advance!

Best regards,

Harry

Link to comment
Share on other sites

Hi @HarryPhone,

If I understand right, what you are doing looks more complicated than it needs to be.

If you just need values/titles in a select inputfield and your site editors don't need to edit these options then you can define the values/titles in an Options field: https://processwire.com/api/modules/select-options-fieldtype/#separate-option-values

If your site editors do need to edit or add new options then you can use a Page Reference field. In the template for the pages you would use the Title field for the option title and add a text field for the option value.

  • Like 1
Link to comment
Share on other sites

Thanks for your answer.

I should explain the problem a little bit more:

My editors should not add any new option - the data are from a leading system. In the leading system is data maintenance.

If I use page reference somebody has to make the reference, it's not automatically. New pages are generated by import, so the page to reference is not known before. There are severals thousands data sets, so a manually reference is not possible.

If I make a select inputfield, Processwire saves the number of the option into the database. After save, an ID number is assigned to each of the options. 

1: JA1
2: NE1
3: NE2

But I get JA1 from the leading system with import. And I want the text of JA1, NE1 and NE2.

I think I have a big problem...

Link to comment
Share on other sites

I'm having a bit of trouble understanding, but you can automate pretty much anything in PW - nothing has be done manually. Suppose you go with a Page Reference field for your options (which is usually the most flexible approach) - you can create new options (i.e. pages) on-the-fly as you import your data if you need to.

But from what you say in the first post, it sounds like you already know the the options ahead of time and that is how you are able to set up the Table field with those options on the Home page. Instead of the Table field, create one page per option under some special branch of the page tree that is dedicated to that purpose. Set up a "Homepage Listung" Page Reference field that uses those pages as options. When you import the data you don't have to know the ID of the option (page) - you can find the option by title (e.g. "Bestätigt") or value (e.g. "JA1") and then set that option (page) for the "Homepage Listung" field.

 

  • Like 1
Link to comment
Share on other sites

Hello Robin,

thanks for your answer.

I'm so sorry it wasn't clear. 

The datas in the first post are only imported data. The pages of this template will only contain imported data. They are used by an other template which references with a Page Reference field to the title (=customer-ID)

CSV-Data of the first post looks like this:

title,VKGRP,KUNNR,ANRED,NAME1,NAME2,STRAS,LAND1,PSTLZ,ORT01,ORT02,TELF1,TELF2,TELFX,AUFSD,BRSCH,KATR7
1000010,42,1000010,Firma,Mustermann GmbH,Schreinerei,Dorfstr. 77,DE,77777,Dorsten,Lembeck,02369 / 7777,,02369/7777,,12,NE2

You see, the value NE2 is already existing.

But most of the editors doesn't know the label of NE2, that's why I want to display it.

Link to comment
Share on other sites

1 hour ago, HarryPhone said:

CSV-Data of the first post looks like this:

title,VKGRP,KUNNR,ANRED,NAME1,NAME2,STRAS,LAND1,PSTLZ,ORT01,ORT02,TELF1,TELF2,TELFX,AUFSD,BRSCH,KATR7
1000010,42,1000010,Firma,Mustermann GmbH,Schreinerei,Dorfstr. 77,DE,77777,Dorsten,Lembeck,02369 / 7777,,02369/7777,,12,NE2

You see, the value NE2 is already existing.

But most of the editors doesn't know the label of NE2, that's why I want to display it.

A Page Reference field will work great for your "Homepage Listung" field. It's no problem to set a Page Reference field using data from a CSV import. You don't say how you are importing the CSV data, but let's say you are using the ImportPagesCSV module. The module readme says...

Quote

Importing page fields (requires ProcessWire 2.5.17+)
----------------------------------------------------
For single-value page fields the CSV imported value can be the page id, path, title, or name.
For multi-value page fields, the value can be the same but multiple-values should be separated by 
either a newline in the column, or a pipe "|" character. 

Probably the easiest way in your case is to use the title of the page. So a basic outline of what's involved...

  1. The template for the pages in your Page Reference field should contain the "Title" field and a "Label" text field.
  2. Create the pages for the Page Reference field - one for each option that might occur in your CSV data.
    • For the page Title use the value that appears in the CSV data. For the page Label use the label that belongs to that value. Example... Title: "NE2", Label: "n. Endkundenrelevant"
  3. Create the Page Reference field and add it to the template used for the pages you will be importing.
    • Specify the pages you just created as the "Selectable pages".
    • For the "Label field" setting, choose "label".
  4. Import your CSV data using the ImportPagesCSV module. Done. :)
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...