So I searched and read and tested and then repeated and now here I am.
I've seen multiple posts that suggest my Set statement should be valid but throws errors in the Editor so there is clearly something wrong in the syntax. My suspicion is that I can't put a Set inside of an If or I have a referential problem because I'm trying to patch a record that I'm also trying to search for within the If.
Here is the logic that sucessfully completes but causes varItem to continue to hold the old values. Specifically Approval_Level which is used to affect visibility of controls:
If(
varNewApprovalLevel <> varItem.Approval_Level,
Patch(
'SPIFF - Requests',// The target data source (e.g., SharePoint list)
LookUp(
'SPIFF - Requests',
ID = varItem.ID
),// Identify the specific record
{Approval_Level: varNewApprovalLevel
// Update or set the value of Approval_Level column
// Add more columns and values as needed
}
);
UpdateContext ({varNewApprovalLevel: Blank()})
);
Here is my unsuccessful attempt at inserting a Set statement into this so that varItem updates:
If(
varNewApprovalLevel <> varItem.Approval_Level,
Set(varItem,
Patch(
'SPIFF - Requests',// The target data source (e.g., SharePoint list)
LookUp(
'SPIFF - Requests',
ID = varItem.ID
),// Identify the specific record
{Approval_Level: varNewApprovalLevel
// Update or set the value of Approval_Level column
// Add more columns and values as needed
}
);
UpdateContext ({varNewApprovalLevel: Blank()})
));
I think it's wrong because I'm actually trying to set varItem equal to just the patch value itself and not the record that's being patched but can't figure out the syntax to do it correctly.
This is what I finally did. I separated the Edit icon from the save icon and use a pre-existing variable that controls a containers visibility allowing for record modification to turn the Edit and Save icons on and off.
Then I put the update logic only on the Save icon to simplify the code.
This is the Save icons OnSelect:
Set(
varGalEdit,
false
);
Refresh('SPIFF - Approvals');
If(
CountRows(
Filter(
'SPIFF - Approvers',
Approve_Level = varItem.Approval_Level
)
) = CountRows(
Filter(
'SPIFF - Approvals',
Approve_Level = varItem.Approval_Level && PositionID = varItem.ID
)
),
UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 1}),
UpdateContext({varNewApprovalLevel: varItem.Approval_Level + 0})
);
If(
varNewApprovalLevel <> varItem.Approval_Level,
Patch(
'SPIFF - Requests',// The target data source (e.g., SharePoint list)
LookUp(
'SPIFF - Requests',
ID = varItem.ID
),// Identify the specific record
{Approval_Level: varNewApprovalLevel
// Update or set the value of Approval_Level column
// Add more columns and values as needed
}
);
UpdateContext ({varNewApprovalLevel: Blank()});
Set(
varItem,
LookUp(
'SPIFF - Requests',
ID = varItem.ID
);
)
);
Refresh('SPIFF - Requests');