cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AndrewValenzuel
Advocate II
Advocate II

Collect function is not collecting... It's in an "If" function.

Here is the code:

 

/*Collects data to be added to a the sharepoint list titled "Tickets"*/

If(tgAutoFill.Value=true,
/*1st Collection if tgAutoFill is switched to true.*/
Collect(
TicketsCollection,
{
Title: "PowerApp1",
Customer_Name: cbCustomerName_1.Selected.Result,
Location: ddLocation_1.Selected.Location,
Make: ddMake_1.Selected.Make2,
Model: ddModel_1.Selected.Model,
Serial_Number: ddSerialNumber_1.Selected.Serial_Number,
Priority: ddPriority_1.Selected.Value,
CallType: ddCallType_1.Selected.Value,
Problem: tiProblem_1.Text
}
),/*2nd Collection if tgAutoFill is switched to false.*/
Collect(
TicketsCollection,
{
Title: "PowerApp1",
Customer_Name: tiNewCustomer.Text,
Location: tiNewLocation.Text,
Make: tiNewMake.Text,
Model: tiModel.Text,
Serial_Number: tiSerialNumber.Text,
Priority: ddPriority_1.Selected.Value,
CallType: ddCallType_1.Selected.Value,
Problem: tiProblem_1.Text
}));

/*Triggered to create a second collection for updating the sharepoint list titled "Machines"*/
If(tgAutoFill.Value=true,"",Collect(MachinesCollection, {Title: "PowerApp1",Customer_Name: tiNewCustomer.Text,
Location: tiNewLocation.Text,
Make: tiNewMake.Text,
Model: tiModel.Text,
Serial_Number: tiSerialNumber.Text})) ;

UpdateContext({SubmitNewTicketClickable:true});

Reset([@cbCustomerName_1]); Reset([@tiProblem_1]);

 

Explanation: 

I'm using this app to track tickets.  At present the published app is working.  And the version is only using the 1st Collect function.  Which is:  

Collect(
TicketsCollection,
{
Title: "PowerApp1",
Customer_Name: cbCustomerName_1.Selected.Result,
Location: ddLocation_1.Selected.Location,
Make: ddMake_1.Selected.Make2,
Model: ddModel_1.Selected.Model,
Serial_Number: ddSerialNumber_1.Selected.Serial_Number,
Priority: ddPriority_1.Selected.Value,
CallType: ddCallType_1.Selected.Value,
Problem: tiProblem_1.Text
}
)

The flow of the app works like this: 

  1.   User adds a new ticket by selecting from pre-existing customers.
  2. Cascading dropdowns populate based on the selected customer.
  3. User then lists the problem and adds the data to a collection "TicketsCollection".
  4. User views the "TicketsCollection" in a gallery.
  5. User submits the tickets in the collection to a sharepoint list titled "Tickets". The "tgAutoFill" is  a toggle switch that enables all of the 2nd collection textboxes to become visible.  

The problem:

I decided to add the ability for users to input data manually.  I used a toggle switch titled "tgAutoFill".  The "tgAutoFill" is  a toggle switch that enables all of the 2nd collection textboxes to become visible.   And the third collection "MachinesCollection" is used to update the auto-populating list of customers/machines.  

 

The only thing that gets submitted to the second collection, and the third collection "MachinesCollection", is the text from "tiProblem_1".  Nothing else in second or third collections text inputs gets submitted to the collection/s.

 

Note: the first collection works just fine.  

 

What am I missing?  Is there a better way to structure this?  

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Thank you for this:  

Notes:

- you could refactor your code down to one If() statement, if you like, like this:

 

If( tgAutoFill.Value, < -- collect dropdowns to TicketCollection -->, <-- collect TextInputs to TicketCollection --> ; < -- collect MachinesCollection -->)

 

I was so annoyed that I couldn't figure that portion out.  

 

1. What type of SharePoint columns are all the Combo/Dropdowns referring to in your working code? Are they choice columns / lookup columns or plain text? I'm thinking that this maybe why none of the fields are getting collected (other than Problem: tiProblem_1.Text) because the 2nd & 3rd code snippets use TextInput fields which don't talk well to Choice columns.

 

All columns are plain text.  There are no choice columns.  The dropdowns pull info from one SP list titled "Machines".  That data gets pulled into a collection.  Then on a seperate screen the data in the collection is patched to another SP list titled Tickets.  Wherein all columns are text too.  

 

I figured out the problem BTW.  I had set the "Reset" function of each field to reset when the Add to collection button was pressed.  

 

It's funny that you solved a problem that I didn't even ask about.  🙂  Thank you for that. 

 

I'm going to use a variable to trigger the text fields resetting instead of the OnSelect of the button.    

View solution in original post

3 REPLIES 3
Eelman
Super User
Super User

@AndrewValenzuel 

I have a few questions:

1. What type of SharePoint columns are all the Combo/Dropdowns referring to in your working code? Are they choice columns / lookup columns or plain text? I'm thinking that this maybe why none of the fields are getting collected (other than Problem: tiProblem_1.Text) because the 2nd & 3rd code snippets use TextInput fields which don't talk well to Choice columns.

 

2. Do the cascading dropdowns depend on one another? Eg If I pick 'Customer X' do all the other dropdowns populate with values ie I don't need to select anything else? I'm thinking this maybe why when tgAutoFill is false values such as Priority: ddPriority_1.Selected.Value is blank because the user appears to be adding a NewCustomer and this new customer doesn't as yet have any dependent values, hence blank is the result.

 

3. For your MachinesCollection, is the <blank> correct ie If(tgAutoFill.Value=true,"",Collect(MachinesCollection, ...? If so, seems you could rewrite this like:

If(tgAutoFill.Value=false,Collect(MachinesCollection,...

 

Notes:

- you could refactor your code down to one If() statement, if you like, like this:

 

If( tgAutoFill.Value, < -- collect dropdowns to TicketCollection -->, <-- collect TextInputs to TicketCollection --> ; < -- collect MachinesCollection -->)

 

Note the semi-colon between <-- collect TextInputs to TicketCollection --> ; < -- collect MachinesCollection -->). You can also drop the bold part of tgAutoFill.Value=true if you like? If(tgAutoFill.Value will test for TRUE.

 

Thank you for this:  

Notes:

- you could refactor your code down to one If() statement, if you like, like this:

 

If( tgAutoFill.Value, < -- collect dropdowns to TicketCollection -->, <-- collect TextInputs to TicketCollection --> ; < -- collect MachinesCollection -->)

 

I was so annoyed that I couldn't figure that portion out.  

 

1. What type of SharePoint columns are all the Combo/Dropdowns referring to in your working code? Are they choice columns / lookup columns or plain text? I'm thinking that this maybe why none of the fields are getting collected (other than Problem: tiProblem_1.Text) because the 2nd & 3rd code snippets use TextInput fields which don't talk well to Choice columns.

 

All columns are plain text.  There are no choice columns.  The dropdowns pull info from one SP list titled "Machines".  That data gets pulled into a collection.  Then on a seperate screen the data in the collection is patched to another SP list titled Tickets.  Wherein all columns are text too.  

 

I figured out the problem BTW.  I had set the "Reset" function of each field to reset when the Add to collection button was pressed.  

 

It's funny that you solved a problem that I didn't even ask about.  🙂  Thank you for that. 

 

I'm going to use a variable to trigger the text fields resetting instead of the OnSelect of the button.    

View solution in original post

Glad I could help, if only a little bit, and glad you got it sorted. It's funny you think I helped find that Reset function error, lol

 

Happy PowerApp'ing 🙂 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (60,941)