Various Questions

Hi Wix team and thank you for offering this in beta, very exciting!
I created a site for our sales team to help with updating any inbound leads that come in. You will see on my page here, https://matthewgdougherty.wixsite.com/mysite a few pages including Team 1, Team 2, Team 3, and Team 4. I have set up a collection of company names with basic information. Each “team” will specialize in adding information to the record and only have access to their team’s page.

Question 1
I’m looking to create a work flow like in this video https://youtu.be/9S5k9Vf7pOE?t=1m59s so the submission from team 1 moves to team 2 then to team 3, etc. Here are the rules I am looking to implement. Once a record is updated with additional information, the status will update and it will be sent to the next team. How do I create a workflow based on the status like this?
If the user input fields are completed, then the record should move from
Team 1 → Team 2
Team 2 → Team 4
Team 3 → Team 4
Team 4 → Team 5

Question 2
You will see that I have a “submit” button and a “next” button on the bottom of each page. The “submit” button should submit the form’s changes, update the status for the next team, and reload the page with the next record to work on. The “next” button should skip this record and move to the next record. Can you tell why the “submit” button is not submitting and the “next” button is not skipping to the next record? I have tried releasing all permissions and still have had no success here.

Question 3
When a team member successfully completes a form, I’d like them to receive one “credit” and if they do not complete the form and click “next,” I would like them to not receive any credits. This way, I can check the database or create an admin page and keep track of the number of credits each person earned. How can I accomplish this? Would I need a “members” collection to add this field to each member?

Question 4
If I would like to add a bunch of companies with their basic information to my database all at once, can I upload a .csv and it will add them all into a database to run through the team sequence starting at Team 1 or can I copy and paste columns into the live database?

Question 5
There will be multiple lists all at one time and you will see I attempted to create an example of a listID in the “ContactList” collections. Once the status reaches team 5, then I would like to sort Team 5 of that particular list and export all completed records. Will this be achievable in Wix Code?

Question 6
Can the lists of companies be completed in order of need? Some lists have higher priority then others as you can see in the database with their deadline date, how can I include this in the sorting of the database as they populate onto each team’s page?

1 Like

OK, lots of questions!
Glad to see you trying out the product with such a comprehensive idea.

I’ll try to answer one by one.

  1. This is achievable with a data-hook. you can read about hooks here . There are a few complimentary articles on that as well.
    the general idea would be to create a post-insert or post-update hook that runs your logic. in that hook you can perform data manipulations that mutate the “team” field and update it to “Team X” per the logic you outlined.
    ===============

  2. Let me give some info on how datasets work, as I have seen this question in other posts as well.
    A dataset is used in two different scenarios:
    (1) in a dynamic page (i.e. a page that gets its data based on the page’s URL).
    In this case the dataset will hold all the items that match the page’s URL.
    you can see which items match a URL by looking for records with this URL in the content manager.
    note that if the dynamic page is designed to show only one specific item (i.e. an “item page”), the dataset will only have one record and hence “next” and “prev” do not do anything.
    in dynamic pages that are designed to show more than one item, next and prev iterate over the records retrieved by the dataset.

(2) in a standard page if you added a dataset to.
in this case, the dataset holds values that are not related to the URL at all.
the dataset will hold all the records that match the filter you have provided when defining the dataset’s configuration.
again, if the dataset holds a single record, “prev” and “next” will not do anything.

And now to your question:
If I understand correctly, what you are trying to achieve is to create a page in which a site member goes over a list of records that are assigned to his team. for each record, the user may update it or skip to the next.

So for this configuration, what you probably need is this:

  • a dynamic “team” page. the auto-generated dataset should be configured so that it retrieves all the records that are relevant to the team. this is achieved by configuring the dynamic page URL to be something like “…/{team}”.
  • now you need to change the dataset to be of type “read/write”. this is because your logic requires showing the record’s data (i.e. “read”) and also updating it (i.e. “write”).
  • assuming your form’s submit button is bound to the dataset’s submit action, that should be enough to let the record get updated.

now, you mentioned that you also need the ability to move to the next record after submission. This can be done by adding some JS code that listens to the “onAfterSave” event and simply calling the dataset’s “next” function.

similarly the “skip” functionality can be implemented by adding a “skip” button, and wiring its “onClick” event to call the dataset’s “next” function.

note : you can disable the “skip” button if this is the last record in the dataset, by using “hasNext”.

[long post - to be continued in part 2]

[part 2]

(3) This can be achieved by creating a “member-credit” collection.
that collection would hold one record per member and have only one field - “credits”.
The member field will actually be the system defined “_owner” field.
this field is populated by wix code to have the user ID of the logged in user; whenever a record is created by a logged in user the _owner field will hold his ID.

now all you need to do is add another dataset to the page and configure it to retrieve the relevant record from the collection.
(a) set the dataset as read-write.
(b) using JS code, add logic to the dataset’s “onReady” event handler.
this code should get the logged in user’s ID using the APIs in “wix-users” package. see an example here: https://www.wix.com/code/reference/wix-users.html#currentUser.

now, use the dataset’s setFilter method to add a filter condition that retrieves the current user’s record.
see an example for setting a filter here : https://www.wix.com/code/reference/wix-dataset.html#setFilter.

this should make sure the dataset has retrieved the current user’s record (if there is one), and should be now ready to update it when given the command.

note that when a user first visits the page, there will be no record for him/her in the collection.
you can detect that case by using the dataset’s getTotalCount() function.
if the count is zero, you need to add a record for that user with zero credits.
you do that simply by calling the dataset’s new() function, and then updating the newly created item’s “credit” field to be zero, then saving it to the collection using the dataset’s save() function.

(c) now, let’s add the logic that increments the credit after successful form submission.
what you need to do is add code to the “onAfterSave” event of the form’s dataset (not the credits dataset you have just created). after a successful form submission, your JS code should select the credit dataset, get the current record, increment the credit field by one, and save the data to the backend.
this is done by getting the dataset’s current item and updating its “credits” field, and then calling the save() function to persist the information to the collection.

I hope it’s clear, try it out!

[part 3 coming later - stay tuned ;-)]

[part 3]

(4) import/export using CSV is on our roadmap. see here: https://www.wix.com/code/home/coming-soon
we will notify the forum when it’s ready.

(5) not sure I understand. once we support export, you will be able to export data using a filter and sort applied to the view in content manager. if you provide more info I’ll try to be more accurate.

(6) simply add a sort order by “deadline” to the dataset’s configuration.
open the dataset’s settings panel, find the sort config panel, and add a sort order.

that’s it, hope you have found it useful.
let us know if anything is amiss.

First, THANK YOU! These are very straightforward instructions and are helping me through each issue I am having very well.

  1. I am looking over the data-hook documentation Velo: About Data Hooks | Help Center | Wix.com and https://www.wix.com/code/reference/wix-data.Hooks.html for some examples of how I need to write out the logic. When you say post-insert and post-update, do you mean “afterInsert” and “afterUpdate?”

  2. I have created a dynamic page for each of the teams and got the submit button to work on each page which is great. I see in the collection for the dataset, that each dynamic page has created a new field column. Is this a concern to have field values (URLs) that I will not be using for each record. For example, I have created the Team 1 site at …wixsite.com/mysite/one/{Team} and the records that are in that Team currently are on that site. However, I see they are present on sites …wixsite.com/mysite/two/{Team}, …wixsite.com/mysite/three/{Team}, and so on. Is this a concern or nothing to worry about as long as I do not link to these pages?

Regarding the dataset’s “next” function, I believe I know where that lives and I added a picture of it below, but where are some examples of the use of “onAfterSave,” “onClick,” “hasNext” in Wix? Is there a page or video tutorial for this or is it in the similar format to the hook types in number 1 above?

  1. I’m working through your instructions and will keep you updated.

  2. That’s great!

  3. You answered my question, this feature will work within export once released.

  4. Figured this out, thanks!

You’re most welcome :slight_smile:
to answer your new set of Qs:

  1. indeed, afterInsert and afterUpdate, my bad.
  2. it seems to me you can make your site a lot simpler.
    instead of having a separate page for each team, you can have a single dynamic page that will be used for all teams.

such a dynamic page would have the URL pattern …/mysite/{team}.
this will make the page load items for that team alone.
for example for the URL …/mysite/Team-one, only records that are now owned by “team-one” will be fetched.

this would remove the redundant URL fields you are seeing in the content manager, now only one will exist.
for a record that is owned by team one it will have the value “…/mysite/team-one”. for a record that is owned by team two it will be “…/mysite/team-two”, etc.

as for the dataset APIs, you can take a look here . the page lists all of the dataset’s APIs and provides a few examples on how to use them.

good luck!

Thanks for the quick response. I’ll check out the link you have provided for help on the APIs.

You’ll find that I tried to create only one dynamic page initially, but what happens is that the text boxes are each shown on the page regardless if that Team needs them or not. For example, team 1 should not be able to see anything below website and phone number because they will not be updating any records besides those. If I have just one dynamic page, then the team sees empty or completed fields that they do not need to complete and that may confuse them. I see it working only if the visibility of text boxes can be dependent of the team the member is on. Is this possible? Hope this makes sense.

you can definitely control the visibility of fields in the form -
just use the component’s hide() and show() functions based on the “team” field value.
you can also use the “collapse()” and “expand()” functions to do more than just hide and show.

play around with it and see if it suits your needs.

you can of course keep your existing pages - that would work as well.

Regarding changing team functionality.

This is the logic for changing from one team to another. we kept it in data.js file but we are not seeing the team in the database change. The columns are not being updated per our logic. We are guessing the callback is not getting executed.

export function ContactList_afterUpdate(item, context) {
const teams = [‘one’, ‘two’, ‘three’, ‘four’, ‘five’];
const currentTeamIndex = teams.indexOf(item.tEam);
item.tEam = teams[currentTeamIndex + 1];
item.title = ‘test’;
return item;
}

Regarding OnAfterSave function to be used for going to the next item after save

Do I need to call save() programmatically so that onAfterSave function gets called or does the page save with the submit button?

I have added this JavaScript to the Team Two page only and when I click the submit button, it does not print the console.log.

$w.onReady(function () {
$w(“#dynamicDataset”).onAfterSave( (event) => {
console.log(“After save”, event);
} );
} );

regarding the after-update question, here’s a quote from our reference API doc:
“Because the afterUpdate hook is called after the update() is executed, it cannot affect the item that is being updated in the collection. It can only affect the item returned by update() .”

I think that your logic should reside in the beforeUpdate hook (sorry for guiding you towards the afterUpdate hook at first).

try it and let’s see.

p.s.
do you know how to debug backend code using console messages?
see this… it’s kind of nifty :wink:

It worked! thank you for the help. Any advice for the OnAfterSave function to be used for the next item?

not sure… are you sure you added the event handler to the right dataset (with the right name)?

I currently have the following code only on Team Two’s page as seen in the image below. I believe based on the text above the dataset image, #dynamicDataset is the correct dataset name?

$w.onReady(function () {
$w(“#dynamicDataset”).onAfterSave( (event) => {
console.log(“After save”, event);
} );
} );


When looking at the other Team pages, I have not added the code to reference the datasets on those pages. However, they are the same dataset name it looks like. I believe #dynamicDataset (see below). Do I need to add the code above to every team’s page or should I add it to the site’s code?


My other question is in regards to the data hooks. I see in the settings for each page “Add Hooks” and when I click “After Router” I get brought to the routers.js page. Do I need one for each page here in addition to the code on each Team’s page?

Any help?

Hi md,
sorry for the late response.

I will take a deeper look into this beginning of next week.
thanks you.