Spiria Posted July 17, 2018 Share Posted July 17, 2018 Hi, I must create a synchronisation process to import data from a CRM. I have a page reference field where I don't know in advance all the available options. It has to be added in the reference tree. In my import script, based on Ryan's Import Page by CSV module, i coded this: $p->crm_member_type = $data['TypeDeMembre']; where $p is a valid page to be saved. $data['TypeDeMembre'] is a string. Actually, if the entry is already present in the page reference tree, the data is saved correctly. But if the entry does not exist, nothing is saved. This page reference field ("crm_member_type") is set to accept new entry on the UI, but I think this feature is not available from API. Do I have to check first if the entry exists then create a the right page to be referenced afterwards? Link to comment Share on other sites More sharing options...
wbmnfktr Posted July 17, 2018 Share Posted July 17, 2018 40 minutes ago, Spiria said: Do I have to check first if the entry exists then create a the right page to be referenced afterwards? As far as I know you have to go this way. You could take just that $data ['TypeDeMembre '] column on first run and create all non-existing pages and afterwards you import as usual. Link to comment Share on other sites More sharing options...
Guy Verville Posted July 17, 2018 Share Posted July 17, 2018 I don't know why I was on the impression that there was an API way (no pun intended). Link to comment Share on other sites More sharing options...
wbmnfktr Posted July 17, 2018 Share Posted July 17, 2018 There could be one but... I don't know where. Didn't you ( @Guy Verville ) did something similar with your skiing(?) project? Link to comment Share on other sites More sharing options...
Guy Verville Posted July 17, 2018 Share Posted July 17, 2018 That's why I asked... We did just a great project (https://centura.ca) and we have a lot of page references (it was not coded by me, and the guy is absent for the moment, and his code is not different from mine...). There is indeed such a field that is supposed to be automatically completed. Maybe I am just too tired of trying. Link to comment Share on other sites More sharing options...
wbmnfktr Posted July 17, 2018 Share Posted July 17, 2018 Maybe you will find or remember that. Link to comment Share on other sites More sharing options...
elabx Posted July 18, 2018 Share Posted July 18, 2018 4 hours ago, Spiria said: Do I have to check first if the entry exists then create a the right page to be referenced afterwards? Yes, you have to check if the page you are trying to reference exists, if not, create it through the API. For educational purposes, you can check how InputfieldPage does it. See how it iterates through the titles it receives as input, and makes decisions based on the page already existing or has to make a new one. https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module#L840 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now