cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sperry1625
Helper V
Helper V

Updating Variables with Loookups

I am building a Canvas App that uses SharePoint as it's data source.  I use variables, in this instance, Screen Context Variables, to store the data for the SharePoint lists.  So when a New entry is created I do:

 

 

UpdateContext( { ctxServiceRequest: Defaults( 'Service Requests' ) } );

 

 

No issues. I have the Form.DataSource set to 'Service Request' and the Form.Item property set to ctxServiceRequest.  All is well.  Now, as part of the "New" process I must initialize other fields in the record to some specific values.  Oh, did I forget to mention that the Service Request list has Lookup columns?  And 2 of the 3 fields I need to set are Lookups.  Here is my Update:

 

 

UpdateContext(
    {
        ctxServiceRequest,
        Patch(
            ctxServiceRequest,
            {
                Application: // Lookup column
                {
                    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                    Id: gblSAPApp.ID,
                    Value: gblSAPApp.Title
                },
                Status: // Choices column
                {
                    Value: "New" 
                },
                'Request Type':  // Lookup column
                {
                    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                    Id: -1,
                    Value: ""
                }
            }
        )
    }
);

 

 

There is no error on the this statement.  But as soon as I add this code I am getting an error on the Form.Item property.  The error is "Invalid formula. Expected a value compatible with 'DataSource'".

This update IS compatible with the Data Source. I will say that the error doesn't show until I add one of the Lookup columns.  I even tried replacing the 'Request Type' column with the internal name, Request_x0020_Type, same result.

 

For whatever reason, making this update is making Power Apps think I have changed the record and it no longer matches the Data Source, but it does as far as I know.  When setting a Lookup column you need to set those three properties. Are there others that I am not aware of that I may be eliminating by doing the update, therefore causing the error?  This really should NOT be this hard or complicated. I just want to update some properties of the variable.

 

PS In case you thinking I should try a global variable, I did.  Same result.

 

UPDATE

Can anyone provide any guidance here?  I have tried multiple ways of setting the values and all lead to an error of one kind or another.  HOW do I resolve this?  The Application property needs to be set to the appropriate record from the Lookup table.  I have tried multiple ways of setting the value but any attempt causes the follwong error, 'Incompatible type. We can't evaluate your formula because the content variable types are incompatible with the types of values in other places in your app.'.  How do I set the Lookup Calumn value for the field if I keep getting this error?

 

 

Thank you.

 

Steven

8 REPLIES 8
PG_WorXz10
Resident Rockstar
Resident Rockstar

Hi @sperry1625 ,

 

Any specific reason you are adding -1 in the id ? 

If this post was helpful or you need more help please consider giving Thumbs Up and Tag me in your reply I'll be happy to help. If this post helped you solve your issue please click Accept as solution and provide Thumbs Up. This will help others find it more readily.

StalinPonnusamy
Community Champion
Community Champion

Hi @sperry1625 

 

1. No need to patch Request type if this has empty as long as default has some other value

2. Can you remove the Request type on the patch command to narrow down the issue

 

 

Request Type (-1) is not valid entry

I have removed Request Type and just left Application, same result.  I have had Request Type set to 0, or not setting it at all.  No change.

Reset it to nothing, no selection.

Hi @sperry1625 ,

 

If the same error message for value  not compatible with 'DataSource' than please check the data type of variable is as expected. If possible could you please share the updated code ?

If this post was helpful or you need more help please consider giving Thumbs Up and Tag me in your reply I'll be happy to help. If this post helped you solve your issue please click Accept as solution and provide Thumbs Up. This will help others find it more readily.

Data Type in all cases is Record.  I don't think it is complaining about the Data Type as much as it is complaining about the structure of the Data Source and that it thinks it is different than what it is expecting.  Data Source for the form is set to the SharePoint list directly.  It is likely comparing that structure to what I gave it for Item, the variable, and finding them to be different in some way.  Not sure what that would be. Power Apps does not provide a way for me to query the structure of the variable or what properties are present.

ok, Did you tried adding application value alone and Status value alone just to be sure about which column value is creating issue ? 

If this post was helpful or you need more help please consider giving Thumbs Up and Tag me in your reply I'll be happy to help. If this post helped you solve your issue please click Accept as solution and provide Thumbs Up. This will help others find it more readily.

Using just Status, the Choice column, all is good.  As soon as I add one of the Lookups it fails.

 

As a test I tried something else.

UpdateContext(
    { ctxApplication: ctxServiceRequest.Application }
);

UpdateContext(
    {
        ctxApplication:
        {
            Id: gblSAPApp.ID,
            Value: gblSAPApp.Title
        }
    }
);

I grabbed the Application property from the ctxServiceRequest, shortly after it was set to Defaults( 'Service Requests' ).  Then I perform an update on that variable for just the two properties I want to change, leaving all the others intact.  I then:

UpdateContext(
    {
        ctxServiceRequest: 
        Patch(
            ctxServiceRequest,
            {
                Status: 
                {
                    Value: "New" 
                },
                Application: ctxApplication
            }
        )
    }
);

The error did not return.  This leads me to believe that there are other properties that are part of the Lookup column that are getting wiped out and causing Power Apps to think the variable does not match the Data Source.  This is a lot of extra work to do an update on a complex property.

 

Even if this works, I am seeing another issue. I added an Update to my original post, but here it is again:

 

UPDATE:  I use a Toggle button as an "OnNew()" event.  I set a variable that basically triggers the toggle and runs any OnNew code needed.  In that event handler is where I set/initialize the variable.  In that event after calling the above (without the two lookup columns, just Status) I set a debug text box to the value of status.  Value shows, no problem.  When I check the value from elsewhere on the screen, either a button or something else, the value for Status is gone, blank.  It's like I never set it at all. It feels like the update of the variable only lasts as long as the event runs. That can't be right. I check all the other code in the screen, and that variable is not touched, set, anywhere else. So now I am really confused.

 

Thanks.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,808)