cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mhulsegge
Regular Visitor

Copying Inspection Points to Work Order on SQL database

Hi all,

 

I'm pretty new to PowerApps and really enjoying all the posibilities it gives. I'm trying to built a sort of inspection app, where people can register results of inspections. Therefore I have created a SQL database with a few tables, including:

  • Inspection --> Containing the inspectionpoints
  • WorkOrder --> Containing the work order of the inspections
  • WoInsp --> Built to make the relationship between "Inspection" and Work order. This table contains a field for the workorderID and the same columns as the Inspection table. 

 

Now I want to make a button, saying "Create new work order"  that does the following:

  1. Create a new work order record (I'm able to do that)
  2. Copy all inspectionpoints from the "Inspection" table to the WoInsp Table, with relation to this work order. 

I'm having trouble with action 2. I looked at something with "Forall" and "Patch", but couldn't get it working

 

Below a screenshot of my work order screen. It shows the work order details from Workorder and below the related inspectionpoints from WoInsp. 

 

mhulsegge_0-1611084634780.png

 

Looking forward to your suggestions!

Matthijs

1 ACCEPTED SOLUTION

Accepted Solutions
mhulsegge
Regular Visitor

I'm not sure what happened over night, but now I am able to create the record. I think my SQL just had to refresh something (although I did press refresh on the powerapps database). 

 

so far so good, thanks

View solution in original post

7 REPLIES 7
WarrenBelz
Super User III
Super User III

Hi @mhulsegge ,

I am assuming that your are using NewForm(YourFormName) and you want to copy in additional information before saving the record? If so, you simply need to set the Default of the relevant control of your new Work Order form to the relevant value from Inspection. There are several ways of getting and setting this value - I will give you one piece of advice first - get rid of the "joining" table and make a direct relationship between them. So in the Default of the control would be something like

If(
   YourFormName.Mode=FormMode.New,
   YourInspectionValue,
   Parent.Default
)

Happy to assist further - just paste your code in Text.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

mhulsegge
Regular Visitor

Thanks for the fast reply!

 

The reason why I want/have to use the joining table is that the inspection points can be modified, so they're not fixed. Thereby I want to store the results per inspection, so I have to have a copy of the records containing the results. 

@mhulsegge ,

You need a Lookup inside your Filter to refer "through" the tables (messy). Please paste the code you have done so far as Text and also what are all the field names?

 

mhulsegge
Regular Visitor

Hi,

Sorry for the late reply, I'm not able to work on this every day. The thing is that I don't really have any code yet, as I'm not sure what the best way to do this is.

 

I want to register a daily inspection via Powerapps into an SQL database. 

The daily inspection consists out of N inspection points, registered in the Inspection table in my SQL

Every daily inspection is a work order in my Workorder table

 

So my challenge is how to cover every inspection point from the inspection table every time I create a new work order. I thought the best way to do this was a third table, containing the relation between the two, my WoInsp table. This WoInsp table contains a column for the InspectionId, the WorkOrderId and the value that is registered. 

 

So I have a work order screen, containing basic work order information from the Workorder table and a second galery with the Inspection Points fromt he Inspection table. The challenge is that I want to open an inspection point and write the entered value to my WoInsp table, including the WorkorderId and InspectionId. 

mhulsegge
Regular Visitor

I'm now one step further. I just thought that I only need 3 columns in my WoInsp table:

- WoInspID (Id of the current row, primary key)

- WoInspInspId (Id of the inspection point)

- WoInspWoId) (Id of the work order)

 

The WoInspId and WoInspInspId columns are "not null", so I tried first to add only the InspId:

Patch('[dbo].[WoInsp]';Defaults('[dbo].[WoInsp]');{WoInspInspId: InspId})

 This results into an error after saving: "Could not find the giver record. Server reply [dbo].[WoInsp] failed: Resource not found" (translated from Dutch). 

 

Below the code I used to create the table:

CREATE TABLE WoInsp (
    WoInspId int identity(1,1) NOT NULL,
    WoInspInspId int NOT NULL,
    WoInspWoId int,
    PRIMARY KEY (WoInspId)
);

 

@mhulsegge ,

Firstly this code

Patch(
   '[dbo].[WoInsp]';
   Defaults('[dbo].[WoInsp]');
   {WoInspInspId: InspId}
)

certainly should create a new record in your table providing WoInpInspId in the table and InspID in your code are both Integers. I am not any SQL authority (I have used it in the past, but am a SharePoint user in Power Apps), but have you had a look at your table and seen if you can enter things directly?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

mhulsegge
Regular Visitor

I'm not sure what happened over night, but now I am able to create the record. I think my SQL just had to refresh something (although I did press refresh on the powerapps database). 

 

so far so good, thanks

View solution in original post

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

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (20,718)