cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
EdHansberry
Level: Powered On

Adding a new record to SQL Server where there is a uniqueidentier with a GUID

I have a form to edit/add records in a SQL table. Edits are easy. Adding not so much.

 

The table has a field that is the primary key, field type "uniqueidentifier", and is a GUID. I cannot set it as Identity YES on the SQL server where it would automatically populate on the server as that apparently only works with integers, not uniqueidentifier fields. (In otherwords, the solution here doesn't work)

 

I cannot for the life of me get a data card that has a normal DataCardValue that will let me stick GUID() in there. It is a required field, but adding the card doesn't give the the StarVisible or ErrorMessage fields, so PowerApps knows something is weird about this field.

 

This is how the field looks on the form:

20190715 18_27_20-Customer Service Maintenance - Saved (Unpublished) - PowerApps.png

You can see it doesn't have the bold blue box around it. It is like it is an uneditable field, which I don't want the user to edit. I just have it here for troubleshooting and was trying to get the UID field to be a GUID() function if this was a NEW form, but SubmitForm() won't take it.

 

So I used Patch(). This is my "Save" button function.

 

If(
    frmBBBFacilityCodeEdit.Mode = FormMode.Edit,
    SubmitForm(frmBBBFacilityCodeEdit),
    Patch(
        '[dbo].[tblBBBPoolFacilityCodes]',
        Defaults('[dbo].[tblBBBPoolFacilityCodes]'),
        {
            FacilityCode: DataCardValue1.Text,
            BuildingID: DataCardValue2.Text,
            ProviderName: DataCardValue3.Text,
            StreetAddress: DataCardValue11.Text,
            City: DataCardValue4.Text,
            State: DataCardValue10.Text,
            ZipCode: DataCardValue13.Text,
            TransitDays: Value(DataCardValue12.Text),
            StartDate: DataCardValue9.SelectedDate,
            UID: GUID()
        }
    )
)

Now, saving does add the record, and the last part of the PATCH() function adds a GUID, so this works, but this is U.G.L.Y. If this has to be this way, I will rename all of my DataCardValueX cards to something meaningful, as well as add the rest of the fields that are not required (about 6 fiedls missing), and finish with navigation back to the main screen.

 

But is there any other way to add a GUID to a record that is required? I cannot get it to work with SubmitForm() since it doesn't seem to see the UID field properly.

 

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 82 members 5,032 guests
Please welcome our newest community members: