Forum Discussion
Translytical Task Flow – Create/Edit Not Reflecting in Report (Only Delete Working)
- 10 months ago
Hi Mohan128256,
Thanks for the update and follow-up question.
It sounds like your SQL logic is fine, but the issue is with how inputs are passed from the report to your User Data Function. Since all values are typed together (like 1,test1,test2…), Power BI can’t identify which value belongs to which parameter, so it’s mapping them randomly. Please try this below I mentioned:Create separate text inputs for each field PageNo, ReportName, PageName, ReportDescription, and ReportLink. Go to your Submit button → Format → Action → User Data Function, and make sure each parameter is mapped to the correct input visual. For optional Add a message box to show the success message after submission. After mapping them separately, the record should be created with correct values.
Hope this clarifies it. Let us know if you have any doubts regarding this. We will be happy to help.Thank you for using the Microsoft Fabric Community Forum.
Mohan128256 Hi!
Let’s build a slightly more robust version of your UDF that does three things differently:
-
Standardizes the ReportName so that create and update/delete won’t mismatch due to spaces/casing.
-
Returns the affected row(s) after each operation so you can display them in a card/table visual in the report.
-
Adds debug feedback in case an update/delete affects 0 rows (so you’ll know immediately if it’s a key mismatch).
import fabric.functions as fn
udf = fn.UserDataFunctions()
@udf.connection(argName="sqlDB", alias="DemoSQLDBPOC")
@udf.function()
def manage_report(sqlDB: fn.FabricSqlConnection,
operation: str, # "create", "update", "delete"
ReportName: str = None,
PageName: str = None,
ReportDescription: str = None,
Keywords: str = None,
ReportLink: str = None):
# Error handling for report description length
if ReportDescription and len(ReportDescription) > 200:
raise fn.UserThrownError(
"Descriptions have a 200 character limit. Please shorten your description.",
{"Description": ReportDescription}
)
# Normalize ReportName for consistency
if ReportName:
ReportName = ReportName.strip().lower()
connection = sqlDB.connect()
cursor = connection.cursor()
result_msg = ""
# CREATE
if operation.lower() == "create":
insert_query = """
INSERT INTO ReportCatalog (ReportName, PageName, ReportDescription, Keywords, ReportLink)
VALUES (?, ?, ?, ?, ?)
"""
cursor.execute(insert_query, (ReportName, PageName, ReportDescription, Keywords, ReportLink))
connection.commit()
result_msg = "Report record was created successfully."
# UPDATE
elif operation.lower() == "update":
update_query = """
UPDATE ReportCatalog
SET PageName = ?, ReportDescription = ?, Keywords = ?, ReportLink = ?
WHERE LOWER(LTRIM(RTRIM(ReportName))) = ?
"""
cursor.execute(update_query, (PageName, ReportDescription, Keywords, ReportLink, ReportName))
connection.commit()
if cursor.rowcount == 0:
result_msg = f"No record found with ReportName = {ReportName}."
else:
result_msg = "Report record was updated successfully."
# DELETE
elif operation.lower() == "delete":
delete_query = "DELETE FROM ReportCatalog WHERE LOWER(LTRIM(RTRIM(ReportName))) = ?"
cursor.execute(delete_query, (ReportName,))
connection.commit()
if cursor.rowcount == 0:
result_msg = f"No record found to delete with ReportName = {ReportName}."
else:
result_msg = "Report record was deleted successfully."
else:
raise fn.UserThrownError(
"Invalid operation. Please specify 'create', 'update', or 'delete'.",
{"operation": operation}
)
# Fetch and return the latest state for that ReportName (if not deleted)
return_data = []
if operation.lower() != "delete":
cursor.execute("SELECT * FROM ReportCatalog WHERE LOWER(LTRIM(RTRIM(ReportName))) = ?", (ReportName,))
rows = cursor.fetchall()
return_data = [dict(zip([desc[0] for desc in cursor.description], row)) for row in rows]
cursor.close()
connection.close()
return {
"message": result_msg,
"data": return_data
}
-
Bind your button action (Submit button) to this UDF.
-
After running, the UDF now returns:
-
message: a status string (create/update/delete success or error).
-
data: the row(s) that were just created/updated.
-
-
In Power BI, bind message to a card visual for user feedback.
-
Bind data to a table visual to instantly reflect what was changed, without waiting for dataset refresh.
BBF
💡 Did I answer your question? Mark my post as a solution!
👍 Kudos are appreciated
🔥 Proud to be a Super User!
- Mohan12825610 months agoHelper IV
Hi BeaBF ,
Thanks for the response i have tried this in update section i am getting errors, so i have created UDF for Create and Delete so it is working fine but suddenly it stopped working like it is showing a promt as record deleted or created but in the report it is not reflection sometime.