First of all, sql statements in UI model should be avoided if possible according to this post:
https://www.bbdevnetwork.com/qa/45780/grant-permission-to-tvf-sql-function-for-custom-ui-modelI created an SP based extension for the Modeling and "Propensity Attribute Edit Form 2" form. I also added a UI action button through edit form extension spec and created a UI model from the extension spec. I wrote an insert statement in the invoke action event for the button but got the error below:
"Cannot find the object 'USR_MU_MODELSCOREEXTENSION', because it does not exist or you do not have permission."
Here is the code below:
Private Sub SaveExtention_InvokeAction(ByVal sender As Object, ByVal e As UIModeling.Core.InvokeActionEventArgs) Handles _saveext.InvokeAction
Using con As SqlClient.SqlConnection = GetRequestContext.OpenAppDBConnection() 'RequestContext.OpenAppDBConnection()
Using command As SqlClient.SqlCommand = con.CreateCommand()
command.CommandText = " Grant insert on dbo.USR_MU_MODELSCOREEXTENSION to [my username]"
command.ExecuteScalar.ToString()
command.CommandText = "insert into dbo.USR_MU_MODELSCOREEXTENSION(ID, SOURCE, AUTHOR, ADDEDBYID, CHANGEDBYID)
values ('19A501D9-B349-4055-BDBF-C0E17F34743A', 'source code d', 'test', 'C5874A28-5F46-42BD-895A-33E0B8DD1ADD', 'C5874A28-5F46-42BD-895A-33E0B8DD1ADD' )"
command.ExecuteScalar.ToString()
End Using
End Using
End Sub