cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ilimeli
Microsoft
Microsoft

Updating an existing record

Hi All,

 

I am trying to perform the following:

 

Checking whether a record exists of this user submitting a value.

If yes, value is updated for the existing record.

If no, new record is created.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Super User
Super User

Hi @ilimeli 

 

What is ratData? I assume it's a collection. So we need to get data from the collection when iterates.

 

 

ForAll(ratData As Source,
With({_Item:LookUp(
'MSD Solution Ratings',
'Rated By' = varUserEmail &&
'Solution ID' = Text(Source.SolutionDeploymentInfo.'Solution Id') &&
'Solution Version' = Source.SolutionDeploymentInfo.'Solution Version')},

If(
IsBlank(_Item)| IsEmpty(_Item),
Patch(
'MSD Solution Ratings',
Defaults('MSD Solution Ratings'),
{
'Solution Version':Source.SolutionDeploymentInfo.'Solution Version',
'Solution Rating':Source.Rating2.Value,
'Solution Name':Source.SolutionDeploymentInfo.Name,
'Solution ID':Text(Source.SolutionDeploymentInfo.'Solution Id'), 
'Rated By':varUserEmail
}
),
Patch('MSD Solution Ratings',
_Item,
{
'Solution Rating':Source.Rating2.Value
}
) //Patch
) //If
) //With
) //ForAll

 


Thanks,
Stalin - Learn To Illuminate

View solution in original post

7 REPLIES 7
StalinPonnusamy
Super User
Super User

Hi @ilimeli 

 

I assume you are using Sharepoint. Partner and Employee are Person records. We can change if the data source is different but the concept is the same.

 

With({_Item:LookUp(Rating, Employee.Email=UserInfo.Email && Partner.Email = SelectedPartnerID.Email)},
Patch(
    Rating,
    If(
       IsBlank(_Item),
        Defaults(Rating),
        _Item
    ),
    {
        Rate: DataCardValue1.Selected,
        Partner: {
            Claims: "i:0#.f|membership|" & SelectedPartnerID.Email,
            Department: "",
            DisplayName: "",
            Email: SelectedPartnerID.Email,
            JobTitle: "",
            Picture: ""
        },
        Employee: {
            Claims: "i:0#.f|membership|" & UserInfo.Email,
            Department: "",
            DisplayName: "",
            Email: UserInfo.Email,
            JobTitle: "",
            Picture: ""
        }
    }
));

 
Thanks,
Stalin - Learn To Illuminate

Hi @StalinPonnusamy , thank you for the reply.

I am using Dataverse. What would that look like?

StalinPonnusamy
Super User
Super User

Hi @ilimeli 

 

I assume ratings given by and given to are User correct. It means Lookup to User record from Rating table.

 

With(
    {
        _Item: LookUp(
            Ratings,
            GivenBy.'Primary Email' = UserInfo.Email && GivenTo.'Primary Email' = LookUp(
                Users,
                'Full Name' = GivenToDataCardValue.Selected.'Full Name'
            ).'Primary Email'
        )
    },
    Patch(
        Ratings,
        If(
            IsBlank(_Item) || IsEmpty(_Item),
            Defaults(Ratings),
            _Item
        ),
        {
            Name: DataCardValue3.Text,
            GivenTo: GivenToDataCardValue.Selected,
            GivenBy: LookUp(
                Users,
                'Primary Email' = UserInfo.Email
            )
        }
    )
);

 

StalinPonnusamy_0-1635382194691.png

 

StalinPonnusamy_1-1635382211895.png

 

I tried a similar method 

 

ForAll(ratData,
If(
IsBlank(


LookUp(
'MSD Solution Ratings',
'Rated By' = varUserEmail &&
'Solution ID' = SolutionDeploymentInfo.'Solution Id' &&
'Solution Version' = Text(SolutionDeploymentInfo.'Solution Version', "#.0")),

 

Patch(
'MSD Solution Ratings',
Defaults('MSD Solution Ratings'),
{'Solution Version':Text(SolutionDeploymentInfo.'Solution Version', "#.0"),'Solution Rating':Rating2.Value,'Solution Name':SolutionDeploymentInfo.Name,'Solution ID':SolutionDeploymentInfo.'Solution Id', 'Rated By':varUserEmail}),

 

Patch('MSD Solution Ratings',
LookUp(
'MSD Solution Ratings',
'Rated By' = varUserEmail &&
'Solution ID' = SolutionDeploymentInfo.'Solution Id' &&
'Solution Version' = Text(SolutionDeploymentInfo.'Solution Version', "#.0")),{'Solution Rating':Rating2.Value}))))

 

but I am getting errors and would love your input

StalinPonnusamy
Super User
Super User

Hi @ilimeli 

 

Please share each field data type. So that I can validate this.

 

 

Solution ID= number

Solution Name = text

Solution Rating = text

Solution Version = text

Rated By = email

 

I fixed a few things but I am still getting errors

 

ForAll(ratData,
If(
IsBlank(
LookUp(
'MSD Solution Ratings',
'Rated By' = varUserEmail &&
'Solution ID' = Text(SolutionDeploymentInfo.'Solution Id') &&
'Solution Version' = SolutionDeploymentInfo.'Solution Version'),

Patch(
'MSD Solution Ratings',
Defaults('MSD Solution Ratings'.'Solution Rating'),
{'Solution Version':SolutionDeploymentInfo.'Solution Version','Solution Rating':Rating2.Value,'Solution Name':SolutionDeploymentInfo.Name,'Solution ID':Text(SolutionDeploymentInfo.'Solution Id'), 'Rated By':varUserEmail}),

Patch('MSD Solution Ratings',
LookUp(
'MSD Solution Ratings'.'Solution Rating',
'Rated By' = varUserEmail &&
'Solution ID' = Text(SolutionDeploymentInfo.'Solution Id') &&
'Solution Version' = SolutionDeploymentInfo.'Solution Version',{'Solution Rating':Rating2.Value}))))

 

StalinPonnusamy
Super User
Super User

Hi @ilimeli 

 

What is ratData? I assume it's a collection. So we need to get data from the collection when iterates.

 

 

ForAll(ratData As Source,
With({_Item:LookUp(
'MSD Solution Ratings',
'Rated By' = varUserEmail &&
'Solution ID' = Text(Source.SolutionDeploymentInfo.'Solution Id') &&
'Solution Version' = Source.SolutionDeploymentInfo.'Solution Version')},

If(
IsBlank(_Item)| IsEmpty(_Item),
Patch(
'MSD Solution Ratings',
Defaults('MSD Solution Ratings'),
{
'Solution Version':Source.SolutionDeploymentInfo.'Solution Version',
'Solution Rating':Source.Rating2.Value,
'Solution Name':Source.SolutionDeploymentInfo.Name,
'Solution ID':Text(Source.SolutionDeploymentInfo.'Solution Id'), 
'Rated By':varUserEmail
}
),
Patch('MSD Solution Ratings',
_Item,
{
'Solution Rating':Source.Rating2.Value
}
) //Patch
) //If
) //With
) //ForAll

 


Thanks,
Stalin - Learn To Illuminate

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (1,785)